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
4
13
5
14
permissions :
6
15
contents : read
11
20
runs-on : ubuntu-latest
12
21
outputs :
13
22
mergedSha : ${{ steps.merged.outputs.mergedSha }}
23
+ baseSha : ${{ steps.baseSha.outputs.baseSha }}
14
24
systems : ${{ steps.systems.outputs.systems }}
15
25
steps :
16
26
# Important: Because of `pull_request_target`, this doesn't check out the PR,
@@ -24,23 +34,39 @@ jobs:
24
34
id : merged
25
35
env :
26
36
GH_TOKEN : ${{ github.token }}
37
+ GH_EVENT : ${{ github.event_name }}
27
38
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
39
+ case "$GH_EVENT" in
40
+ push)
41
+ echo "mergedSha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
42
+ ;;
43
+ pull_request_target)
44
+ if mergedSha=$(base/ci/get-merge-commit.sh ${{ github.repository }} ${{ github.event.number }}); then
45
+ echo "Checking the merge commit $mergedSha"
46
+ echo "mergedSha=$mergedSha" >> "$GITHUB_OUTPUT"
47
+ else
48
+ # Skipping so that no notifications are sent
49
+ echo "Skipping the rest..."
50
+ fi
51
+ ;;
52
+ esac
35
53
rm -rf base
36
54
- name : Check out the PR at the test merge commit
37
55
uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
38
56
# Add this to _all_ subsequent steps to skip them
39
57
if : steps.merged.outputs.mergedSha
40
58
with :
41
59
ref : ${{ steps.merged.outputs.mergedSha }}
60
+ fetch-depth : 2
42
61
path : nixpkgs
43
62
63
+ - name : Determine base commit
64
+ if : github.event_name == 'pull_request_target' && steps.merged.outputs.mergedSha
65
+ id : baseSha
66
+ run : |
67
+ baseSha=$(git -C nixpkgs rev-parse HEAD^1)
68
+ echo "baseSha=$baseSha" >> "$GITHUB_OUTPUT"
69
+
44
70
- name : Install Nix
45
71
uses : cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
46
72
if : steps.merged.outputs.mergedSha
@@ -124,18 +150,71 @@ jobs:
124
150
- name : Combine all output paths and eval stats
125
151
run : |
126
152
nix-build nixpkgs/ci -A eval.combine \
127
- --arg resultsDir ./intermediate
153
+ --arg resultsDir ./intermediate \
154
+ -o prResult
128
155
129
156
- name : Upload the combined results
130
157
uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
131
158
with :
132
159
name : result
133
- path : result/*
160
+ path : prResult/*
161
+
162
+ - name : Get base run id
163
+ if : needs.attrs.outputs.baseSha
164
+ id : baseRunId
165
+ run : |
166
+ set -e
167
+
168
+ # TODO: Wait until it's done
169
+ # Get the latest eval.yml workflow run for the PR's base commit
170
+ if ! run=$(gh api --method GET /repos/"$REPOSITORY"/actions/workflows/eval.yml/runs \
171
+ -f head_sha="$BASE_SHA" \
172
+ --jq '.workflow_runs | sort_by(.run_started_at) | .[-1]')
173
+ || [[ -z "$run" ]]; then
174
+ echo "Could not find an eval.yml workflow run for $BASE_SHA, cannot make comparison"
175
+ exit 0
176
+ fi
177
+ echo "Comparing against $(jq .html_url <<< "$run")"
178
+ runId=$(jq .id <<< "$run")
179
+ conclusion=$(jq .conclusion <<< "$run")
180
+
181
+ while [[ "$conclusion" == null ]]; do
182
+ echo "Workflow not done, waiting 10 seconds before checking again"
183
+ sleep 10
184
+ conclusion=$(gh api /repos/"$REPOSITORY"/actions/runs/"$runId" --jq '.conclusion')
185
+ done
186
+
187
+ if [[ "$conclusion" != "success" ]]; then
188
+ echo "Workflow was not successful, cannot make comparison"
189
+ exit 0
190
+ fi
191
+
192
+ echo "baseRunId=$runId" >> "$GITHUB_OUTPUT"
193
+ env :
194
+ REPOSITORY : ${{ github.repository }}
195
+ BASE_SHA : ${{ needs.attrs.outputs.baseSha }}
134
196
197
+ - uses : actions/download-artifact@v4
198
+ if : steps.baseRunId.outputs.baseRunId
199
+ with :
200
+ name : result
201
+ path : baseResult
202
+ github-token : ${{ github.token }}
203
+ run-id : ${{ steps.baseRunId.outputs.baseRunId }}
204
+
205
+ - name : Compare against the base branch
206
+ if : steps.baseRunId.outputs.baseRunId
207
+ run : |
208
+ nix-build nixpkgs/ci -A eval.compare \
209
+ --arg beforeResultDir ./baseResult \
210
+ --arg afterResultDir ./prResult \
211
+ -o comparison
135
212
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
213
+ # TODO: Request reviews from maintainers for packages whose files are modified in the PR
214
+
215
+ - name : Upload the combined results
216
+ if : steps.baseRunId.outputs.baseRunId
217
+ uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
218
+ with :
219
+ name : comparison
220
+ path : comparison/*
0 commit comments