Repository navigation
98 lines (86 loc) · 2.83 KB
/
Copy pathci.yml
File metadata and controls
98 lines (86 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: CI
on:
push:
branches: [main]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
# Projects opt in to CI simply by having a .tool-versions file in their top level directory
discover:
name: Discover projects
runs-on: ubuntu-latest
outputs:
projects: ${{ steps.find.outputs.projects }}
steps:
- uses: actions/checkout@v5
- name: Find projects with a .tool-versions
id: find
run: |
projects=$(
for dir in */; do
if [[ -f "${dir}.tool-versions" ]]; then
echo "${dir%/}"
fi
done | jq -R . | jq -sc .
)
echo "Discovered: $projects"
echo "projects=$projects" >> "$GITHUB_OUTPUT"
# Guards against a half-adopted project silently dropping out of CI.
# If a project declares a .tool-versions it must also provide the scripts the build job runs.
conform:
name: Check project structure
needs: discover
if: needs.discover.outputs.projects != '[]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Every project must have executable setup and test scripts
env:
PROJECTS: ${{ needs.discover.outputs.projects }}
run: |
status=0
for project in $(jq -r '.[]' <<< "$PROJECTS"); do
for script in setup test; do
path="$project/script/$script"
if [[ ! -f "$path" ]]; then
echo "::error file=$project/.tool-versions::$project declares a .tool-versions but has no $path"
status=1
elif [[ ! -x "$path" ]]; then
echo "::error file=$path::$path is not executable, run: chmod +x $path"
status=1
fi
done
done
exit $status
build:
name: ${{ matrix.project }}
needs: discover
if: needs.discover.outputs.projects != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
project: ${{ fromJSON(needs.discover.outputs.projects) }}
defaults:
run:
working-directory: ${{ matrix.project }}
steps:
- uses: actions/checkout@v5
# Optional extra step for toolchains that build from source and need system
# libraries the runner does not ship (e.g. php).
# Runs before mise, so it cannot rely on dependencies in `.tool-versions`.
- name: Install system packages
run: |
if [[ -x script/system-packages ]]; then
./script/system-packages
fi
- name: Install the toolchain declared in .tool-versions
uses: jdx/mise-action@v2
with:
working_directory: ${{ matrix.project }}
- run: ./script/setup
- run: ./script/test