feat: use download-artifact instead of manually downloading it
This should hopefully work on private repos too!
This commit is contained in:
parent
b7e76df813
commit
bf9d3cb078
3 changed files with 50 additions and 80 deletions
47
action.yml
47
action.yml
|
@ -39,6 +39,8 @@ inputs:
|
|||
artifact-name:
|
||||
description: The name of the generated artifact.
|
||||
default: report.json
|
||||
github-token:
|
||||
description: A github token with read permissions for this repository, required if do-comparison is 'true'
|
||||
# Comparison Report (comment only)
|
||||
do-comparison:
|
||||
description: |
|
||||
|
@ -110,6 +112,46 @@ runs:
|
|||
issue-number: ${{ steps.pr-number.outputs.pr-number }}
|
||||
direction: first
|
||||
body-includes: "<!-- AUTOGENERATED by nix-flake-outputs-size action -->"
|
||||
- name: Find previous run on base-branch
|
||||
# Only run when doing comparisons
|
||||
if: inputs.do-comparison == 'true'
|
||||
id: previous-report
|
||||
continue-on-error: true
|
||||
env:
|
||||
BASE_BRANCH: ${{ inputs.base-branch }}
|
||||
JOB_NAME: ${{ inputs.job-name }}
|
||||
ARTIFACT_NAME: ${{ inputs.artifact-name }}
|
||||
run: |
|
||||
. "${GITHUB_ACTION_PATH}/utils.sh"
|
||||
|
||||
# Determine the default branch of this repo
|
||||
default_branch() {
|
||||
curl -X GET \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H 'Accept: application/json' \
|
||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY" |
|
||||
jq --raw-output '.default_branch'
|
||||
}
|
||||
|
||||
run_id=$(curl -X 'GET' \
|
||||
"$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/tasks" \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H 'Accept: application/json' |
|
||||
jq --raw-output \
|
||||
--arg name "$JOB_NAME" \
|
||||
--arg head_branch "${BASE_BRANCH:-$(default_branch)}" \
|
||||
'[.workflow_runs[] | select(.name == $name and .head_branch == $head_branch)] | first | .run_number')
|
||||
|
||||
echo "run-id=${{ github.run_id }}" >> "$GITHUB_OUTPUT"
|
||||
log Would try to download "$ARTIFACT_NAME" from "$run_id"
|
||||
- name: Download previous report
|
||||
uses: https://git.salame.cl/actions/download-artifact@d8d0a99033603453ad2255e58720b460a0555e1e # v4
|
||||
# Ensure the previous step succeeded
|
||||
if: steps.previous-report.outcome == 'success'
|
||||
with:
|
||||
name: ${{ inputs.artifact-name }}
|
||||
github-token: ${{ inputs.github-token }}
|
||||
run-id: ${{ steps.previous-report.outputs.run-id }}
|
||||
- name: Create report
|
||||
if: inputs.comment-on-pr == 'true' || inputs.generate-artifact == 'true'
|
||||
env:
|
||||
|
@ -129,6 +171,9 @@ runs:
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# move old report so it doesn't clash with the new report
|
||||
[ -f report.json ] && mv report.json old-report.json
|
||||
|
||||
# Create Size Report
|
||||
"$GITHUB_ACTION_PATH/create-report.sh" > report.json
|
||||
|
||||
|
@ -137,7 +182,7 @@ runs:
|
|||
|
||||
# Try to do a comparison report
|
||||
if [ "$DO_COMPARISON" = 'true' ]; then
|
||||
if "$GITHUB_ACTION_PATH/retrieve-old-report.sh" && [ -f old-report.json ]; then
|
||||
if [ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue