Skip to content

Commit

Permalink
Update CI to use re-usable actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Dec 20, 2022
1 parent 533b6d8 commit b151e36
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 45 deletions.
47 changes: 15 additions & 32 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
name: Build

on:
workflow_run:
workflows: ["Lint & Test"]
branches:
- main
types:
- completed

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
workflow_call:
inputs:
sha-tag:
description: "A short-form SHA tag for the commit that triggered this flow"
required: true
type: string

jobs:
build:
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push'
name: Build & Push
runs-on: ubuntu-latest

steps:
# Create a commit SHA-based tag for the container repositories
- name: Create SHA Container Tag
id: sha_tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "::set-output name=tag::$tag"
- name: Checkout code
uses: actions/checkout@v3

# The current version (v2) of Docker's build-push action uses
# buildx, which comes with BuildKit features that help us speed
# up our builds using additional cache features. Buildx also
# has a lot of other features that are not as relevant to us.
#
# See https://github.com/docker/build-push-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Login to Github Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand All @@ -48,7 +36,7 @@ jobs:
# Repository. The container will be tagged as "latest"
# and with the short SHA of the commit.
- name: Build and push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
Expand All @@ -57,7 +45,7 @@ jobs:
cache-to: type=inline
tags: |
ghcr.io/python-discord/code-jam-management:latest
ghcr.io/python-discord/code-jam-management:${{ steps.sha_tag.outputs.tag }}
ghcr.io/python-discord/code-jam-management:${{ inputs.sha-tag }}
build-args: |
git_sha=${{ github.sha }}
Expand All @@ -67,12 +55,6 @@ jobs:
runs-on: ubuntu-latest

steps:
# Create a commit SHA-based tag for the container repositories
- name: Create SHA Container Tag
id: sha_tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "::set-output name=tag::$tag"

# Check out the private "kubernetes" repository in the `kubernetes`
# subdirectory using a GitHub Personal Access Token
Expand All @@ -82,16 +64,17 @@ jobs:
repository: python-discord/kubernetes
path: kubernetes

- uses: azure/setup-kubectl@v3

- name: Authenticate with Kubernetes
uses: azure/k8s-set-context@v1
uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}

- name: Deploy to Kubernetes
uses: Azure/k8s-deploy@v1
uses: Azure/k8s-deploy@v4
with:
manifests: |
kubernetes/namespaces/default/code-jam-management/deployment.yaml
images: 'ghcr.io/python-discord/code-jam-management:${{ steps.sha_tag.outputs.tag }}'
kubectl-version: 'latest'
images: 'ghcr.io/python-discord/code-jam-management:${{ inputs.sha-tag }}'
19 changes: 6 additions & 13 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
name: Lint & Test

on:
push:
branches:
- main
pull_request:
workflow_call

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
Expand All @@ -35,17 +29,15 @@ jobs:
uses: actions/checkout@v3

- name: Install Python Dependencies
uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.2
uses: HassanAbouelela/actions/setup-python@setup-python_v1.4.0
with:
# Set dev=true to install flake8 extensions, which are dev dependencies
dev: true
python_version: '3.9'
python_version: "3.11"

# We will not run `flake8` here, as we will use a separate flake8
# action. As pre-commit does not support user installs, we set
# PIP_USER=0 to not do a user install.
- name: Run pre-commit hooks
run: export PIP_USER=0; SKIP=flake8 pre-commit run --all-files
run: SKIP=flake8 pre-commit run --all-files

# Run flake8 and have it format the linting errors in the format of
# the GitHub Workflow command to register error annotations. This
Expand All @@ -58,6 +50,7 @@ jobs:
- name: Run flake8
run: "flake8 \
--format='::error file=%(path)s,line=%(row)d,col=%(col)d::[flake8] %(code)s: %(text)s'"

# We run `coverage` using the `python` command so we can suppress
# irrelevant warnings in our CI output.
- name: Run tests and generate coverage report
Expand All @@ -73,7 +66,7 @@ jobs:
# print a "job" link in the output of the GitHub Action
- name: Publish coverage report to coveralls.io
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
run: coveralls --service=github

# Prepare the Pull Request Payload artifact. If this fails, we
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
pull_request:
push:
branches: main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

lint-test:
uses: ./.github/workflows/lint-test.yaml
secrets: inherit

generate-inputs:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
sha-tag: ${{ steps.sha-tag.outputs.sha-tag }}
steps:
- name: Create SHA Container Tag
id: sha-tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "sha-tag=$tag" >> $GITHUB_OUTPUT
build-deploy:
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/build.yaml
needs:
- lint-test
- generate-inputs
with:
sha-tag: ${{ needs.generate-inputs.outputs.sha-tag }}
secrets: inherit

0 comments on commit b151e36

Please sign in to comment.