Skip to content

Commit 41ab3a4

Browse files
Merge pull request #2388 from clash-lang/all-check
Various CI improvements
2 parents 5357a2b + 8f9614f commit 41ab3a4

File tree

2 files changed

+85
-5
lines changed

2 files changed

+85
-5
lines changed

.ci/all_check.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Makes sure:
4+
* All jobs are listed in the 'all' job
5+
* Only existing tests are listed
6+
"""
7+
8+
import sys
9+
import yaml
10+
11+
CI_PATH = ".github/workflows/ci.yml"
12+
ALL_TEST = "all"
13+
14+
def main():
15+
ci_yml_fp = open(CI_PATH, "r")
16+
ci_yml_parsed = yaml.load(ci_yml_fp, Loader=yaml.FullLoader)
17+
18+
all_jobs = set(ci_yml_parsed['jobs'].keys()) - {ALL_TEST}
19+
all_needs = set(ci_yml_parsed["jobs"][ALL_TEST]["needs"])
20+
21+
if all_jobs - all_needs:
22+
sys.exit(f"Not all jobs mentioned in {ALL_TEST}.needs: {all_jobs - all_needs}")
23+
24+
if all_needs - all_jobs:
25+
sys.exit(f"Non-existing jobs found in {ALL_TEST}.needs: {all_needs - all_jobs}")
26+
27+
28+
if __name__ == '__main__':
29+
main()

.github/workflows/ci.yml

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
name: CI
2-
on: pull_request
2+
3+
on:
4+
push:
5+
branches:
6+
# PRs can only use caches from their target branch. We therefore need to
7+
# make sure we run on 'master' too.
8+
- master
9+
pull_request:
310

411
concurrency:
512
group: ${{ github.head_ref }}
@@ -31,8 +38,8 @@ jobs:
3138
ghc: 9.0.2
3239

3340
steps:
34-
- uses: actions/checkout@v2
35-
- uses: haskell/actions/setup@v1
41+
- uses: actions/checkout@v3
42+
- uses: haskell/actions/setup@v2
3643
id: setup-haskell
3744
with:
3845
ghc-version: ${{ matrix.ghc }}
@@ -51,6 +58,9 @@ jobs:
5158
cp .ci/stack-${{ matrix.ghc }}.yaml stack.yaml
5259
5360
- name: Cache
61+
# Note: we're stuck on v1 because of:
62+
#
63+
# https://github.com/actions/cache/issues/666
5464
uses: actions/cache@v1
5565
with:
5666
path: |
@@ -124,7 +134,7 @@ jobs:
124134

125135
steps:
126136
- name: Checkout
127-
uses: actions/checkout@v2
137+
uses: actions/checkout@v3
128138
with:
129139
submodules: true
130140
ref: ${{ github.event.pull_request.head.ref }}
@@ -140,7 +150,7 @@ jobs:
140150
mv cabal.project.freeze frozen
141151
142152
- name: Restore Cache
143-
uses: actions/cache@v2
153+
uses: actions/cache@v3
144154
with:
145155
path: |
146156
dist-newstyle
@@ -168,3 +178,44 @@ jobs:
168178

169179
- name: Testsuite (SystemVerilog)
170180
run: cabal v2-run clash-testsuite -- -j$THREADS --hide-successes -p .SystemVerilog --no-modelsim --no-vivado
181+
182+
183+
all:
184+
name: All jobs finished
185+
if: always()
186+
needs: [
187+
build_mac_windows,
188+
build_and_test,
189+
]
190+
runs-on: ubuntu-22.04
191+
steps:
192+
- name: Checkout
193+
uses: actions/checkout@v3
194+
195+
- name: Check dependencies for failures
196+
run: |
197+
# Test all dependencies for success/failure
198+
set -x
199+
success="${{ contains(needs.*.result, 'success') }}"
200+
fail="${{ contains(needs.*.result, 'failure') }}"
201+
set +x
202+
203+
# Test whether success/fail variables contain sane values
204+
if [[ "${success}" != "true" && "${success}" != "false" ]]; then exit 1; fi
205+
if [[ "${fail}" != "true" && "${fail}" != "false" ]]; then exit 1; fi
206+
207+
# We want to fail if one or more dependencies fail. For safety, we introduce
208+
# a second check: if no dependencies succeeded something weird is going on.
209+
if [[ "${fail}" == "true" || "${success}" == "false" ]]; then
210+
echo "One or more dependency failed, or no dependency succeeded."
211+
exit 1
212+
fi
213+
214+
- name: Install dependencies
215+
run: |
216+
sudo apt-get update
217+
sudo apt-get -y install python3-yaml
218+
219+
- name: Check that the 'all' job depends on all other jobs
220+
run: |
221+
.ci/all_check.py

0 commit comments

Comments
 (0)