Skip to content

feat: add rename-after-install-and-build input to publish-preview.yml workflow#254

Merged
mikesposito merged 10 commits into
mainfrom
mikesposito/snap-previews
Jun 11, 2026
Merged

feat: add rename-after-install-and-build input to publish-preview.yml workflow#254
mikesposito merged 10 commits into
mainfrom
mikesposito/snap-previews

Conversation

@mikesposito

@mikesposito mikesposito commented May 20, 2026

Copy link
Copy Markdown
Member

The reusable publish-preview workflow renames each workspace's package.json#name from @metamask/... to @metamask-previews/... before running the build. This works for typical libraries but breaks for Snap packages, because:

  • The Snap build (mm-snap build) embeds the package name into dist/bundle.js.
  • snap.manifest.json contains a source.shasum computed over the bundle, the manifest itself (minus the shasum), the icon, and locales.
  • source.location.npm.packageName in the manifest must match package.json#name at publish time.
    When the rename happens before the build, the bundle and manifest are produced against the preview scope, the shasum is computed over the contaminated bundle, and downstream clients that verify against the published @metamask/... shasum reject the snap.
    The workaround used by snap repos today (e.g. snap-tron-wallet) is to build first, then rename — but the reusable workflow had no way to express that ordering.

To fix this issue and make this workflow usable for Snaps, this PR adds a new boolean input is-snap (default false) to .github/workflows/publish-preview.yml.

Existing consumers don't need to change anything. Snap consumers add a single input:

jobs:
  publish-preview:
    uses: MetaMask/github-tools/.github/workflows/publish-preview.yml
    with:
      is-snap: true
    secrets:
      PUBLISH_PREVIEW_NPM_TOKEN: ${{ secrets.PUBLISH_PREVIEW_NPM_TOKEN }}

Note

Medium Risk
Changes CI ordering for preview builds and introduces secret env injection into build steps; default path is unchanged but misconfigured BUILD_ENV or rename ordering could break consumer preview builds.

Overview
Extends the reusable publish-preview workflow so consumers can control when package names are rewritten to the preview NPM scope, and can inject build-time environment from secrets.

Adds rename-after-install-and-build (default false). When true, the job runs install → build → manifest rename → install so artifacts like Snap bundles and snap.manifest.json are built under the original @metamask/... name before preview renaming. When false, behavior stays rename → install → build.

Adds optional secret BUILD_ENV (JSON key/value map) applied to the build step via fromJSON, with a step that masks those values in logs. The prepare step is renamed to Prepare preview manifests; install/build are split into conditional pre-rename and post-rename steps.

Reviewed by Cursor Bugbot for commit 9994d8b. Bugbot is set up for automated code reviews on this repo. Configure here.

Allow callers to pass arbitrary build-time environment variables to the
build step via a JSON object passed as a secret. This is needed by snap
consumers whose build commands require additional configuration (e.g.
API URLs, RPC endpoints) to produce valid preview builds.
gabrieledm
gabrieledm previously approved these changes May 21, 2026

@gabrieledm gabrieledm left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mikesposito

mikesposito commented May 21, 2026

Copy link
Copy Markdown
Member Author

@mikesposito mikesposito marked this pull request as ready for review May 21, 2026 15:54
wantedsystem
wantedsystem previously approved these changes May 21, 2026
Comment thread .github/workflows/publish-preview.yml Outdated
Comment thread CHANGELOG.md Outdated
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
@mikesposito mikesposito dismissed stale reviews from wantedsystem and gabrieledm via 8192f4b June 9, 2026 09:50
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b97ae02. Configure here.

Comment thread .github/workflows/publish-preview.yml Outdated
Comment thread CHANGELOG.md Outdated
Comment thread .github/workflows/publish-preview.yml Outdated
Comment thread .github/workflows/publish-preview.yml Outdated
Comment thread .github/workflows/publish-preview.yml Outdated
Co-authored-by: Michele Esposito <34438276+mikesposito@users.noreply.github.com>
@mikesposito mikesposito changed the title feat: add is-snap argument to publish-preview.yml workflow feat: add rename-after-install-and-build input to publish-preview.yml workflow Jun 9, 2026
Mrtenz
Mrtenz previously requested changes Jun 9, 2026

@Mrtenz Mrtenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to rethink this, as this conflicts with NPM trusted publishing. 😞 We can't configure multiple sources for a single package, so if the preview packages use the same NPM package name, we'd need to allow npm publish (in addition to npm stage publish) for the production workflow as well.

Is there really no way to publish these Snaps with a different package name?

@Mrtenz Mrtenz dismissed their stale review June 9, 2026 10:30

I misunderstood what this change does.

Comment thread .github/workflows/publish-preview.yml
Comment thread .github/workflows/publish-preview.yml Outdated
Comment thread .github/workflows/publish-preview.yml Outdated
Comment thread .github/workflows/publish-preview.yml Outdated
mikesposito and others added 3 commits June 11, 2026 10:03
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
Co-authored-by: Maarten Zuidhoorn <maarten@zuidhoorn.com>
@mikesposito mikesposito requested a review from Mrtenz June 11, 2026 08:08
@mikesposito mikesposito merged commit 2cf30d4 into main Jun 11, 2026
10 checks passed
@mikesposito mikesposito deleted the mikesposito/snap-previews branch June 11, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants