Skip to content

Commit b0d44b2

Browse files
fix(action): fail on a reportless run and encode the baseline name (#407)
- exit 1 when subenum exits 0 without a report (-dry-run, -version) - URL-encode the baseline artifact name in the gh api query - cover the exit-0 reportless case in CI
1 parent dd5b156 commit b0d44b2

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎.github/workflows/go.yml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,23 @@ jobs:
260260
test "${{ steps.bad.outcome }}" = failure
261261
test -z "${{ steps.bad.outputs.verdict }}"
262262
263+
# -version exits 0 before the outputs are opened, so no report is written.
264+
# The step must still fail rather than pass on the previous use's outputs (#407).
265+
- name: Use the action with -version
266+
id: version
267+
continue-on-error: true
268+
uses: ./
269+
with:
270+
version: source
271+
domain: lab.example
272+
args: -version
273+
274+
- name: Check it failed without a report
275+
shell: bash
276+
run: |
277+
test "${{ steps.version.outcome }}" = failure
278+
test -z "${{ steps.version.outputs.verdict }}"
279+
263280
# found counts the -permute hits too (#363).
264281
- name: Scan with -permute
265282
id: permute

‎action.yml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ runs:
171171
echo "Using the baseline an earlier step in this job saved."
172172
exit 0
173173
fi
174-
run=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$NAME&per_page=1" \
174+
# upload-artifact allows &, +, # and % in names. Encode the name so the
175+
# query string cannot truncate or reinterpret it (#407).
176+
encoded=$(jq -rn --arg n "$NAME" '$n|@uri')
177+
run=$(gh api "repos/$GITHUB_REPOSITORY/actions/artifacts?name=$encoded&per_page=1" \
175178
--jq '.artifacts[0] | select(.expired == false) | .workflow_run.id // empty')
176179
if [ -n "$run" ]; then
177180
gh run download "$run" --repo "$GITHUB_REPOSITORY" --name "$NAME" --dir "$dir"
@@ -240,7 +243,13 @@ runs:
240243
if [ "$resumed" = false ]; then
241244
subenum "${flags[@]}" "${extra[@]}" "${target[@]}" > "$out/changes.jsonl" || code=$?
242245
fi
243-
if [ ! -s "$out/run.json" ]; then echo "::error::subenum exited $code without a report"; exit "$code"; fi
246+
if [ ! -s "$out/run.json" ]; then
247+
echo "::error::subenum exited $code without a report"
248+
# -dry-run and -version exit 0 without writing a report; the step
249+
# must still fail rather than pass on the previous use's outputs (#407).
250+
[ "$code" -ne 0 ] || code=1
251+
exit "$code"
252+
fi
244253
245254
verdict=$(jq -r .verdict "$out/run.json")
246255
reason=$(jq -r .reason "$out/run.json")

0 commit comments

Comments
 (0)