Skip to content

Commit 62a0dfb

Browse files
committed
ci/update: cancel gracefully
Cancelling via `exit 1` will mark the workflow as "failed". Instead we can write a `cancelled` step output and have all the following steps be conditional.
1 parent 4652e38 commit 62a0dfb

File tree

1 file changed

+56
-29
lines changed

1 file changed

+56
-29
lines changed

.github/workflows/update.yml

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ jobs:
103103
fi
104104
105105
- name: Check if nixpkgs input was changed
106+
id: changes
106107
if: github.event_name == 'schedule' || inputs.check_for_changes
107108
env:
108109
pr_num: ${{ steps.open_pr_info.outputs.number }}
109110
pr_url: ${{ steps.open_pr_info.outputs.url }}
110-
changes: ${{ steps.flake_lock.outputs.body || 'No changes' }}
111111
run: |
112112
getAttr() {
113113
nix eval --raw --impure \
@@ -126,36 +126,15 @@ jobs:
126126
old=$(getNixpkgsRev "github:$repo/$old_branch")
127127
new=$(getNixpkgsRev "$PWD")
128128
129-
if [[ "$old" = "$new" ]]; then
130-
(
131-
echo "nixpkgs rev has not changed ($new). Stopping..."
132-
echo 'You can re-run the workflow manually to update anyway.'
133-
) >&2
134-
(
135-
echo '## Update cancelled'
136-
echo
137-
if [[ -n "$pr_num" ]]; then
138-
echo -n 'The `nixpkgs` input has not changed compared to the already open PR: '
139-
echo "[#$pr_num]($pr_url) (\`nixpkgs.rev: $new\`)."
140-
else
141-
echo -n 'The `nixpkgs` input has not changed compared to the base branch: '
142-
echo "\`$base_branch\`"
143-
fi
144-
echo
145-
echo 'The following changes would have been made:'
146-
echo '```'
147-
echo "$changes"
148-
echo '```'
149-
echo
150-
echo 'You can re-run the workflow manually to update anyway.'
151-
echo
152-
) >> $GITHUB_STEP_SUMMARY
153-
exit 1
154-
fi
129+
(
130+
echo "old_rev=$old"
131+
echo "new_rev=$new"
132+
[[ "$old" = "$new" ]] && echo 'cancelled=1'
133+
) >> $GITHUB_OUTPUT
155134
156135
- name: Update generated files
157136
id: generate
158-
if: inputs.generate || github.event_name == 'schedule'
137+
if: (!steps.changes.outputs.cancelled) && (inputs.generate || github.event_name == 'schedule')
159138
run: |
160139
old=$(git show --no-patch --format=%h)
161140
nix-build ./update-scripts -A generate
@@ -178,6 +157,7 @@ jobs:
178157
179158
- name: Create Pull Request
180159
id: pr
160+
if: (!steps.changes.outputs.cancelled)
181161
uses: peter-evans/create-pull-request@v6
182162
with:
183163
add-paths: "!**"
@@ -195,7 +175,7 @@ jobs:
195175
${{ steps.generate.outputs.body || 'No changes' }}
196176
197177
- name: Print summary
198-
if: ${{ steps.pr.outputs.pull-request-number }}
178+
if: steps.pr.outputs.pull-request-number
199179
run: |
200180
num="${{ steps.pr.outputs.pull-request-number }}"
201181
pr_url="${{ steps.pr.outputs.pull-request-url }}"
@@ -214,3 +194,50 @@ jobs:
214194
echo >> $GITHUB_STEP_SUMMARY
215195
echo "[#${num}](${pr_url}) was ${operation}." >> $GITHUB_STEP_SUMMARY
216196
echo >> $GITHUB_STEP_SUMMARY
197+
198+
- name: Print cancellation summary
199+
if: (!steps.pr.outputs.pull-request-number)
200+
env:
201+
pr_num: ${{ steps.open_pr_info.outputs.number }}
202+
pr_url: ${{ steps.open_pr_info.outputs.url }}
203+
changes: ${{ steps.flake_lock.outputs.body || 'No changes' }}
204+
cancelled: ${{ steps.changes.outputs.cancelled || '' }}
205+
rev: ${{ steps.changes.outputs.new_rev || '' }}
206+
run: |
207+
if [[ -n "$cancelled" ]]; then
208+
( # stdout
209+
echo "nixpkgs rev has not changed ($rev)."
210+
echo 'You can re-run the workflow manually to update anyway.'
211+
) >&2
212+
( # markdown summary
213+
echo '## Update cancelled'
214+
echo
215+
if [[ -n "$pr_num" ]]; then
216+
echo -n 'The `nixpkgs` input has not changed compared to the already open PR: '
217+
echo "[#$pr_num]($pr_url) (\`nixpkgs.rev: ${rev:0:6}\`)."
218+
else
219+
echo -n 'The `nixpkgs` input has not changed compared to the base branch: '
220+
echo "\`$base_branch\`"
221+
fi
222+
echo
223+
echo 'You can re-run the workflow manually to update anyway.'
224+
echo
225+
) >> $GITHUB_STEP_SUMMARY
226+
else
227+
( #stdout
228+
echo "No PR was opened"
229+
) >&2
230+
(
231+
echo "## Not updated"
232+
echo
233+
) >> $GITHUB_STEP_SUMMARY
234+
fi
235+
( # markdown summary
236+
echo
237+
echo 'The following changes would have been made:'
238+
echo
239+
echo '```'
240+
echo "$changes"
241+
echo '```'
242+
echo
243+
) >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)