Skip to content

Commit d1161b7

Browse files
committed
Update CI to use re-usable actions
1 parent df4c350 commit d1161b7

3 files changed

Lines changed: 59 additions & 45 deletions

File tree

.github/workflows/build.yaml

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,32 @@
11
name: Build
22

33
on:
4-
workflow_run:
5-
workflows: ["Lint & Test"]
6-
branches:
7-
- main
8-
types:
9-
- completed
10-
11-
concurrency:
12-
group: ${{ github.workflow }}-${{ github.ref }}
13-
cancel-in-progress: true
4+
workflow_call:
5+
inputs:
6+
sha-tag:
7+
description: "A short-form SHA tag for the commit that triggered this flow"
8+
required: true
9+
type: string
1410

1511
jobs:
1612
build:
17-
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push'
1813
name: Build & Push
1914
runs-on: ubuntu-latest
2015

2116
steps:
22-
# Create a commit SHA-based tag for the container repositories
23-
- name: Create SHA Container Tag
24-
id: sha_tag
25-
run: |
26-
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
27-
echo "::set-output name=tag::$tag"
2817
- name: Checkout code
2918
uses: actions/checkout@v3
30-
3119
# The current version (v2) of Docker's build-push action uses
3220
# buildx, which comes with BuildKit features that help us speed
3321
# up our builds using additional cache features. Buildx also
3422
# has a lot of other features that are not as relevant to us.
3523
#
3624
# See https://github.com/docker/build-push-action
3725
- name: Set up Docker Buildx
38-
uses: docker/setup-buildx-action@v1
26+
uses: docker/setup-buildx-action@v2
3927

4028
- name: Login to Github Container Registry
41-
uses: docker/login-action@v1
29+
uses: docker/login-action@v2
4230
with:
4331
registry: ghcr.io
4432
username: ${{ github.repository_owner }}
@@ -48,7 +36,7 @@ jobs:
4836
# Repository. The container will be tagged as "latest"
4937
# and with the short SHA of the commit.
5038
- name: Build and push
51-
uses: docker/build-push-action@v2
39+
uses: docker/build-push-action@v3
5240
with:
5341
context: .
5442
file: ./Dockerfile
@@ -57,7 +45,7 @@ jobs:
5745
cache-to: type=inline
5846
tags: |
5947
ghcr.io/python-discord/code-jam-management:latest
60-
ghcr.io/python-discord/code-jam-management:${{ steps.sha_tag.outputs.tag }}
48+
ghcr.io/python-discord/code-jam-management:${{ inputs.sha-tag }}
6149
build-args: |
6250
git_sha=${{ github.sha }}
6351
@@ -67,12 +55,6 @@ jobs:
6755
runs-on: ubuntu-latest
6856

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

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

67+
- uses: azure/setup-kubectl@v3
68+
8569
- name: Authenticate with Kubernetes
86-
uses: azure/k8s-set-context@v1
70+
uses: azure/k8s-set-context@v3
8771
with:
8872
method: kubeconfig
8973
kubeconfig: ${{ secrets.KUBECONFIG }}
9074

9175
- name: Deploy to Kubernetes
92-
uses: Azure/k8s-deploy@v1
76+
uses: Azure/k8s-deploy@v4
9377
with:
9478
manifests: |
9579
kubernetes/namespaces/default/code-jam-management/deployment.yaml
96-
images: 'ghcr.io/python-discord/code-jam-management:${{ steps.sha_tag.outputs.tag }}'
97-
kubectl-version: 'latest'
80+
images: 'ghcr.io/python-discord/code-jam-management:${{ inputs.sha-tag }}'

.github/workflows/lint-test.yaml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
name: Lint & Test
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
4+
workflow_call
85

9-
concurrency:
10-
group: ${{ github.workflow }}-${{ github.ref }}
11-
cancel-in-progress: true
126

137
jobs:
148
lint:
@@ -35,17 +29,15 @@ jobs:
3529
uses: actions/checkout@v3
3630

3731
- name: Install Python Dependencies
38-
uses: HassanAbouelela/actions/setup-python@setup-python_v1.3.2
32+
uses: HassanAbouelela/actions/setup-python@setup-python_v1.4.0
3933
with:
40-
# Set dev=true to install flake8 extensions, which are dev dependencies
41-
dev: true
42-
python_version: '3.9'
34+
python_version: "3.11"
4335

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

5042
# Run flake8 and have it format the linting errors in the format of
5143
# the GitHub Workflow command to register error annotations. This
@@ -58,6 +50,7 @@ jobs:
5850
- name: Run flake8
5951
run: "flake8 \
6052
--format='::error file=%(path)s,line=%(row)d,col=%(col)d::[flake8] %(code)s: %(text)s'"
53+
6154
# We run `coverage` using the `python` command so we can suppress
6255
# irrelevant warnings in our CI output.
6356
- name: Run tests and generate coverage report
@@ -73,7 +66,7 @@ jobs:
7366
# print a "job" link in the output of the GitHub Action
7467
- name: Publish coverage report to coveralls.io
7568
env:
76-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
69+
GITHUB_TOKEN: ${{ github.token }}
7770
run: coveralls --service=github
7871

7972
# Prepare the Pull Request Payload artifact. If this fails, we

.github/workflows/main.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: main
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
14+
lint-test:
15+
uses: ./.github/workflows/lint-test.yaml
16+
secrets: inherit
17+
18+
generate-inputs:
19+
if: github.ref == 'refs/heads/main'
20+
runs-on: ubuntu-latest
21+
outputs:
22+
sha-tag: ${{ steps.sha-tag.outputs.sha-tag }}
23+
steps:
24+
- name: Create SHA Container Tag
25+
id: sha-tag
26+
run: |
27+
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
28+
echo "sha-tag=$tag" >> $GITHUB_OUTPUT
29+
30+
build-deploy:
31+
if: github.ref == 'refs/heads/main'
32+
uses: ./.github/workflows/build.yaml
33+
needs:
34+
- lint-test
35+
- generate-inputs
36+
with:
37+
sha-tag: ${{ needs.generate-inputs.outputs.sha-tag }}
38+
secrets: inherit

0 commit comments

Comments
 (0)