Skip to content

Commit c415c1a

Browse files
felickzCopilot
andauthored
fix(publish): keep newest result artifact when a publish job is restarted (#244)
When a publish job is cancelled and restarted, the run ends up with two artifacts with the same name (for example publish-result-csharp-src). The summary job downloaded them with merge-multiple, which extracts every match into one directory in no guaranteed order, so the stale "failed" fragment overwrote the newer "published" one. The release notes then showed "publish failed" for packs that had published (seen on v0.8.3 for the C# and Go query packs). Replace the download step with download-latest-publish-results.sh, which lists the run's artifacts via the API and downloads only the newest non-expired one per name. The summary job needs actions: read for that listing. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 5930377 commit c415c1a

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
# Downloads the publish-result-* artifacts of a publish.yml run into a flat
3+
# directory, keeping only the NEWEST artifact per artifact name.
4+
#
5+
# Usage: download-latest-publish-results.sh <run-id> <dest-dir>
6+
#
7+
# Why not actions/download-artifact with merge-multiple? Re-running or
8+
# restarting a publish job (e.g. after cancelling it) uploads a second
9+
# artifact with the same name into the same run, and the earlier attempt's
10+
# artifact is kept. merge-multiple extracts every match into one directory in
11+
# no guaranteed order, so a stale "failed" fragment can overwrite the newer
12+
# "published" one, and the summary then reports a published pack as failed.
13+
#
14+
# Requires: gh (GH_TOKEN with actions:read), jq, unzip. GITHUB_REPOSITORY
15+
# defaults to this repo so the script also works locally.
16+
set -euo pipefail
17+
18+
RUN_ID="${1:?usage: download-latest-publish-results.sh <run-id> <dest-dir>}"
19+
DEST="${2:?usage: download-latest-publish-results.sh <run-id> <dest-dir>}"
20+
REPO="${GITHUB_REPOSITORY:-GitHubSecurityLab/CodeQL-Community-Packs}"
21+
22+
mkdir -p "$DEST"
23+
WORK=$(mktemp -d)
24+
trap 'rm -rf "$WORK"' EXIT
25+
26+
# One "<id> <name>" line per artifact name: the newest non-expired one.
27+
gh api --paginate "repos/${REPO}/actions/runs/${RUN_ID}/artifacts?per_page=100" \
28+
--jq '.artifacts[] | select((.expired | not) and (.name | startswith("publish-result-"))) | [.created_at, .id, .name] | @tsv' \
29+
| sort -t$'\t' -k3,3 -k1,1r \
30+
| awk -F'\t' '!seen[$3]++ { print $2, $3 }' > "$WORK/latest.txt"
31+
32+
if [ ! -s "$WORK/latest.txt" ]; then
33+
echo "No publish-result-* artifacts found for run ${RUN_ID}."
34+
exit 0
35+
fi
36+
37+
while read -r ID NAME; do
38+
echo "Downloading ${NAME} (artifact ${ID})"
39+
gh api "repos/${REPO}/actions/artifacts/${ID}/zip" > "$WORK/${ID}.zip"
40+
unzip -o -q "$WORK/${ID}.zip" -d "$DEST"
41+
done < "$WORK/latest.txt"

‎.github/workflows/publish.yml‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,19 @@ jobs:
387387

388388
permissions:
389389
contents: write
390+
actions: read
390391

391392
steps:
392393
- uses: actions/checkout@v7
393394

395+
# Not actions/download-artifact with merge-multiple: a re-run or restarted publish job
396+
# leaves a second same-named artifact in the run, and merge-multiple can let the stale
397+
# (e.g. cancelled/failed) one overwrite the newer result. This keeps the newest per name.
394398
- name: Download publish results
395-
uses: actions/download-artifact@v8
396399
continue-on-error: true
397-
with:
398-
pattern: publish-result-*
399-
path: publish-results
400-
merge-multiple: true
400+
env:
401+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
402+
run: .github/scripts/download-latest-publish-results.sh "${{ github.run_id }}" publish-results
401403

402404
- name: Build summary table
403405
run: |

0 commit comments

Comments
 (0)