From 38e8d3a1657760ddc7dbf6b8db2303e4327f84db Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Mon, 18 Nov 2024 20:03:54 +0000 Subject: [PATCH 1/2] Publish GitHub Pages previews on every PR --- .../actions/compile-gh-pages/action.yml | 32 ++++++ .github/workflows/preview-gh-pages.yml | 99 +++++++++++++++++++ .github/workflows/publish-gh-pages.yml | 44 ++------- 3 files changed, 140 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/actions/compile-gh-pages/action.yml create mode 100644 .github/workflows/preview-gh-pages.yml diff --git a/.github/workflows/actions/compile-gh-pages/action.yml b/.github/workflows/actions/compile-gh-pages/action.yml new file mode 100644 index 000000000000..56331cfa3475 --- /dev/null +++ b/.github/workflows/actions/compile-gh-pages/action.yml @@ -0,0 +1,32 @@ +name: Compile GitHub Pages +description: Compiles content for GitHub Pages and uploads it to the artifact cache + +inputs: + pr-number: + type: number + repository: + default: 'solana-web3.js' + type: string + +runs: + using: composite + steps: + - name: Compile + shell: bash + run: pnpm turbo run compile:typedefs compile:ghpages --concurrency=${TURBO_CONCURRENCY:-1} + env: + REACT_EXAMPLE_APP_BASE_PATH: /${{ inputs.repository }}${{ inputs.pr-number && format('/{0}', inputs.pr-number) || '' }}/example/ + + - name: Assemble Deploy Directory + shell: bash + run: | + mkdir -p .ghpages-deploy + mv ./examples/react-app/dist/ .ghpages-deploy/example/ + mv ./docs/* .ghpages-deploy/ + + - uses: actions/upload-artifact@v4 + with: + include-hidden-files: true + name: ghpages-deploy-artifacts + path: .ghpages-deploy + retention-days: 1 diff --git a/.github/workflows/preview-gh-pages.yml b/.github/workflows/preview-gh-pages.yml new file mode 100644 index 000000000000..c3288dd0180c --- /dev/null +++ b/.github/workflows/preview-gh-pages.yml @@ -0,0 +1,99 @@ +name: Preview GitHub Pages + +on: + pull_request: + types: [synchronize, opened, reopened] + +env: + # Among other things, opts out of Turborepo telemetry + # See https://consoledonottrack.com/ + DO_NOT_TRACK: '1' + # Some tasks slow down considerably on GitHub Actions runners when concurrency is high + TURBO_CONCURRENCY: 1 + # Enables Turborepo Remote Caching. + TURBO_REMOTE_CACHE_SIGNATURE_KEY: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }} + TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }} + TURBO_TEAM: ${{ secrets.TURBO_TEAM }} + +jobs: + compile-gh-pages-legacy: + runs-on: ubuntu-latest + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: maintenance/v1.x + + - name: Install Dependencies + uses: ./.github/workflows/actions/install-dependencies + + - name: Compile and Upload Artifacts + uses: ./.github/workflows/actions/compile-gh-pages + + compile-gh-pages: + runs-on: ubuntu-latest + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Dependencies + uses: ./.github/workflows/actions/install-dependencies + + - name: Compile and Upload Artifacts + uses: ./.github/workflows/actions/compile-gh-pages + with: + pr-number: ${{ github.event.pull_request.number }} + repository: solana-web3.js-pr-preview + + preview: + runs-on: ubuntu-latest + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' + needs: [compile-gh-pages, compile-gh-pages-legacy] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Dependencies + uses: ./.github/workflows/actions/install-dependencies + + - uses: actions/download-artifact@v4 + with: + path: .ghpages-deploy + pattern: ghpages-deploy-artifacts* + merge-multiple: true + + - name: Deploy to Preview Github Pages + uses: peaceiris/actions-gh-pages@v4 + with: + destination_dir: ${{ format('{0}/', github.event.pull_request.number) }} + external_repository: solana-labs/solana-web3.js-pr-preview + personal_token: ${{ secrets.PR_PREVIEW_REPO_CONTENTS_TOKEN }} + publish_dir: .ghpages-deploy + + - name: Find Existing Preview Link Comment + uses: peter-evans/find-comment@v3 + id: find-comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: + + - name: Create Preview Link Comment + uses: actions/github-script@v7 + if: steps.find-comment.outputs.comment-id == '' + with: + script: > + const prNumber = context.issue.number; + github.rest.issues.createComment({ + issue_number: prNumber, + owner: context.repo.owner, + repo: context.repo.repo, + body: [ + '', + 'A preview of the GitHub Pages site based on this PR is now available here:', + '', + `solana-labs.github.io/solana-web3.js-pr-preview/${prNumber}/`, + ].join('\n'), + }); diff --git a/.github/workflows/publish-gh-pages.yml b/.github/workflows/publish-gh-pages.yml index d12c6a6417bc..0be21b6f282e 100644 --- a/.github/workflows/publish-gh-pages.yml +++ b/.github/workflows/publish-gh-pages.yml @@ -22,7 +22,7 @@ env: TURBO_TEAM: ${{ secrets.TURBO_TEAM }} jobs: - compile-v1-docs: + compile-gh-pages-legacy: runs-on: ubuntu-latest steps: - name: Checkout @@ -33,22 +33,11 @@ jobs: - name: Install Dependencies uses: ./.github/workflows/actions/install-dependencies - - name: Compile docs - run: pnpm compile:docs + - name: Compile and Upload Artifacts + # Be aware that this is the version that lives on the `maintenance/v1.x` branch. + uses: ./.github/workflows/actions/compile-gh-pages - - name: Assemble Deploy Directory - run: | - mkdir -p .ghpages-deploy/v1.x - mv ./doc/* .ghpages-deploy/v1.x - - - uses: actions/upload-artifact@v4 - with: - include-hidden-files: true - name: ghpages-deploy-artifacts-v1-docs - path: .ghpages-deploy - retention-days: 1 - - compile-github-pages: + compile-gh-pages: runs-on: ubuntu-latest steps: - name: Checkout @@ -57,27 +46,12 @@ jobs: - name: Install Dependencies uses: ./.github/workflows/actions/install-dependencies - - name: Compile - run: pnpm turbo run compile:typedefs compile:ghpages --concurrency=${TURBO_CONCURRENCY:-1} - env: - REACT_EXAMPLE_APP_BASE_PATH: /solana-web3.js/example/ - - - name: Assemble Deploy Directory - run: | - mkdir -p .ghpages-deploy - mv ./examples/react-app/dist/ .ghpages-deploy/example/ - mv ./docs/* .ghpages-deploy/ - - - uses: actions/upload-artifact@v4 - with: - include-hidden-files: true - name: ghpages-deploy-artifacts - path: .ghpages-deploy - retention-days: 1 + - name: Compile and Upload Artifacts + uses: ./.github/workflows/actions/compile-gh-pages publish: runs-on: ubuntu-latest - needs: [compile-v1-docs, compile-github-pages] + needs: [compile-gh-pages, compile-gh-pages-legacy] steps: - name: Checkout uses: actions/checkout@v4 @@ -92,7 +66,7 @@ jobs: merge-multiple: true - name: Deploy to Github Pages - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: .ghpages-deploy From f3177bc9b8058d859fbf15bd8ced578b7fe39eb1 Mon Sep 17 00:00:00 2001 From: Steven Luscher Date: Sun, 24 Nov 2024 23:43:49 -0800 Subject: [PATCH 2/2] Add comments --- .github/workflows/actions/compile-gh-pages/action.yml | 5 ++++- .github/workflows/preview-gh-pages.yml | 3 ++- .github/workflows/publish-gh-pages.yml | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actions/compile-gh-pages/action.yml b/.github/workflows/actions/compile-gh-pages/action.yml index 56331cfa3475..4e68ebcaa45a 100644 --- a/.github/workflows/actions/compile-gh-pages/action.yml +++ b/.github/workflows/actions/compile-gh-pages/action.yml @@ -4,6 +4,8 @@ description: Compiles content for GitHub Pages and uploads it to the artifact ca inputs: pr-number: type: number + # Typically used when it's important to know the base URL for the GitHub Pages site, + # for instance when a web app's router needs to know its base URL. repository: default: 'solana-web3.js' type: string @@ -24,7 +26,8 @@ runs: mv ./examples/react-app/dist/ .ghpages-deploy/example/ mv ./docs/* .ghpages-deploy/ - - uses: actions/upload-artifact@v4 + - name: Upload Deploy Directory to Artifact Cache + uses: actions/upload-artifact@v4 with: include-hidden-files: true name: ghpages-deploy-artifacts diff --git a/.github/workflows/preview-gh-pages.yml b/.github/workflows/preview-gh-pages.yml index c3288dd0180c..1751ed661088 100644 --- a/.github/workflows/preview-gh-pages.yml +++ b/.github/workflows/preview-gh-pages.yml @@ -58,7 +58,8 @@ jobs: - name: Install Dependencies uses: ./.github/workflows/actions/install-dependencies - - uses: actions/download-artifact@v4 + - name: Download Deploy Directory from Artifact Cache + uses: actions/download-artifact@v4 with: path: .ghpages-deploy pattern: ghpages-deploy-artifacts* diff --git a/.github/workflows/publish-gh-pages.yml b/.github/workflows/publish-gh-pages.yml index 0be21b6f282e..1993584ced0d 100644 --- a/.github/workflows/publish-gh-pages.yml +++ b/.github/workflows/publish-gh-pages.yml @@ -59,7 +59,8 @@ jobs: - name: Install Dependencies uses: ./.github/workflows/actions/install-dependencies - - uses: actions/download-artifact@v4 + - name: Download Deploy Directory from Artifact Cache + uses: actions/download-artifact@v4 with: path: .ghpages-deploy pattern: ghpages-deploy-artifacts*