feat!(report): generate JSON instead of markdown

This allows us to analyze the report more easily. There is experimental
support for comparing against a base report, but we don't expose that
functionality to the action.
This commit is contained in:
Jalil David Salamé Messina 2024-12-17 23:15:39 +01:00
parent 3c231dbfef
commit 46291fc850
Signed by: jalil
GPG key ID: F016B9E770737A0B
4 changed files with 171 additions and 76 deletions

View file

@ -28,59 +28,21 @@ inputs:
default: 'false'
artifact-name:
description: The name of the generated artifact.
default: 'size-report.md'
default: report.json
outputs:
runs:
using: 'composite'
steps:
- name: Create report
run: |
"$GITHUB_ACTION_PATH/create-report.sh"
"$GITHUB_ACTION_PATH/create-report.sh" > report.json
- name: Upload Artifact
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
if: inputs.generate-artifact == 'true'
with:
path: size-report.md
path: report.json
name: ${{ inputs.artifact-name }}
- name: Comment Report
if: inputs.comment-on-pr == 'true'
run: |
set -eu
echo '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"
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')
# 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"
exit 0
fi
echo "Retrieved index: $pr_number" >&2
echo "Expected PR URL: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pulls/$pr_number" >&2
echo 'Generating comment body' >&2
comment=$(cat size-report.md)
echo 'Posting comment:' >&2
echo "$comment" >&2
echo 'Request data:' >&2
data=$(echo '{}' | jq --arg comment "$comment" '.body=$comment')
echo "$data" >&2
curl -o - -X 'POST' \
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pr_number/comments" \
-H 'accept: application/json' \
-H "Authorization: token $GITHUB_TOKEN" \
-H 'Content-Type: application/json' \
-d "$data"
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json