Repository navigation
124 lines (111 loc) · 4.95 KB
/
Copy pathcheck-script-cache-drift.yml
File metadata and controls
124 lines (111 loc) · 4.95 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
# Nightly (and on demand), the cache-drift job proves the generator cache sound
# (target/gen/exports-cache, populated by verify-scripts.yml): it regenerates
# and audits once with the restored CI cache and once from an empty cache, and
# compares both with each other and the generated files with the committed ones
# (tools/ci/check_cache_drift.py). On drift the job fails, uploads the
# evidence, saves the cold cache over the stale one, and the report job opens
# or updates the `cache-drift` issue.
name: Check Script Cache Drift
env:
XLINGS_VERSION: v2026.10.26.1
XLINGS_NON_INTERACTIVE: '1'
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
# A manual run must not cancel the nightly one (or the reverse).
concurrency:
group: cache-drift-${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
cache-drift:
name: cache drift (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 360
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up the generation toolchain
uses: ./.github/actions/setup-generator
# The cache verify restores: the newest entry under the current salt.
- name: Restore generator export intermediates
uses: actions/cache/restore@v6
with:
path: target/gen/exports-cache
key: exports-cache-v2-${{ runner.os }}-${{ runner.arch }}-llvm-${{ env.LLVM_VERSION }}-${{ hashFiles('tools/gen_exports.py', 'tools/ast_json.py', 'tools/boost_common.py', 'tools/export_policy.toml', 'tools/fetch_mingw_sysroot.py') }}-${{ github.sha }}
restore-keys: |
exports-cache-v2-${{ runner.os }}-${{ runner.arch }}-llvm-${{ env.LLVM_VERSION }}-${{ hashFiles('tools/gen_exports.py', 'tools/ast_json.py', 'tools/boost_common.py', 'tools/export_policy.toml', 'tools/fetch_mingw_sysroot.py') }}-
- name: Compare cached, cold and committed generation
id: drift
run: uv run --project tools --locked python tools/ci/check_cache_drift.py --out target/cache-drift
# Upload before anything replaces the stale entries: the restored
# versions are the evidence of what the cache key missed.
- name: Upload drift evidence
if: ${{ !cancelled() && steps.drift.outcome != 'skipped' }}
uses: actions/upload-artifact@v7
with:
name: cache-drift-${{ runner.os }}
path: target/cache-drift
if-no-files-found: ignore
retention-days: 30
# The cold run rewrote target/gen/exports-cache from scratch. Saved
# under the restore prefix, it is the newest entry, so the next verify
# run restores it instead of the stale one.
- name: Save the cold cache over the stale one
if: ${{ !cancelled() && steps.drift.outputs.cache_drift == 'true' }}
uses: actions/cache/save@v6
with:
path: target/gen/exports-cache
key: exports-cache-v2-${{ runner.os }}-${{ runner.arch }}-llvm-${{ env.LLVM_VERSION }}-${{ hashFiles('tools/gen_exports.py', 'tools/ast_json.py', 'tools/boost_common.py', 'tools/export_policy.toml', 'tools/fetch_mingw_sysroot.py') }}-${{ github.sha }}-cold-${{ github.run_id }}
report:
name: report cache drift
needs: cache-drift
if: ${{ !cancelled() && needs.cache-drift.result != 'skipped' }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
sparse-checkout: tools
# Absent when no platform got as far as the comparison.
- name: Download drift results
continue-on-error: true
uses: actions/download-artifact@v8
with:
pattern: cache-drift-*
path: drift
# One open issue tracks drift: later runs comment on it instead of
# opening duplicates.
- name: Open or update the cache-drift issue
shell: bash
run: |
set -euo pipefail
mkdir -p drift
python3 tools/ci/check_cache_drift.py --summarize drift \
--run-url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
> issue.md
if [ ! -s issue.md ]; then
echo "no drift reported"
exit 0
fi
gh label create cache-drift --color B60205 \
--description "Generator cache replayed output a cold run does not produce" \
--force
number="$(gh issue list --label cache-drift --state open \
--json number --jq '.[0].number // empty')"
if [ -n "$number" ]; then
gh issue comment "$number" --body-file issue.md
else
gh issue create --title "Generator cache drift detected" \
--label cache-drift --body-file issue.md
fi