Skip to content

Commit

Permalink
CI all test is the only required test
Browse files Browse the repository at this point in the history
This means we can just use the `needs` of that test to determine which
CI actions are required for status checks to pass.
  • Loading branch information
DigitalBrains1 committed Sep 12, 2023
1 parent 65ef8c1 commit a93967a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
32 changes: 32 additions & 0 deletions .ci/all_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""
Makes sure:
* All jobs are listed in the 'all' job
* Only existing tests are listed
"""

import sys
import yaml

CI_PATH = '.github/workflows/ci.yaml'
ALL_TEST = 'all'


def main():
ci_yaml_fp = open(CI_PATH, 'r')
ci_yaml_parsed = yaml.load(ci_yaml_fp, Loader=yaml.FullLoader)

all_jobs = set(ci_yaml_parsed['jobs'].keys()) - {ALL_TEST}
all_needs = set(ci_yaml_parsed['jobs'][ALL_TEST]['needs'])

if all_jobs - all_needs:
sys.exit(f'Not all jobs mentioned in {ALL_TEST}.needs: '
f'{all_jobs - all_needs}')

if all_needs - all_jobs:
sys.exit(f'Non-existing jobs found in {ALL_TEST}.needs: '
f'{all_needs - all_jobs}')


if __name__ == '__main__':
main()
33 changes: 30 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,41 @@ jobs:
run: |
cabal v2-run unittests
# Mandatory check on GitHub
# Mechanism copied from https://github.com/clash-lang/clash-compiler/
all:
name: All jobs finished
needs:
- cabal
- stack
runs-on: ubuntu-latest
steps:
- name: Void
- name: Checkout
uses: actions/checkout@v3

- name: Check dependencies for failures
run: |
# Test all dependencies for success/failure
set -x
success="${{ contains(needs.*.result, 'success') }}"
fail="${{ contains(needs.*.result, 'failure') }}"
set +x
# Test whether success/fail variables contain sane values
if [[ "${success}" != "true" && "${success}" != "false" ]]; then exit 1; fi
if [[ "${fail}" != "true" && "${fail}" != "false" ]]; then exit 1; fi
# We want to fail if one or more dependencies fail. For safety, we introduce
# a second check: if no dependencies succeeded something weird is going on.
if [[ "${fail}" == "true" || "${success}" == "false" ]]; then
echo "One or more dependency failed, or no dependency succeeded."
exit 1
fi
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get -y install python3-yaml
- name: Check that the 'all' job depends on all other jobs
run: |
echo "All good"
.ci/all_check.py

0 comments on commit a93967a

Please sign in to comment.