feat(action): add workaround for private repos

This is a slow, but foolproof way to ensure a comparison report is
generated.
This commit is contained in:
Jalil David Salamé Messina 2024-12-18 21:15:52 +01:00
parent c3362d4650
commit 1db9349c00
Signed by: jalil
GPG key ID: F016B9E770737A0B

View file

@ -46,6 +46,15 @@ inputs:
The name of the job running this action. If not set, no comparisons can
be made.
default: ''
private-repo-workaround:
description: |
Forgejo doesn't support downloading artifacts through the API [see
codeberg.org/forgejo/forgejo#6315](https://codeberg.org/forgejo/forgejo/issues/6315).
As a workaround, checkout the base branch and regenerate the report.
This is very innefficient T-T and slow.
default: 'false'
outputs:
runs:
using: 'composite'
@ -65,6 +74,7 @@ runs:
ARTIFACT_NAME: ${{ inputs.artifact-name }}
HEAD_BRANCH: ${{ inputs.base-branch }}
JOB_NAME: ${{ inputs.job-name }}
PRIVATE_REPO: ${{ inputs.private-repo-workaround }}
run: |
. "${GITHUB_ACTION_PATH}/utils.sh"
@ -87,8 +97,17 @@ runs:
test "$http_code" = '200'
}
if [ "$PRIVATE_REPO" = 'true' ]; then
log "In a private repo, switching to $HEAD_BRANCH to build the old report"
git switch "$HEAD_BRANCH"
"$GITHUB_ACTION_PATH/create-report.sh" > old-report.json
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
# If we have a previous report compare against it
if [ "$JOB_NAME" ] && [ "$HEAD_BRANCH" ]; then
elif [ "$JOB_NAME" ] && [ "$HEAD_BRANCH" ]; then
url=$(base_report_url)
log "Found previous run at: $url"
report_url="$url/artifacts/$ARTIFACT_NAME"