Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add all check to CI #97

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/scripts/all_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""
Makes sure:

* All jobs are listed in the 'all' job
* Only existing tests are listed

"""

# SPDX-FileCopyrightText: 2022 Google LLC
#
# SPDX-License-Identifier: Apache-2.0

import sys
import yaml

CI_PATH = ".github/workflows/ci.yml"
ALL_TEST = "all"

def main():
ci_yml_fp = open(CI_PATH, "r")
ci_yml_parsed = yaml.load(ci_yml_fp, Loader=yaml.FullLoader)

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

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

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


if __name__ == '__main__':
main()
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,46 @@ jobs:
- name: Whitespace
run: |
.ci/test_whitespace.sh

# Mandatory check on GitHub
all:
name: All jobs finished
if: always()
needs: [
cabal,
fourmolu,
linting,
stack,
]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- 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: |
.github/scripts/all_check.py
Loading