Skip to content

Commit

Permalink
Improve Github Actions workflows (#537)
Browse files Browse the repository at this point in the history
* Add version sanity check Github Actions workflows
* Make build a re-usable workflow
* Combine sanity checks into one workflow
* Add concurrency constraints
* Skip integration tests on LICENSE and VERSION changes
  • Loading branch information
markbastiaans committed May 19, 2022
1 parent 823cdd6 commit 01ce0be
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 37 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build

on:
workflow_call:

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.6
- name: Install Python requirements
run: make install_requirements
- name: Lint
run: make lint
- name: Run unit tests
run: make test_unit
- name: Build
run: make build
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
19 changes: 11 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ on:

jobs:
pre:
name: Prepare workflow run
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.skip-check.outputs.should_skip }}
steps:
- id: skip-check
- name: Check if workflow should be skipped
id: skip-check
uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ github.token }}
Expand All @@ -26,7 +28,7 @@ jobs:
exists: ${{ steps.get-version.outputs.exists }}
version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
if: ${{ github.event.pull_request.merged }}
with:
ref: master
Expand All @@ -43,20 +45,21 @@ jobs:
fi
echo "::set-output name=exists::${EXISTS}"
echo "::set-output name=version::${VERSION}"
build:
name: Build
needs: pre
if: ${{ needs.pre.outputs.skip != 'true' && github.event.pull_request.merged }}
uses: ./.github/workflows/build.yml
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: prepare-deployment
needs: [prepare-deployment, build]
if: ${{ needs.prepare-deployment.outputs.exists == 'false' }}
steps:
- name: Download pull request artifact
uses: dawidd6/action-download-artifact@v2
- uses: actions/download-artifact@v3
with:
workflow: test.yml
pr: ${{github.event.pull_request.number}}
name: dist
path: dist
check_artifacts: true
- name: Create Github release
id: create-release
uses: actions/create-release@v1
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/sanity-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Sanity Check

on:
push:
branches:
- develop
pull_request:
branches:
- develop
- master

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

jobs:
check-version-changed:
name: Check for VERSION changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check if VERSION has been changed
uses: tj-actions/verify-changed-files@v9
id: verify-version-changed
with:
files: |
VERSION
- name: Fail when branch is not the main branch
if: steps.verify-changed-files.outputs.files_changed && ( github.ref != 'refs/heads/master' )
run: exit 1
45 changes: 16 additions & 29 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,28 @@ on:
- develop
- master

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

jobs:
pre:
name: Prepare workflow run
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.skip-check.outputs.should_skip }}
steps:
- id: skip-check
- name: Check if workflow should be skipped
id: skip-check
uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ github.token }}
paths_ignore: '["**.md", "dev/**"]'
paths_ignore: '["**.md", "dev/**", "LICENSE", "VERSION"]'
build:
name: Build
runs-on: ubuntu-latest
needs: pre
uses: ./.github/workflows/build.yml
if: ${{ needs.pre.outputs.skip != 'true' }}
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.6
- name: Install Python requirements
run: make install_requirements
- name: Lint
run: make lint
- name: Run unit tests
run: make test_unit
- name: Build
run: make build
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
setup-integration-tests:
name: Set up integration tests
runs-on: ubuntu-latest
Expand All @@ -52,7 +39,7 @@ jobs:
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- id: set-matrix
name: Set up test matrix
run: |
Expand All @@ -71,13 +58,13 @@ jobs:
TEST_MEMORY: 1G
TEST_PROCESSES: 1
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: 3.6
- name: Install Python requirements
Expand All @@ -97,11 +84,11 @@ jobs:
- name: Run test (${{ matrix.test }})
run: make test_integration TEST_FILES=tests/integration/${{ matrix.test }}
integration-test-result:
if: ${{ always() }}
if: ${{ needs.pre.outputs.skip != 'true' }}
runs-on: ubuntu-latest
name: Get integration test results
needs: [pre, integration-test]
steps:
- name: Get integration test results
if: ${{ needs.pre.outputs.skip != 'true' && needs.integration-test.result != 'success' }}
run: exit 1
if: ${{ needs.integration-test.result != 'success' }}
run: exit 1

0 comments on commit 01ce0be

Please sign in to comment.