1
1
name : Eval
2
2
3
- on : pull_request_target
3
+ on :
4
+ pull_request_target :
5
+ push :
6
+ # Keep this synced with ci/request-reviews/dev-branches.txt
7
+ branches :
8
+ - master
9
+ - staging
10
+ - release-*
11
+ - staging-*
12
+ - haskell-updates
13
+ - python-updates
4
14
5
15
permissions :
6
16
contents : read
11
21
runs-on : ubuntu-latest
12
22
outputs :
13
23
mergedSha : ${{ steps.merged.outputs.mergedSha }}
24
+ baseSha : ${{ steps.baseSha.outputs.baseSha }}
14
25
systems : ${{ steps.systems.outputs.systems }}
15
26
steps :
16
27
# Important: Because of `pull_request_target`, this doesn't check out the PR,
@@ -24,23 +35,39 @@ jobs:
24
35
id : merged
25
36
env :
26
37
GH_TOKEN : ${{ github.token }}
38
+ GH_EVENT : ${{ github.event_name }}
27
39
run : |
28
- if mergedSha=$(base/ci/get-merge-commit.sh ${{ github.repository }} ${{ github.event.number }}); then
29
- echo "Checking the merge commit $mergedSha"
30
- echo "mergedSha=$mergedSha" >> "$GITHUB_OUTPUT"
31
- else
32
- # Skipping so that no notifications are sent
33
- echo "Skipping the rest..."
34
- fi
40
+ case "$GH_EVENT" in
41
+ push)
42
+ echo "mergedSha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
43
+ ;;
44
+ pull_request_target)
45
+ if mergedSha=$(base/ci/get-merge-commit.sh ${{ github.repository }} ${{ github.event.number }}); then
46
+ echo "Checking the merge commit $mergedSha"
47
+ echo "mergedSha=$mergedSha" >> "$GITHUB_OUTPUT"
48
+ else
49
+ # Skipping so that no notifications are sent
50
+ echo "Skipping the rest..."
51
+ fi
52
+ ;;
53
+ esac
35
54
rm -rf base
36
55
- name : Check out the PR at the test merge commit
37
56
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38
57
# Add this to _all_ subsequent steps to skip them
39
58
if : steps.merged.outputs.mergedSha
40
59
with :
41
60
ref : ${{ steps.merged.outputs.mergedSha }}
61
+ fetch-depth : 2
42
62
path : nixpkgs
43
63
64
+ - name : Determine base commit
65
+ if : github.event_name == 'pull_request_target' && steps.merged.outputs.mergedSha
66
+ id : baseSha
67
+ run : |
68
+ baseSha=$(git -C nixpkgs rev-parse HEAD^1)
69
+ echo "baseSha=$baseSha" >> "$GITHUB_OUTPUT"
70
+
44
71
- name : Install Nix
45
72
uses : cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
46
73
if : steps.merged.outputs.mergedSha
@@ -105,6 +132,8 @@ jobs:
105
132
name : Process
106
133
runs-on : ubuntu-latest
107
134
needs : [ outpaths, attrs ]
135
+ outputs :
136
+ baseRunId : ${{ steps.baseRunId.outputs.baseRunId }}
108
137
steps :
109
138
- name : Download output paths and eval stats for all systems
110
139
uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
@@ -124,18 +153,98 @@ jobs:
124
153
- name : Combine all output paths and eval stats
125
154
run : |
126
155
nix-build nixpkgs/ci -A eval.combine \
127
- --arg resultsDir ./intermediate
156
+ --arg resultsDir ./intermediate \
157
+ -o prResult
128
158
129
159
- name : Upload the combined results
130
160
uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
131
161
with :
132
162
name : result
133
- path : result /*
163
+ path : prResult /*
134
164
165
+ - name : Get base run id
166
+ if : needs.attrs.outputs.baseSha
167
+ id : baseRunId
168
+ run : |
169
+ set -e
170
+
171
+ # TODO: Wait until it's done
172
+ # Get the latest eval.yml workflow run for the PR's base commit
173
+ if ! run=$(gh api --method GET /repos/"$REPOSITORY"/actions/workflows/eval.yml/runs \
174
+ -f head_sha="$BASE_SHA" \
175
+ --jq '.workflow_runs | sort_by(.run_started_at) | .[-1]') \
176
+ || [[ -z "$run" ]]; then
177
+ echo "Could not find an eval.yml workflow run for $BASE_SHA, cannot make comparison"
178
+ exit 0
179
+ fi
180
+ echo "Comparing against $(jq .html_url <<< "$run")"
181
+ runId=$(jq .id <<< "$run")
182
+ conclusion=$(jq -r .conclusion <<< "$run")
183
+
184
+ while [[ "$conclusion" == null ]]; do
185
+ echo "Workflow not done, waiting 10 seconds before checking again"
186
+ sleep 10
187
+ conclusion=$(gh api /repos/"$REPOSITORY"/actions/runs/"$runId" --jq '.conclusion')
188
+ done
189
+
190
+ if [[ "$conclusion" != "success" ]]; then
191
+ echo "Workflow was not successful, cannot make comparison"
192
+ exit 0
193
+ fi
135
194
136
- # TODO: Run this workflow also on `push` (on at least the main development branches)
137
- # Then add an extra step here that waits for the base branch (not the merge base, because that could be very different)
138
- # to have completed the eval, then use
139
- # gh api --method GET /repos/NixOS/nixpkgs/actions/workflows/eval.yml/runs -f head_sha=<BASE>
140
- # and follow it to the artifact results, where you can then download the outpaths.json from the base branch
141
- # That can then be used to compare the number of changed paths, get evaluation stats and ping appropriate reviewers
195
+ echo "baseRunId=$runId" >> "$GITHUB_OUTPUT"
196
+ env :
197
+ REPOSITORY : ${{ github.repository }}
198
+ BASE_SHA : ${{ needs.attrs.outputs.baseSha }}
199
+ GH_TOKEN : ${{ github.token }}
200
+
201
+ - uses : actions/download-artifact@v4
202
+ if : steps.baseRunId.outputs.baseRunId
203
+ with :
204
+ name : result
205
+ path : baseResult
206
+ github-token : ${{ github.token }}
207
+ run-id : ${{ steps.baseRunId.outputs.baseRunId }}
208
+
209
+ - name : Compare against the base branch
210
+ if : steps.baseRunId.outputs.baseRunId
211
+ run : |
212
+ nix-build nixpkgs/ci -A eval.compare \
213
+ --arg beforeResultDir ./baseResult \
214
+ --arg afterResultDir ./prResult \
215
+ -o comparison
216
+
217
+ # TODO: Request reviews from maintainers for packages whose files are modified in the PR
218
+
219
+ - name : Upload the combined results
220
+ if : steps.baseRunId.outputs.baseRunId
221
+ uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
222
+ with :
223
+ name : comparison
224
+ path : comparison/*
225
+
226
+ # Separate job to have a very tightly scoped PR write token
227
+ tag :
228
+ name : Tag
229
+ runs-on : ubuntu-latest
230
+ needs : process
231
+ if : needs.process.outputs.baseRunId
232
+ permissions :
233
+ pull-requests : write
234
+ steps :
235
+ - name : Download process result
236
+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
237
+ with :
238
+ name : comparison
239
+ path : comparison
240
+
241
+ - name : Tagging pull request
242
+ run : |
243
+ ls -laa
244
+ ls -laa comparison
245
+ gh api \
246
+ --method POST \
247
+ /repos/${{ github.repository }}/issues/${{ github.event.number }}/labels \
248
+ --input <(jq -c '{ labels: .labels }' comparison/changed-paths.json)
249
+ env :
250
+ GH_TOKEN : ${{ github.token }}
0 commit comments