Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ on:
type: boolean
required: false
default: true
is-snap:
description: 'Whether the consumer is a Snap. When true, the build runs before manifests are renamed so that snap artifacts (e.g. dist/bundle.js, snap.manifest.json) capture the original package name.'
type: boolean
required: false
default: false
Comment on lines +26 to +30
Copy link
Copy Markdown
Contributor

@mcmire mcmire May 21, 2026

Choose a reason for hiding this comment

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

Instead of adding a flag that's specific to a type of project, what are your thoughts on adding a flag that describes the behavior? Maybe something like:

Suggested change
is-snap:
description: 'Whether the consumer is a Snap. When true, the build runs before manifests are renamed so that snap artifacts (e.g. dist/bundle.js, snap.manifest.json) capture the original package name.'
type: boolean
required: false
default: false
rename-after-install-and-build:
description: 'Governs where in the workflow that packages in the repo are renamed to use the preview build scope. If true, this step runs after the install and build steps; if false (default), it runs before. This option is mostly for Snaps so that artifacts (e.g. dist/bundle.js, snap.manifest.json) capture the original package name, not the preview build name.'
type: boolean
required: false
default: false

environment:
description: 'GitHub environment for the publish job (e.g., default-branch). Empty = no gate.'
type: string
Expand All @@ -46,6 +51,9 @@ on:
secrets:
PUBLISH_PREVIEW_NPM_TOKEN:
required: true
BUILD_ENV:
description: 'JSON object of environment variables to pass to the build step (e.g. ''{"FOO":"bar","API_URL":"https://..."}''). Use this for build-time configuration and secrets needed by the build command.'
required: false

jobs:
is-fork-pull-request:
Expand Down Expand Up @@ -100,7 +108,16 @@ jobs:
id: commit-sha
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

- name: Prepare preview builds
- name: Install dependencies (snap, pre-build)
if: ${{ inputs.is-snap }}
run: yarn install --no-immutable

- name: Build (snap, pre-rename)
if: ${{ inputs.is-snap }}
env: ${{ fromJSON(secrets.BUILD_ENV || '{}') }}
run: ${{ inputs.build-command }}

- name: Prepare preview manifests
env:
NPM_SCOPE: ${{ inputs.npm-scope }}
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
Expand Down Expand Up @@ -139,10 +156,12 @@ jobs:
prepare_manifest package.json
fi

echo "Installing dependencies..."
yarn install --no-immutable
- name: Install dependencies
run: yarn install --no-immutable

- name: Build
if: ${{ !inputs.is-snap }}
env: ${{ fromJSON(secrets.BUILD_ENV || '{}') }}
run: ${{ inputs.build-command }}

- name: Upload build artifacts (monorepo)
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `is-snap` input to the `publish-preview` reusable workflow
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you associate the current PR with these changelog entries? e.g.

Suggested change
- Add `is-snap` input to the `publish-preview` reusable workflow
- Add `is-snap` input to the `publish-preview` reusable workflow ([#254](https://github.com/MetaMask/github-tools/pull/254))

- When set to `true`, the workflow installs dependencies and runs the build _before_ renaming workspace manifests to the preview NPM scope. This ensures snap artifacts (e.g. `dist/bundle.js`, `snap.manifest.json` and its `source.shasum`) are produced with the original `@metamask/...` package name.
- Defaults to `false` to preserve existing behavior for non-snap consumers.
- Add `BUILD_ENV` secret input to the `publish-preview` reusable workflow
- Accepts a JSON object of environment variables that will be passed to the build step (e.g. `'{"API_URL":"https://...","LOG_LEVEL":"all"}'`). Useful when the build command needs additional configuration or secret values to produce a valid preview build.

## [1.9.4]

### Fixed
Expand Down