-
Notifications
You must be signed in to change notification settings - Fork 7
212 lines (186 loc) · 8.13 KB
/
Copy pathtest.yaml
File metadata and controls
212 lines (186 loc) · 8.13 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Build and Test Julia Package
on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- develop
permissions:
contents: read
concurrency:
# One in-flight run per branch/PR. Superseded pull request runs are cancelled;
# runs on main/develop are allowed to finish so every merged commit is verified.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
changes:
name: Detect Julia changes
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
pull-requests: read
outputs:
julia: ${{ steps.filter.outputs.julia }}
steps:
- name: Check whether the pull request touches Julia code
id: filter
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
# Report the decision to the job log as well as the run summary, so
# `why did/didn't this run?` is answerable from either one.
say() { echo "$1"; echo "$1" >> "$GITHUB_STEP_SUMMARY"; }
# Pushes to main/develop always run: every merged commit gets verified.
if [ "${{ github.event_name }}" != "pull_request" ]; then
echo "julia=true" >> "$GITHUB_OUTPUT"
say "Not a pull request — running the full test suite."
exit 0
fi
files=$(gh api --paginate "repos/${REPO}/pulls/${PR_NUMBER}/files" --jq '.[].filename')
# Allowlist of what test/runtests.jl actually exercises: the package
# itself, the tests and their fixtures, the example decks the tests run
# end-to-end, the dependency set (declared in Project.toml and pinned in
# ci/manifests), and this workflow. Anything not listed here does not
# trigger a run, so new untested Julia (benchmarks, docs scripts, a
# future tools/ directory) is excluded by default rather than by
# remembering to exclude it.
tested='(^src/|^test/|^examples/|^ci/manifests/|^Project\.toml$|^\.github/workflows/test\.yaml$)'
relevant=$(printf '%s\n' "$files" | grep -E "$tested" || true)
say "### Julia change detection"
say ""
if [ -n "$relevant" ]; then
say "Running the test suite. Matched files:"
say '```'
say "$relevant"
say '```'
else
say "No Julia code, test data or example decks changed — skipping the test suite."
say ""
say "Files considered:"
say '```'
say "$files"
say '```'
fi
if [ -n "$relevant" ]; then
echo "julia=true" >> "$GITHUB_OUTPUT"
else
echo "julia=false" >> "$GITHUB_OUTPUT"
fi
test:
name: runtests ${{ matrix.version }} - ${{ matrix.os }}
needs: changes
if: needs.changes.outputs.julia == 'true'
runs-on: ${{ matrix.os }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
version:
- '1.11'
- '1.x' # latest (currently 1.12)
os:
- ubuntu-latest
env:
DEPOT_PATHS: |
~/.julia/artifacts
~/.julia/packages
~/.julia/registries
~/.julia/compiled
~/.julia/scratchspaces
~/.julia/logs
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Julia
id: julia
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
# Keyed on the resolved Julia version, not the matrix label: precompiled .ji
# files are tied to the exact Julia build, so a patch release invalidates
# every one of them. Cache entries are immutable, so were the key not to
# rotate the run would recompile the whole tree, hit the unchanged key, skip
# the save as having nothing new, and repeat that forever. The version-only
# fallback still reuses packages, artifacts and registries across a bump; the
# next push to the default branch repopulates under the new key.
- name: Restore the Julia depot
id: depot
uses: actions/cache/restore@v4
with:
path: ${{ env.DEPOT_PATHS }}
key: julia-depot-${{ matrix.os }}-${{ matrix.version }}-${{ steps.julia.outputs.julia-version }}-${{ hashFiles('Project.toml', 'ci/manifests/Manifest-v*.toml') }}
restore-keys: |
julia-depot-${{ matrix.os }}-${{ matrix.version }}-${{ steps.julia.outputs.julia-version }}-
julia-depot-${{ matrix.os }}-${{ matrix.version }}-
- name: Pin the CI dependency set
run: |
set -euo pipefail
minor=$(julia -e 'print(VERSION.major, ".", VERSION.minor)')
pinned="ci/manifests/Manifest-v${minor}.toml"
if [ ! -f "$pinned" ]; then
echo "::warning::No pinned dependency set for Julia ${minor}; resolving fresh. Generate one with 'julia +${minor} ci/manifests/update.jl'."
exit 0
fi
cp "$pinned" Manifest.toml
echo "Pinned dependency set: ${pinned}"
recorded=$(cat ci/manifests/project.sha256)
actual=$(shasum -a 256 Project.toml | cut -d ' ' -f 1)
if [ "$recorded" != "$actual" ]; then
echo "::warning::Project.toml has changed since the pinned dependency sets were generated, so ${pinned} may be stale. Regenerate with ci/manifests/update.jl."
fi
- name: Build Julia packages
uses: julia-actions/julia-buildpkg@v1
with:
ignore-no-cache: true
# Coverage instrumentation is off: nothing consumes the .cov files (they are
# gitignored and never uploaded), and instrumenting slows compute-heavy
# numerical code noticeably. Set coverage: true and add a Codecov upload
# step together if coverage reporting is ever wanted.
- name: Run tests
uses: julia-actions/julia-runtest@v1
with:
coverage: false
# An exact hit has nothing new to store. Otherwise pushes refresh the shared
# default-branch entry, and a pull request writes one only when it restored
# nothing at all -- which happens when this key prefix is cold, as it is the
# first time this runs, after a matrix version is added, or once entries age
# out. That entry is scoped to the pull request's own ref and so cannot be
# reused by another, but seeding it beats discarding a full compile; once the
# default branch has an entry, pull requests always prefix-match and skip.
- name: Prune the depot before caching
if: always() && steps.depot.outputs.cache-hit != 'true' && (github.event_name == 'push' || steps.depot.outputs.cache-matched-key == '')
run: julia --project=. -e 'using Pkg; Pkg.gc()'
- name: Save the Julia depot
if: always() && steps.depot.outputs.cache-hit != 'true' && (github.event_name == 'push' || steps.depot.outputs.cache-matched-key == '')
uses: actions/cache/save@v4
with:
path: ${{ env.DEPOT_PATHS }}
key: julia-depot-${{ matrix.os }}-${{ matrix.version }}-${{ steps.julia.outputs.julia-version }}-${{ hashFiles('Project.toml', 'ci/manifests/Manifest-v*.toml') }}
# Stable check that is present on every pull request, whether or not the suite
# ran. Point branch protection at this job so skipped runs do not block merges.
test-status:
name: Tests
needs: [changes, test]
if: always()
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Report suite result
run: |
set -euo pipefail
if [ "${{ needs.changes.result }}" != "success" ]; then
echo "Change detection failed; cannot tell whether tests were needed."
exit 1
fi
case "${{ needs.test.result }}" in
success) echo "Test suite passed." ;;
skipped) echo "No Julia code changed; test suite intentionally skipped." ;;
*) echo "Test suite result: ${{ needs.test.result }}"; exit 1 ;;
esac