Skip to content

Commit 1216723

Browse files
authored
Backport: Improve utility script not to fail with empty response (#888) (#893)
There is a case that the response of API doesn't match expected pull request. As a result, it must follow the next one or more to search. Signed-off-by: Kentaro Hayashi <hayashi@clear-code.com>
1 parent 5e39445 commit 1216723

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

fluent-package/manage-fluent-repositories.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ case $COMMAND in
5050
# Allow copying the URL from browser's URL bar.
5151
PULL_REQUEST_URL=$2
5252
PULL_NUMBER=${PULL_REQUEST_URL##*/}
53-
read -rsp "Please enter your GitHub personal access token: " GITHUB_ACCESS_TOKEN
54-
echo
53+
if [ -z "$GITHUB_ACCESS_TOKEN" ]; then
54+
read -rsp "Please enter your GitHub personal access token: " GITHUB_ACCESS_TOKEN
55+
echo
56+
fi
5557
;;
5658
*)
5759
FLUENT_RELEASE_PROFILE=$2
@@ -196,12 +198,22 @@ EOF
196198
head_branch=$(echo $response | cut -d' ' -f1)
197199
head_sha=$(echo $response | cut -d' ' -f2)
198200
rm -f dl.list
199-
curl --silent --location \
200-
-H "Accept: application/vnd.github+json" \
201-
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
202-
-H "X-GitHub-Api-Version: 2022-11-28" \
203-
"https://api.github.com/repos/fluent/fluent-package-builder/actions/artifacts?per_page=100&page=$d" | \
204-
jq --raw-output '.artifacts[] | select(.workflow_run.head_branch == "'$head_branch'" and .workflow_run.head_sha == "'$head_sha'") | .name + " " + (.size_in_bytes|tostring) + " " + .archive_download_url' > dl.list
201+
for d in `seq 1 5`; do
202+
curl --silent --location \
203+
-H "Accept: application/vnd.github+json" \
204+
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
205+
-H "X-GitHub-Api-Version: 2022-11-28" \
206+
"https://api.github.com/repos/fluent/fluent-package-builder/actions/artifacts?per_page=100&page=$d" | \
207+
jq --raw-output '.artifacts[] | select(.workflow_run.head_branch == "'$head_branch'" and .workflow_run.head_sha == "'$head_sha'") | .name + " " + (.size_in_bytes|tostring) + " " + .archive_download_url' > dl.list
208+
filesize=$(stat -c "%s" dl.list)
209+
if [ $filesize -eq 0 ]; then
210+
echo "Failed to fetch artifacts list"
211+
rm -f dl.list
212+
continue
213+
else
214+
break
215+
fi
216+
done
205217
while read line
206218
do
207219
package=$(echo $line | cut -d' ' -f1)

0 commit comments

Comments
 (0)