refactor: try to condense the action in fewer steps
Some checks failed
/ check (treefmt) (push) Successful in 3s
/ report-size (push) Failing after 4s
/ report-download-check (push) Has been skipped

This should make it easier to debug/maintain.
This commit is contained in:
Jalil David Salamé Messina 2025-07-11 18:23:06 +02:00
parent 1b14f63169
commit dd7cf9e09e
Signed by: jalil
GPG key ID: F016B9E770737A0B
3 changed files with 79 additions and 51 deletions

View file

@ -67,42 +67,18 @@ outputs:
runs:
using: 'composite'
steps:
- name: Find PR (if it exists)
- name: Run
id: pr-number
if: inputs.comment-on-pr == 'true'
env:
BASE_BRANCH: ${{ inputs.base-branch }}
COMMENT: ${{ inputs.comment-on-pr }}
DO_COMPARISON: ${{ inputs.do-comparison }}
GENERATE_ARTIFACT: ${{ inputs.generate-artifact }}
JOB_NAME: ${{ inputs.job-name }}
run: |
. "$GITHUB_ACTION_PATH/scripts/utils.sh"
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}
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" \
-H 'Accept: application/json')
pr_number=$(echo "$prs" |
jq --arg head_ref "$head_ref" '.[] | select(.head.ref == $head_ref) | .number')
# This seems to create the file???
log "GITHUB_OUTPUT=$GITHUB_OUTPUT"
log "$(ls -l "$GITHUB_OUTPUT")"
# 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"
echo "pr-number=" >> "$GIHUB_OUTPUT"
exit 0
fi
log "Retrieved index: $pr_number"
log "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number"
echo "pr-number=$pr_number" >> "$GITHUB_OUTPUT"
"$GITHUB_ACTION_PATH/scripts/run.sh"
- name: Find previous comment (if present)
# We want to generate a comment, and we we able to fin the PR number
# We want to generate a comment and we we able to find the PR number
if: inputs.comment-on-pr == 'true' && steps.pr-number.outputs.pr-number != ''
id: find-comment
uses: https://github.com/peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
@ -110,35 +86,21 @@ runs:
issue-number: ${{ steps.pr-number.outputs.pr-number }}
direction: first
body-includes: "<!-- AUTOGENERATED by nix-flake-outputs-size action -->"
- name: Create report
if: inputs.comment-on-pr == 'true' || inputs.generate-artifact == 'true'
- name: Create report and comment on PR
# We want to generate a comment and we we able to find the PR number
if: inputs.comment-on-pr == 'true' && steps.pr-number.outputs.pr-number != ''
env:
PR_ID: ${{ steps.pr-number.outputs.pr-number }}
COMMENT: ${{ inputs.comment-on-pr }}
COMMENT_ID: ${{ steps.find-comment.outputs.comment-id }}
ARTIFACT_NAME: ${{ inputs.artifact-name }}
DO_COMPARISON: ${{ inputs.do-comparison }}
BASE_BRANCH: ${{ inputs.base-branch }}
JOB_NAME: ${{ inputs.job-name }}
run: |
. "$GITHUB_ACTION_PATH/scripts/utils.sh"
# Input validation
if [ "$DO_COMPARISON" = 'true' ] && [ -z "$JOB_NAME" ]; then
error 'job-name should be set if you want to generate a comparison report'
exit 1
fi
# Create Size Report
"$GITHUB_ACTION_PATH/scripts/create-report.sh" report.json
# Nothing else to do
if [ "$COMMENT" != 'true' ]; then exit 0; fi
# Try to do a comparison report
if [ "$DO_COMPARISON" = 'true' ]; then
if "$GITHUB_ACTION_PATH/scripts/retrieve-old-report.sh" && [ -f old-report.json ]; then
log "Reporting on sizes and comparing to sizes in $HEAD_BRANCH"
log "Reporting on sizes and comparing to sizes in $BASE_BRANCH"
"$GITHUB_ACTION_PATH/scripts/comment_on_pr.sh" report.json old-report.json
exit 0