diff --git a/.github/workflows/publish-preview-comment.yml b/.github/workflows/publish-preview-comment.yml new file mode 100644 index 000000000..c05fca857 --- /dev/null +++ b/.github/workflows/publish-preview-comment.yml @@ -0,0 +1,36 @@ +name: Notify about new "Publish preview" workflow + +on: + issue_comment: + types: created + +permissions: {} + +jobs: + notify: + name: Notify about new "Publish preview" workflow + if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot publish-preview') }} + permissions: + pull-requests: write + environment: default-branch + runs-on: ubuntu-latest + steps: + - name: Notify + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + with: + script: | + const { owner, repo } = context.repo; + const workflowUrl = `https://github.com/${owner}/${repo}/actions/workflows/publish-preview.yml`; + + const commentBody = [ + 'The "Publish preview" workflow has been updated to a new version that uses OIDC for authentication. Please use the new workflow instead of this one.', + '', + `To trigger the new workflow, go to the [Publish a preview build](${workflowUrl}) workflow, click "Run workflow", and enter \`${context.issue.number}\` as the pull request number.`, + ].join('\n'); + + await github.rest.issues.createComment({ + owner, + repo, + issue_number: context.issue.number, + body: commentBody, + }); diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index 47b5de367..6938773f6 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -1,23 +1,54 @@ name: Publish a preview build on: - issue_comment: - types: created + workflow_dispatch: + inputs: + pull-request: + description: 'Pull request number to publish a preview build for. Mutually exclusive with "branch".' + required: false + type: number + branch: + description: 'Branch in this repository to publish a preview build for. Mutually exclusive with "pull-request".' + required: false + type: string + default: '' + packages: + description: 'Comma-separated list of packages to publish, e.g., "@metamask/bitcoin-wallet-snap, tron-wallet-snap". Mutually exclusive with "only-changed-packages". Leave empty to publish all packages.' + required: false + type: string + default: '' + only-changed-packages: + description: 'Only publish packages changed compared to the base branch. Mutually exclusive with "packages".' + required: false + type: boolean + default: true + dry-run: + description: 'Perform a dry run.' + type: boolean + required: false + default: false permissions: contents: read - pull-requests: write jobs: publish-preview: - if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot publish-preview') }} - uses: MetaMask/github-tools/.github/workflows/publish-preview.yml@88836cf1473f73a64848a809cf89e616ed6ed692 # v1.22.0 + name: Publish preview + permissions: + contents: read + id-token: write + pull-requests: write + uses: MetaMask/github-tools/.github/workflows/publish-preview-oidc.yml@a4c45d2f30cf1d30b0ee43303bb8ea6441cb54c2 # v1.27.0 with: + pull-request: ${{ fromJSON(inputs.pull-request || '0') }} + branch: ${{ inputs.branch }} + packages: ${{ inputs.packages }} + only-changed-packages: ${{ inputs.only-changed-packages }} + dry-run: ${{ inputs.dry-run }} rename-after-install-and-build: true - environment: default-branch + environment: npm-preview docs-url: 'https://github.com/MetaMask/internal-snaps/blob/main/docs/processes/preview-builds.md' secrets: - PUBLISH_PREVIEW_NPM_TOKEN: ${{ secrets.PUBLISH_PREVIEW_NPM_TOKEN }} BUILD_ENV: | { "LOG_LEVEL": "error", diff --git a/docs/processes/preview-builds.md b/docs/processes/preview-builds.md index de741488b..32788fffa 100644 --- a/docs/processes/preview-builds.md +++ b/docs/processes/preview-builds.md @@ -15,8 +15,8 @@ Generally, when working with preview builds, you will follow this process: To publish preview builds: 1. Create a pull request with the changes to your package(s). -2. Post a comment on the pull request with the text `@metamaskbot publish-preview`. The `publish-preview` GitHub action will kick off to generate and publish preview builds for all packages in the monorepo. -3. After a few minutes, you will see a new comment that lists the newly published packages along with their versions. +2. Go to the [Publish a preview build](https://github.com/MetaMask/internal-snaps/actions/workflows/publish-preview.yml) workflow, click "Run workflow", and enter the pull request number (or a branch name). By default, only packages changed compared to the base branch are published; you can instead provide a list of packages to publish. +3. After a few minutes, you will see a new comment on the pull request that lists the newly published packages along with their versions. This workflow is available to members of the MetaMask engineering team on GitHub. Independent contributors should use [local builds](./local-builds.md) instead.