Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Download latest bundle analysis artifact from base branch #2994

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/nextjs-bundle-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ jobs:
path: .next/analyze/__bundle_analysis.json

- name: Download base branch bundle stats
uses: dawidd6/action-download-artifact@v2
if: success() && github.event.number
with:
workflow: nextjs_bundle_analysis.yml
branch: ${{ github.event.pull_request.base.ref }}
path: .next/analyze/base
run: bash ./scripts/github/download_bundle_analyser_artifact.sh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}


- name: Compare with base branch bundle
if: success() && github.event.number
Expand Down
31 changes: 31 additions & 0 deletions scripts/github/download_bundle_analyser_artifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# We use this instead of action-download-artifact. See discussion on
# https://github.com/dawidd6/action-download-artifact/issues/240
set -xe
ORG="safe-global"
REPO="safe-wallet-web"
WORKFLOW="nextjs-bundle-analysis.yml"
ARTIFACT_NAME="bundle"
DESTINATION=".next/analyze/base"
BASE_BRANCH="dev"

ARTIFACTS_URL=$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${ORG}/${REPO}/actions/workflows/${WORKFLOW}/runs?event=push&branch=${BASE_BRANCH}&status=success&per_page=1" \
--jq ".workflow_runs[0].artifacts_url"
)

DOWNLOAD_URL=$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"${ARTIFACTS_URL}" \
--jq '.artifacts[] | select(.name == "'"${ARTIFACT_NAME}"'") | .archive_download_url'
)

set +x
curl -H "Accept: application/vnd.github+json" -H "Authorization: token $GH_TOKEN" -L -o "${DESTINATION}.zip" "$DOWNLOAD_URL"
set -x
unzip "${DESTINATION}.zip" -d "${DESTINATION}" && mkdir -p "${DESTINATION}/bundle" && mv "${DESTINATION}/__bundle_analysis.json" "${DESTINATION}/bundle/"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to unzip the contents of ${DESTINATION}.zip into the directory ${DESTINATION}/bundle. I tried using wildcards but without success so I hard-code the filename here.

rm "${DESTINATION}.zip"
Loading