refactor!(action): detect when in private branches
This removes the need to use the private-repo-workaround input.
This commit is contained in:
parent
bff5365c60
commit
39f58ee538
5 changed files with 125 additions and 69 deletions
104
action.yml
104
action.yml
|
@ -5,7 +5,7 @@ description: |
|
|||
report.
|
||||
|
||||
You can post this report as a comment to the PR associated with the current
|
||||
branch and/or export the report as a markdown artifact.
|
||||
branch and/or export the report as a JSON artifact.
|
||||
|
||||
Requires `nix`, `jq`, `curl`, `sed`, `gunzip`, `tar` and `coreutils` to be in
|
||||
the runner's path.
|
||||
|
@ -19,75 +19,95 @@ description: |
|
|||
comment-on-pr: 'true'
|
||||
generate-artifact: 'false'
|
||||
artifact-name: 'size-report.md'
|
||||
base-branch: ${{ github.base_ref }} # set to e.g. main if not triggered by a pull_request
|
||||
job-name: '' # set to the name of this job if you want to enable comparisons
|
||||
# If you want to enable comparisons set this to true
|
||||
do-comparison: 'false'
|
||||
job-name: '' # required if do-comparison is true
|
||||
# This is the branch that will be compared against
|
||||
base-branch: ${{ github.base_ref }} # or default branch if missing
|
||||
```
|
||||
inputs:
|
||||
comment-on-pr:
|
||||
description: Comment the report on the PR associated with the current branch.
|
||||
description: |
|
||||
Comment the report on the PR associated with the current branch.
|
||||
|
||||
This is a no-op in case no PR is associated with the current branch.
|
||||
default: 'true'
|
||||
# Generate workflow artifact
|
||||
generate-artifact:
|
||||
description: Export the generated markdown document as an artifact.
|
||||
description: Export the generated markdown document as a workflow artifact.
|
||||
default: 'false'
|
||||
artifact-name:
|
||||
description: The name of the generated artifact.
|
||||
default: report.json
|
||||
base-branch:
|
||||
# Comparison Report (comment only)
|
||||
do-comparison:
|
||||
description: |
|
||||
The name of the base branch, defaults to github.base_ref which is only
|
||||
available in pull_request triggered workflows, for other workflows
|
||||
specify it manually.
|
||||
When commenting on the PR compare the results with those in the base branch.
|
||||
|
||||
It will try to download the generated artifact from this branch so make
|
||||
sure `generate-artifacte: true` when the workflow is running on that
|
||||
branch.
|
||||
default: ${{ github.base_ref }}
|
||||
This is a no-op when `comment-on-pr: false`.
|
||||
|
||||
It requires `job-name` to be set.
|
||||
default: 'false'
|
||||
job-name:
|
||||
description: |
|
||||
The name of the job running this action. If not set, no comparisons can
|
||||
be made.
|
||||
default: ''
|
||||
private-repo-workaround:
|
||||
base-branch:
|
||||
description: |
|
||||
Forgejo doesn't support downloading artifacts through the API [see
|
||||
codeberg.org/forgejo/forgejo#6315](https://codeberg.org/forgejo/forgejo/issues/6315).
|
||||
The name of the base branch, defaults to `github.base_ref` if present
|
||||
(when triggered by a `pull_request`). Otherwise defaults to the repo's
|
||||
default branch. Set in case you want to override this behaviour.
|
||||
|
||||
As a workaround, checkout the base branch and regenerate the report.
|
||||
|
||||
This is very innefficient T-T and slow.
|
||||
default: 'false'
|
||||
It will try to download the generated artifact from this branch so make
|
||||
sure `generate-artifacte: true` when the workflow is running on that
|
||||
branch.
|
||||
default: ${{ github.base_ref }}
|
||||
outputs:
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Create report
|
||||
if: inputs.comment-on-pr == 'true' || inputs.generate-artifact == 'true'
|
||||
env:
|
||||
COMMENT: ${{ inputs.comment-on-pr == }}
|
||||
ARTIFACT_NAME: ${{ inputs.artifact-name }}
|
||||
DO_COMPARISON: ${{ inputs.do-comparison }}
|
||||
BASE_BRANCH: ${{ inputs.base-branch }}
|
||||
JOB_NAME: ${{ inputs.job-name }}
|
||||
run: |
|
||||
. "$GITHUB_ACTION_PATH/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/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/retrieve-old-report.sh" && [ -f old-report.json ]; then
|
||||
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
|
||||
else
|
||||
error 'Failed to do comparison, fallback to posting the report without them'
|
||||
fi
|
||||
fi
|
||||
|
||||
# Just report values
|
||||
log 'Reporting on sizes'
|
||||
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json
|
||||
- name: Upload Artifact
|
||||
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
|
||||
if: inputs.generate-artifact == 'true'
|
||||
with:
|
||||
path: report.json
|
||||
name: ${{ inputs.artifact-name }}
|
||||
- name: Comment Report
|
||||
if: inputs.comment-on-pr == 'true'
|
||||
env:
|
||||
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"
|
||||
|
||||
if "$GITHUB_ACTION_PATH/retrieve-old-report.sh" && [ -f old-report.json ]; then
|
||||
log "Reporting on sizes and comparing to sizes in $HEAD_BRANCH"
|
||||
|
||||
group 'Old report data'
|
||||
cat old-report.json
|
||||
endgroup
|
||||
|
||||
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json old-report.json
|
||||
else
|
||||
log 'Reporting on sizes'
|
||||
"$GITHUB_ACTION_PATH/comment_on_pr.sh" report.json
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue