Skip to content

Commit f9e45ca

Browse files
committed
Improve preview builds
When we added preview builds to some polyrepos, we copied the workflow from this repo and made some improvements at the same time. This commit applies those same improvements. - Add emoji reaction to preview build request comment when workflow begins. - Simplify preview build docs by removing external contributor-specific instructions. - Remove package scripts from root and workspace packages. The scripts used by the preview build workflow aren't meant to be called explicitly, and in fact may be dangerous to do so. This also makes the workflow more copy-and-pasteable to other projects. - Convert script to generate reply comment to bash. - Simplify output in reply comment, and fix link to docs.
1 parent 7e387eb commit f9e45ca

File tree

65 files changed

+88
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+88
-196
lines changed

.github/workflows/publish-preview.yml

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ jobs:
99
name: Determine whether this issue comment was on a pull request from a fork
1010
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '@metamaskbot publish-preview') }}
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
pull-requests: read
1215
outputs:
1316
IS_FORK: ${{ steps.is-fork.outputs.IS_FORK }}
1417
steps:
@@ -17,23 +20,46 @@ jobs:
1720
id: is-fork
1821
run: echo "IS_FORK=$(gh pr view --json isCrossRepository --jq '.isCrossRepository' "${PR_NUMBER}" )" >> "$GITHUB_OUTPUT"
1922
env:
20-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2124
PR_NUMBER: ${{ github.event.issue.number }}
2225

23-
publish-preview:
24-
name: Publish build preview
26+
react-to-comment:
27+
name: React to the comment
2528
needs: is-fork-pull-request
26-
permissions:
27-
pull-requests: write
2829
# This ensures we don't publish on forks. We can't trust forks with this token.
2930
if: ${{ needs.is-fork-pull-request.outputs.IS_FORK == 'false' }}
3031
runs-on: ubuntu-latest
32+
permissions:
33+
contents: read
34+
pull-requests: write
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: React to the comment
38+
run: |
39+
gh api \
40+
--method POST \
41+
-H "Accept: application/vnd.github+json" \
42+
-H "X-GitHub-Api-Version: 2022-11-28" \
43+
"/repos/${REPO}/issues/comments/${COMMENT_ID}/reactions" \
44+
-f content='+1'
45+
env:
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
COMMENT_ID: ${{ github.event.comment.id }}
48+
REPO: ${{ github.repository }}
49+
50+
publish-preview:
51+
name: Publish build preview
52+
needs: react-to-comment
53+
runs-on: ubuntu-latest
54+
permissions:
55+
contents: read
56+
pull-requests: write
3157
steps:
3258
- uses: actions/checkout@v4
3359
- name: Check out pull request
3460
run: gh pr checkout "${PR_NUMBER}"
3561
env:
36-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3763
PR_NUMBER: ${{ github.event.issue.number }}
3864
- name: Checkout and setup environment
3965
uses: MetaMask/action-checkout-and-setup@v1
@@ -42,17 +68,15 @@ jobs:
4268
- name: Get commit SHA
4369
id: commit-sha
4470
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
45-
- run: yarn prepare-preview-builds @metamask-previews ${{ steps.commit-sha.outputs.COMMIT_SHA }}
71+
- run: ./scripts/prepare-preview-builds.sh @metamask-previews ${{ steps.commit-sha.outputs.COMMIT_SHA }}
4672
- run: yarn build
47-
- name: Publish preview build
48-
run: yarn publish-previews
73+
- name: Publish preview builds
74+
run: yarn workspaces foreach --all --no-private --parallel --verbose run yarn npm publish --tag preview
4975
env:
5076
YARN_NPM_AUTH_TOKEN: ${{ secrets.PUBLISH_PREVIEW_NPM_TOKEN }}
51-
- name: Generate preview build message
52-
run: yarn tsx scripts/generate-preview-build-message.ts
53-
- name: Post build preview in comment
54-
run: gh pr comment "${PR_NUMBER}" --body-file preview-build-message.txt
77+
- name: Post list of preview build identifiers
78+
run: ./scripts/generate-preview-build-message.sh | gh pr comment "${PR_NUMBER}" --body-file -
5579
env:
80+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5681
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
57-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5882
PR_NUMBER: ${{ github.event.issue.number }}

