-
Notifications
You must be signed in to change notification settings - Fork 57
172 lines (157 loc) · 5.96 KB
/
ci.yaml
File metadata and controls
172 lines (157 loc) · 5.96 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
name: ci
# Combined CI pipeline. `fix` runs first, post-processing same-repo PRs
# that bump Go modules / npm manifests so the workspace ends up in a
# state the Nix build can consume (per-module `go mod tidy` plus
# `nix-update` of vendor hashes; see https://github.com/golang/go/issues/63901).
# If `fix` pushed a corrective commit, downstream nix-checks jobs are
# skipped — the resulting `pull_request synchronize` triggers a fresh
# CI run on the corrected SHA, and branch protection on the PR HEAD
# prevents merging until that fresh run reports success.
on:
pull_request:
permissions:
contents: read
concurrency:
group: ci-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
fix:
# Forks can't be pushed to (their GITHUB_TOKEN is read-only and
# secrets are not exposed); skip the job entirely there.
if: github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
outputs:
pushed: ${{ steps.push.outputs.pushed }}
steps:
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
relevant:
- 'go.mod'
- 'go.sum'
- 'bindings/go/scip/go.mod'
- 'bindings/go/scip/go.sum'
- 'reprolang/go.mod'
- 'reprolang/go.sum'
- 'bindings/typescript/package.json'
- 'bindings/typescript/package-lock.json'
- name: Generate GitHub App token
if: steps.filter.outputs.relevant == 'true'
id: app-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.RENOVATE_FIX_APP_ID }}
private-key: ${{ secrets.RENOVATE_FIX_APP_PRIVATE_KEY }}
- if: steps.filter.outputs.relevant == 'true'
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.ref }}
# Pushing under the App identity (not GITHUB_TOKEN) makes
# `git push` fire `pull_request synchronize`, which triggers
# a fresh CI run that revalidates the corrected SHA.
token: ${{ steps.app-token.outputs.token }}
- if: steps.filter.outputs.relevant == 'true'
uses: DeterminateSystems/nix-installer-action@v22
with:
summarize: false
- if: steps.filter.outputs.relevant == 'true'
uses: DeterminateSystems/magic-nix-cache-action@v13
- name: Tidy Go modules
if: steps.filter.outputs.relevant == 'true'
env:
GOWORK: 'off'
# https://github.com/golang/go/issues/63901
run: |
set -euo pipefail
for dir in bindings/go/scip . reprolang; do
(cd "$dir" && nix develop --command go mod tidy)
done
- name: Recompute vendor hashes with nix-update
if: steps.filter.outputs.relevant == 'true'
run: |
set -euo pipefail
# nix-update only auto-resolves packages.<system>.<attr>; for
# attributes under `checks` we must pass the full dotted path.
# One attribute per invocation; sequential to avoid concurrent
# writes to the same .nix files.
for attr in \
packages.x86_64-linux.scip \
checks.x86_64-linux.go-bindings \
checks.x86_64-linux.reprolang \
checks.x86_64-linux.typescript-bindings; do
nix run github:Mic92/nix-update -- \
--flake --version=skip "$attr"
done
- name: Commit and push
id: push
if: steps.filter.outputs.relevant == 'true'
run: |
set -euo pipefail
if git diff --quiet; then
echo "No changes; nothing to push."
echo "pushed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am 'chore: tidy Go modules and update vendor hashes'
git push
echo "pushed=true" >> "$GITHUB_OUTPUT"
list:
needs: fix
# Skip downstream when `fix` pushed corrective commits — the
# resulting `pull_request synchronize` triggers a fresh CI run that
# validates the corrected SHA, and branch protection on the PR
# HEAD prevents merging until that fresh run reports success.
if: always() && needs.fix.outputs.pushed != 'true'
runs-on: ubuntu-latest
outputs:
checks: ${{ steps.checks.outputs.result }}
packages: ${{ steps.packages.outputs.result }}
steps:
- uses: actions/checkout@v6
- uses: DeterminateSystems/nix-installer-action@v22
- id: checks
run: |
CHECKS=$(nix eval .#checks.x86_64-linux \
--apply builtins.attrNames --json)
echo "result=$CHECKS" >> "$GITHUB_OUTPUT"
- id: packages
run: |
PACKAGES=$(nix eval .#packages.x86_64-linux \
--apply 'ps: builtins.attrNames (removeAttrs ps ["default"])' \
--json)
echo "result=$PACKAGES" >> "$GITHUB_OUTPUT"
checks:
needs: list
runs-on: ubuntu-latest
strategy:
matrix:
check: ${{ fromJSON(needs.list.outputs.checks) }}
steps:
- uses: actions/checkout@v6
- uses: DeterminateSystems/nix-installer-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v13
- run: nix build .#checks.x86_64-linux.${{ matrix.check }}
packages:
needs: list
runs-on: ubuntu-latest
strategy:
matrix:
package: ${{ fromJSON(needs.list.outputs.packages) }}
steps:
- uses: actions/checkout@v6
- uses: DeterminateSystems/nix-installer-action@v22
- uses: DeterminateSystems/magic-nix-cache-action@v13
- run: nix run .#${{ matrix.package }}
- run: git diff --exit-code
ci-pass:
if: always()
needs: [fix, list, checks, packages]
runs-on: ubuntu-latest
steps:
- if: >-
contains(needs.*.result, 'failure') ||
contains(needs.*.result, 'cancelled')
run: exit 1