fix(action): better logging

Be more clear about why it failed
This commit is contained in:
Jalil David Salamé Messina 2024-12-18 15:51:07 +01:00
parent 7cc7a6f6f4
commit 08d9598c26
Signed by: jalil
GPG key ID: F016B9E770737A0B
4 changed files with 62 additions and 24 deletions

View file

@ -66,6 +66,8 @@ runs:
HEAD_BRANCH: ${{ inputs.base-branch }}
JOB_NAME: ${{ inputs.job-name }}
run: |
. "${GITHUB_ACTION_PATH}/utils.sh"
# USAGE: base_report_url
base_report_url() {
curl -X 'GET' \
@ -77,27 +79,33 @@ runs:
--arg head_branch "$HEAD_BRANCH" \
'[.workflow_runs[] | select(.name == $name and .head_branch == $head_branch)] | first | .url'
}
# USAGE: has_report <RUN_URL>
# USAGE: has_report <REPORT_URL>
has_report() {
http_code=$(curl -X 'GET' -o /dev/null --silent -Iw '%{http_code}' \
-H "Authorization: token $GITHUB_TOKEN" \
"$1/artifacts/$ARTIFACT_NAME")
"$1")
log "Got code $http_code for $url"
test "$http_code" = '200'
}
# If we have a previous report compare against it
if [ "$JOB_NAME" ] && [ "$HEAD_BRANCH" ]; then
url=$(base_report_url)
echo "Found previous run at: $url"
if has_report "$url"; then
log "Found previous run at: $url"
report_url="$url/artifacts/$ARTIFACT_NAME"
if has_report "$report_url"; then
log 'Found previous report, downloading...'
curl -X 'GET' \
-H "Authorization: token $GITHUB_TOKEN" \
"$url/artifacts/$ARTIFACT_NAME" |
gunzip > old-report.json
echo 'Found previous report'
log "Reporting on sizes and comparing to sizes in $HEAD_BRANCH"
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json old-report.json
exit 0
else
log "Failed to find previous report, expected at: $report_url"
fi
fi
log 'Reporting on sizes'
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json