refactor: try to condense the action in fewer steps
This should make it easier to debug/maintain.
This commit is contained in:
parent
1b14f63169
commit
ca72db2a3b
3 changed files with 79 additions and 51 deletions
61
scripts/run.sh
Executable file
61
scripts/run.sh
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/bin/sh
|
||||
|
||||
. "$GITHUB_ACTION_PATH/scripts/utils.sh"
|
||||
|
||||
# Input validation
|
||||
if [ "$COMMENT" != "true" ] && [ "$GENERATE_ARTIFACT" != "true" ]; then
|
||||
panic 'Neither comment-on-pr nor generate-artifact is set
|
||||
note: this looks like an error; if it isn'"'"'t disable this action with "step.if"'
|
||||
fi
|
||||
|
||||
if [ "$DO_COMPARISON" = 'true' ] && [ -z "$JOB_NAME" ]; then
|
||||
panic 'Requested a comparison report but job-name wasn'"'"'t set'
|
||||
fi
|
||||
|
||||
# Create Size Report (will be uploaded by the upload-artifact action)
|
||||
"$GITHUB_ACTION_PATH/scripts/create-report.sh" report.json
|
||||
|
||||
# Nothing else to do
|
||||
if [ "$COMMENT" != "true" ]; then exit 0; fi
|
||||
|
||||
# Find the PR for this commit so we can post a comment on it
|
||||
pr_number=
|
||||
case "$GITHUB_EVENT_NAME" in
|
||||
"pull_request")
|
||||
pr_number=$(jq .number "$GITHUB_EVENT_PATH")
|
||||
log "Triggered by a pull request with index: $pr_number"
|
||||
;;
|
||||
"push")
|
||||
log "Triggered by a push to $GITHUB_REF_NAME autodetecting PR number"
|
||||
|
||||
log "Get PR number for $GITHUB_REF_NAME"
|
||||
prs=$(curl -X 'GET' \
|
||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls?state=open&sort=recentupdate" \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H 'Accept: application/json')
|
||||
|
||||
log "Found these open PRs: $(echo "$prs" | jq '[.[] | .number]')"
|
||||
|
||||
pr_number=$(echo "$prs" |
|
||||
jq --arg ref "$GITHUB_REF_NAME" '.[] | select(.head.ref == $ref) | .number')
|
||||
|
||||
# Protect against running before a PR is made or if it is triggered on the main branch
|
||||
if [ -z "$pr_number" ]; then
|
||||
warn "No PR created for this commit"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
log "The PR we found for $GITHUB_REF_NAME is $pr_number"
|
||||
;;
|
||||
*)
|
||||
panic "Unexpected event $GITHUB_EVENT_NAME for commenting on a PR, expected push or pull_request"
|
||||
;;
|
||||
esac
|
||||
|
||||
log "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number"
|
||||
|
||||
# This seems to create the file???
|
||||
log "GITHUB_OUTPUT=$GITHUB_OUTPUT"
|
||||
log "$(ls -l "$GITHUB_OUTPUT")"
|
||||
|
||||
echo "pr-number=$pr_number" >>"$GITHUB_OUTPUT"
|
Loading…
Add table
Add a link
Reference in a new issue