docs/contributing.md

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -129,70 +129,44 @@ If you're developing your project locally and want to test changes to a package,
129129
130130
3. Due to the use of Yarn's `file:` protocol, if you update the package in the monorepo, then you'll need to run `yarn install` in the project again.
131131
132-
### Testing changes to packages with preview builds
132+
## Testing changes against other projects using preview builds
133133
134-
If you want to test changes to a package where it would be unwieldy or impossible to use a local version, such as on CI, you can publish a preview build and configure your project to use it.
134+
If you are working on a pull request and want to test changes to one or more packages in another project before you publish them, you can create _preview builds_ and then configure your project to use them.
135135
136-
#### Publishing preview builds as a MetaMask contributor
137-
138-
If you're a member of the MetaMask organization, you can create preview builds based on a pull request by following these steps:
139-
140-
1. Post a comment on the pull request with the text `@metamaskbot publish-preview`. This starts the `publish-preview` GitHub action, which will create preview builds for all packages in the monorepo.
141-
2. After a few minutes, the action should complete and you will see a new comment that lists the newly published packages along with their versions.
142-
143-
Note two things about each package:
136+
### Creating preview builds
144137
138+
1. Within your pull request, post a comment with the text `@metamaskbot publish-preview`. This starts the `publish-preview` GitHub action, which will build all of the packages as they exist on the branch and publish them to NPM under a special namespace.
139+
2. After a few minutes, the action should complete and you will see a new comment. Note two things:
145140
- The name is scoped to `@metamask-previews` instead of `@metamask`.
146141
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-preview-e2df9b4` instead of `1.2.3`.
147142
148-
Now you can [use these preview builds in your project](#using-preview-builds).
149-
150-
If you make more changes to a package, follow step 2 again, making sure to update the reference to the package in your project's `package.json` to use the newly published preview version.
151-
152-
#### Publishing preview builds as an independent contributor
153-
154-
If you've forked this repository, you can create preview builds based on a branch by following these steps:
155-
156-
1. First, since an NPM scope is used to host preview build releases, you'll need access to one. If you do not, you can either [create a new organization](https://www.npmjs.com/org/create) or [convert your existing username into an organization](https://www.npmjs.com/org/upgrade).
157-
158-
2. Once you've done this, open the `package.json` for each package that you want to publish and change the scope in the name from `@metamask` to `@<NPM_ORG>`, replacing `NPM_ORG` with your NPM organization.
159-
160-
3. Next, run the following command to create and publish the preview builds (again, replacing `NPM_ORG` as appropriate):
161-
162-
```
163-
yarn prepare-preview-builds "@<NPM_ORG>" "$(git rev-parse --short HEAD)" && yarn build && yarn publish-previews
164-
```
165-
166-
You should be able to see the published version of each package in the output. Note two things:
167-
168-
- The name is scoped to the NPM organization you entered instead of `@metamask`.
169-
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-preview-e2df9b4` instead of `1.2.3`.
170-
171-
Now you can [use these preview builds in your project](#using-preview-builds).
172-
173-
If you make more changes to a package, follow step 3 again, making sure to update the reference to the package in your project's `package.json` to use the newly published preview version.
143+
### Using preview builds
174144
175-
#### Using preview builds
145+
To use preview builds within a project, you need to override the resolution logic for your package manager so that the "production" version of that package is replaced with the preview version. Here's how you do that:
176146
177-
To use a preview build for a package within a project, you need to override the resolution logic for your package manager so that the "production" version of that package is replaced with the preview version. Here's how you do that:
178-
179-
1. Open `package.json` in the project and locate the dependency entry for the core package for which you want to use a preview build.
147+
1. Open `package.json` in the project and locate the entry for this package in `dependencies`.
180148
2. Locate the section responsible for resolution overrides (or create it if it doesn't exist). If you're using Yarn, this is `resolutions`; if you're using NPM or any other package manager, this is `overrides`.
181-
3. Add a line to this section that mirrors the dependency entry on the left-hand side and points to the preview version on the right-hand side:
149+
3. Add a line to this section that mirrors the dependency entry on the left-hand side and points to the preview version on the right-hand side. Note the exact format of the left-hand side will differ based on which version of Yarn or NPM you are using. For example:
150+
- For Yarn Modern, you will add something like this to `resolutions`:
151+
```
152+
"@metamask/foo-controller@^1.2.3": "npm:@metamask-previews/[email protected]"
153+
```
154+
- For Yarn Classic, you will add something like this to `resolutions`:
155+
```
156+
"@metamask/foo-controller": "npm:@metamask-previews/[email protected]"
157+
```
158+
- For NPM, you will add something like this to `overrides`:
159+
```
160+
"@metamask/foo-controller": "npm:@metamask-previews/[email protected]"
161+
```
162+
4. Run `yarn install`.
182163
183-
```
184-
"@metamask/<PACKAGE_NAME>@<PRODUCTION_VERSION_RANGE>": "npm:@<NPM_ORG>/<PACKAGE_NAME>@<PREVIEW_VERSION>"
185-
```
164+
### Updating preview builds
186165
187-
> **Example:**
188-
>
189-
> - If your project uses Yarn, `@metamask/controller-utils` is listed in dependencies at `^1.1.4`, and you want to use the preview version `1.2.3-preview-e2df9b4`, add the following to `resolutions`:
190-
>
191-
> ```
192-
> "@metamask/controller-utils@^1.1.4": "npm:@metamask-previews/[email protected]"
193-
> ```
166+
If you make more changes to your pull request and want to create a new set of preview builds:
194167
195-
4. Run `yarn install`.
168+
1. Post another `@metamaskbot` comment on the pull request and wait for the response.
169+
2. Update the version of the preview builds in your project's `package.json`. Make sure to re-run `yarn install`!
196170
197171
## Releasing changes
198172

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
"lint:misc": "prettier --no-error-on-unmatched-pattern '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' '!merged-packages/**' --ignore-path .gitignore",
3131
"lint:teams": "tsx scripts/lint-teams-json.ts",
3232
"prepack": "./scripts/prepack.sh",
33-
"prepare-preview-builds": "./scripts/prepare-preview-builds.sh",
34-
"publish-previews": "yarn workspaces foreach --all --no-private --parallel --verbose run publish:preview",
3533
"setup": "yarn install",
3634
"test": "yarn test:scripts --silent --collectCoverage=false --reporters=jest-silent-reporter && yarn test:packages",
3735
"test:clean": "yarn workspaces foreach --all --parallel --verbose run test:clean && yarn test",

packages/account-tree-controller/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"build:docs": "typedoc",
4040
"changelog:update": "../../scripts/update-changelog.sh @metamask/account-tree-controller",
4141
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/account-tree-controller",
42-
"publish:preview": "yarn npm publish --tag preview",
4342
"since-latest-release": "../../scripts/since-latest-release.sh",
4443
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
4544
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",

packages/accounts-controller/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"build:docs": "typedoc",
4040
"changelog:update": "../../scripts/update-changelog.sh @metamask/accounts-controller",
4141
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/accounts-controller",
42-
"publish:preview": "yarn npm publish --tag preview",
4342
"since-latest-release": "../../scripts/since-latest-release.sh",
4443
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
4544
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",

packages/address-book-controller/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"build:docs": "typedoc",
4040
"changelog:update": "../../scripts/update-changelog.sh @metamask/address-book-controller",
4141
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/address-book-controller",
42-
"publish:preview": "yarn npm publish --tag preview",
4342
"since-latest-release": "../../scripts/since-latest-release.sh",
4443
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
4544
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",

packages/announcement-controller/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"build:docs": "typedoc",
4040
"changelog:update": "../../scripts/update-changelog.sh @metamask/announcement-controller",
4141
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/announcement-controller",
42-
"publish:preview": "yarn npm publish --tag preview",
4342
"since-latest-release": "../../scripts/since-latest-release.sh",
4443
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
4544
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",

packages/app-metadata-controller/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"build:docs": "typedoc",
4040
"changelog:update": "../../scripts/update-changelog.sh @metamask/app-metadata-controller",
4141
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/app-metadata-controller",
42-
"publish:preview": "yarn npm publish --tag preview",
4342
"since-latest-release": "../../scripts/since-latest-release.sh",
4443
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
4544
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",

packages/approval-controller/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"build:docs": "typedoc",
4040
"changelog:update": "../../scripts/update-changelog.sh @metamask/approval-controller",
4141
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/approval-controller",
42-
"publish:preview": "yarn npm publish --tag preview",
4342
"since-latest-release": "../../scripts/since-latest-release.sh",
4443
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
4544
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",

packages/assets-controllers/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"build:docs": "typedoc",
4040
"changelog:update": "../../scripts/update-changelog.sh @metamask/assets-controllers",
4141
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/assets-controllers",
42-
"publish:preview": "yarn npm publish --tag preview",
4342
"since-latest-release": "../../scripts/since-latest-release.sh",
4443
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
4544
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",

0 commit comments

Comments
 (0)