fix(action): better logging
Be more clear about why it failed
This commit is contained in:
parent
7cc7a6f6f4
commit
08d9598c26
4 changed files with 62 additions and 24 deletions
|
@ -2,6 +2,11 @@
|
|||
|
||||
set -eu
|
||||
|
||||
util_path="${GITHUB_ACTION_PATH-.}/utils.sh"
|
||||
|
||||
# shellcheck source=utils.sh
|
||||
. "${util_path}"
|
||||
|
||||
# USAGE: json_to_md_rows <FIELD> [JSON_FILE]
|
||||
#
|
||||
# JSON_FILE can be piped from stdin
|
||||
|
@ -96,11 +101,11 @@ if [ "${CI-false}" != 'true' ]; then
|
|||
exit 0
|
||||
fi
|
||||
|
||||
echo 'Determine head_ref'
|
||||
log 'Determine head_ref'
|
||||
# For push & tag events it'll bet GITHUB_REF_NAME, for pull_request events it'll be GITHUB_HEAD_REF
|
||||
head_ref=${GITHUB_REF_NAME-$GITHUB_HEAD_REF}
|
||||
|
||||
echo "Get PR number for $head_ref"
|
||||
log "Get PR number for $head_ref"
|
||||
prs=$(curl -X 'GET' \
|
||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls?state=open&sort=recentupdate" \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
|
@ -111,22 +116,25 @@ pr_number=$(echo "$prs" |
|
|||
|
||||
# Protect against running before a PR is made or if it is triggered on the main branch
|
||||
if [ -z "$pr_number" ]; then
|
||||
echo "No PR created for this commit"
|
||||
log "No PR created for this commit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Retrieved index: $pr_number" >&2
|
||||
echo "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number" >&2
|
||||
log "Retrieved index: $pr_number"
|
||||
log "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number"
|
||||
|
||||
echo 'Generating comment body' >&2
|
||||
log 'Generating comment body'
|
||||
comment=$(markdown_from_report "$@")
|
||||
|
||||
echo 'Posting comment:' >&2
|
||||
echo "$comment" >&2
|
||||
group 'Comment Data:'
|
||||
log "$comment"
|
||||
endgroup
|
||||
|
||||
echo 'Request data:' >&2
|
||||
data=$(echo '{}' | jq --arg comment "$comment" '.body=$comment')
|
||||
echo "$data" >&2
|
||||
group 'Request data:'
|
||||
log "$data"
|
||||
endgroup
|
||||
|
||||
curl -o - -X 'POST' \
|
||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments" \
|
||||
-H 'accept: application/json' \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue