From 16b9bded21322ed428644131a96b3eb3594d3e71 Mon Sep 17 00:00:00 2001 From: Usame Algan Date: Mon, 11 Dec 2023 12:59:01 +0100 Subject: [PATCH] chore: Download latest bundle analysis artifact from base branch --- .github/workflows/nextjs-bundle-analysis.yml | 9 +++--- .../download_bundle_analyser_artifact.sh | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 scripts/github/download_bundle_analyser_artifact.sh diff --git a/.github/workflows/nextjs-bundle-analysis.yml b/.github/workflows/nextjs-bundle-analysis.yml index 1840f8d380..3cfa1f8573 100644 --- a/.github/workflows/nextjs-bundle-analysis.yml +++ b/.github/workflows/nextjs-bundle-analysis.yml @@ -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 diff --git a/scripts/github/download_bundle_analyser_artifact.sh b/scripts/github/download_bundle_analyser_artifact.sh new file mode 100644 index 0000000000..e5c0fa122f --- /dev/null +++ b/scripts/github/download_bundle_analyser_artifact.sh @@ -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/" +rm "${DESTINATION}.zip"