diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 52307c9..964b07c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -123,5 +123,4 @@ jobs: uses: ./.github/workflows/publish-release.yml secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }} SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index 3f2ea6c..9fc3a27 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -6,9 +6,6 @@ on: destination_dir: required: true type: string - secrets: - PUBLISH_DOCS_TOKEN: - required: true jobs: publish-docs-to-gh-pages: @@ -17,22 +14,38 @@ jobs: environment: github-pages permissions: contents: write + id-token: write steps: - name: Ensure `destination_dir` is not empty if: ${{ inputs.destination_dir == '' }} run: exit 1 + - name: Get access token + id: get-token + uses: MetaMask/github-tools/.github/actions/get-token@v1 + with: + token-exchange-url: ${{ vars.TOKEN_EXCHANGE_URL }} + permissions: | + contents: write + continue-on-error: true - name: Checkout and setup environment + if: ${{ steps.get-token.outcome == 'success' }} uses: MetaMask/action-checkout-and-setup@v3 with: is-high-risk-environment: true persist-credentials: false - name: Run build script + if: ${{ steps.get-token.outcome == 'success' }} run: yarn build:docs - name: Deploy to `${{ inputs.destination_dir }}` directory of `gh-pages` branch + if: ${{ steps.get-token.outcome == 'success' }} uses: peaceiris/actions-gh-pages@de7ea6f8efb354206b205ef54722213d99067935 with: - # This `PUBLISH_DOCS_TOKEN` needs to be manually set per-repository. - # Look in the repository settings under "Environments", and set this token in the `github-pages` environment. - personal_token: ${{ secrets.PUBLISH_DOCS_TOKEN }} + # A policy must be registered for this repo and workflow + # within the Token Exchange Service. + personal_token: ${{ steps.get-token.outputs.token }} publish_dir: ./docs destination_dir: ${{ inputs.destination_dir }} + - name: Show warning if the get-token step failed + if: ${{ steps.get-token.outcome == 'failure' }} + run: | + echo "::warning::The docs publishing workflow failed because the required token could not be obtained. If you want to publish docs for this repo, you'll need to add a policy to the Token Exchange Service." diff --git a/.github/workflows/publish-main-docs.yml b/.github/workflows/publish-main-docs.yml index b9bbbef..f0b2855 100644 --- a/.github/workflows/publish-main-docs.yml +++ b/.github/workflows/publish-main-docs.yml @@ -9,8 +9,7 @@ jobs: name: Publish docs to `staging` directory of `gh-pages` branch permissions: contents: write + id-token: write uses: ./.github/workflows/publish-docs.yml with: destination_dir: staging - secrets: - PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }} diff --git a/.github/workflows/publish-rc-docs.yml b/.github/workflows/publish-rc-docs.yml index dc8573d..9c640a6 100644 --- a/.github/workflows/publish-rc-docs.yml +++ b/.github/workflows/publish-rc-docs.yml @@ -26,9 +26,8 @@ jobs: name: Publish docs to `rc-${{ needs.get-release-version.outputs.release-version }}` directory of `gh-pages` branch permissions: contents: write + id-token: write uses: ./.github/workflows/publish-docs.yml needs: get-release-version with: destination_dir: rc-${{ needs.get-release-version.outputs.release-version }} - secrets: - PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 6447a0d..3609979 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -7,8 +7,6 @@ on: required: false SLACK_WEBHOOK_URL: required: true - PUBLISH_DOCS_TOKEN: - required: true permissions: contents: read @@ -114,22 +112,20 @@ jobs: needs: get-release-version permissions: contents: write + id-token: write uses: ./.github/workflows/publish-docs.yml with: destination_dir: ${{ needs.get-release-version.outputs.RELEASE_VERSION }} - secrets: - PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }} publish-release-to-latest-gh-pages: name: Publish docs to `latest` directory of `gh-pages` branch needs: publish-npm permissions: contents: write + id-token: write uses: ./.github/workflows/publish-docs.yml with: destination_dir: latest - secrets: - PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }} publish-release: name: Publish to GitHub