Skip to content

Commit bc24d0b

Browse files
committed
gh-run-download: Fix comment retrieval
- refactor run download to a script - replace `gh run download` because the endpoint is broken https://api.github.com/repos/cli/cli/issues/12437
1 parent 1789d9c commit bc24d0b

2 files changed

Lines changed: 64 additions & 20 deletions

File tree

‎action.yml‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -530,28 +530,27 @@ runs:
530530
suffix: ${{ inputs.report_title_suffix }}
531531
run: |
532532
: Retrieve comment
533-
if ! gh run download -R "$GITHUB_REPOSITORY" "$GITHUB_RUN_ID" -n "check-spelling-comment-$suffix" 2>/dev/null; then
534-
if ! gh run download -R "$GITHUB_REPOSITORY" "$GITHUB_RUN_ID" -n check-spelling-comment 2>/dev/null; then
535-
gh_api_out=$(mktemp)
536-
gh_api_err=$(mktemp)
537-
if ! gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts?per_page=1" > "$gh_api_out" 2> "$gh_api_err"; then
538-
if grep -q 'HTTP 403' "$gh_api_err"; then
539-
act-summary
540-
(
541-
echo '# Workflow is missing permissions'
542-
echo 'Please add `actions: read` to enable check-spelling to retrieve the artifact it needs to post a comment. [more info](https://docs.check-spelling.dev/Workflow-Permissions#actions-read)'
543-
echo
544-
echo '#### Technical details'
545-
echo '```'
546-
cat "$gh_api_err"
547-
cat "$gh_api_out"
548-
echo
549-
echo '```'
550-
) >> "$GITHUB_STEP_SUMMARY"
551-
fi
533+
"$spellchecker/gh-run-download.sh"
534+
if [ ! -s artifact.zip ]; then
535+
gh_api_out=$(mktemp)
536+
gh_api_err=$(mktemp)
537+
if ! gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID/artifacts?per_page=1" > "$gh_api_out" 2> "$gh_api_err"; then
538+
if grep -q 'HTTP 403' "$gh_api_err"; then
539+
act-summary
540+
(
541+
echo '# Workflow is missing permissions'
542+
echo 'Please add `actions: read` to enable check-spelling to retrieve the artifact it needs to post a comment. [more info](https://docs.check-spelling.dev/Workflow-Permissions#actions-read)'
543+
echo
544+
echo '#### Technical details'
545+
echo '```'
546+
cat "$gh_api_err"
547+
cat "$gh_api_out"
548+
echo
549+
echo '```'
550+
) >> "$GITHUB_STEP_SUMMARY"
552551
fi
553-
echo "no-comment=1" >> "$GITHUB_OUTPUT"
554552
fi
553+
echo "no-comment=1" >> "$GITHUB_OUTPUT"
555554
fi
556555
- name: check-spelling
557556
id: spelling

‎gh-run-download.sh‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
. "$spellchecker/call-curl.sh"
2+
3+
if [ -n "$GH_TOKEN" ]; then
4+
export AUTHORIZATION_HEADER="Authorization: token $GH_TOKEN"
5+
fi
6+
7+
get_comment_artifact_flavor() {
8+
keep_headers=1 call_curl "$GITHUB_API_URL/repositories/$GITHUB_REPOSITORY_ID/actions/runs/$GITHUB_RUN_ID/artifacts?name=$1&per_page=1" > "$comment_artifact_json"
9+
total_count=$(jq '.total_count // empty' "$comment_artifact_json")
10+
if [ -n "$total_count" ] && [ $total_count -gt 1 ]; then
11+
link=$(get_link last "$response_headers")
12+
call_curl "$link" > "$comment_artifact_json"
13+
fi
14+
}
15+
16+
get_artifact_url() {
17+
jq -r '.artifacts[0].archive_download_url // empty' "$comment_artifact_json"
18+
}
19+
20+
get_comment_artifact_url() {
21+
comment_artifact_json=$(mktemp)
22+
comment=check-spelling-comment
23+
if [ -n "$suffix" ]; then
24+
get_comment_artifact_flavor "$comment-$suffix"
25+
artifact_url=$(get_artifact_url)
26+
if [ -n "$artifact_url" ]; then
27+
return
28+
fi
29+
fi
30+
get_comment_artifact_flavor "$comment"
31+
artifact_url=$(get_artifact_url)
32+
}
33+
34+
get_comment_artifact() {
35+
get_comment_artifact_url
36+
if [ -n "$artifact_url" ]; then
37+
artifact_zip=$(mktemp)
38+
call_curl "$artifact_url" > "$artifact_zip"
39+
if [ $curl_exit_code = 0 ]; then
40+
unzip -q "$artifact_zip" && rm "$artifact_zip"
41+
fi
42+
fi
43+
}
44+
45+
get_comment_artifact

0 commit comments

Comments
 (0)