Skip to content

Commit 2cf30d4

Browse files
authored
feat: add rename-after-install-and-build input to publish-preview.yml workflow (#254)
1 parent 351d8ec commit 2cf30d4

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

.github/workflows/publish-preview.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ on:
2323
type: boolean
2424
required: false
2525
default: true
26+
rename-after-install-and-build:
27+
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.'
28+
type: boolean
29+
required: false
30+
default: false
2631
environment:
2732
description: 'GitHub environment for the publish job (e.g., default-branch). Empty = no gate.'
2833
type: string
@@ -46,6 +51,9 @@ on:
4651
secrets:
4752
PUBLISH_PREVIEW_NPM_TOKEN:
4853
required: true
54+
BUILD_ENV:
55+
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.'
56+
required: false
4957

5058
jobs:
5159
is-fork-pull-request:
@@ -100,7 +108,28 @@ jobs:
100108
id: commit-sha
101109
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
102110

103-
- name: Prepare preview builds
111+
- name: Install dependencies (pre-build)
112+
if: ${{ inputs.rename-after-install-and-build }}
113+
run: yarn install --no-immutable
114+
115+
- name: Mask build environment values
116+
env:
117+
BUILD_ENV: ${{ secrets.BUILD_ENV }}
118+
run: |
119+
if [[ -n "$BUILD_ENV" ]]; then
120+
while IFS= read -r line; do
121+
if [[ -n "$line" ]]; then
122+
echo "::add-mask::$line"
123+
fi
124+
done < <(jq --raw-output '.[] | tostring' <<< "$BUILD_ENV")
125+
fi
126+
127+
- name: Build (pre-rename)
128+
if: ${{ inputs.rename-after-install-and-build }}
129+
env: ${{ fromJSON(secrets.BUILD_ENV || '{}') }}
130+
run: ${{ inputs.build-command }}
131+
132+
- name: Prepare preview manifests
104133
env:
105134
NPM_SCOPE: ${{ inputs.npm-scope }}
106135
COMMIT_SHA: ${{ steps.commit-sha.outputs.COMMIT_SHA }}
@@ -139,10 +168,12 @@ jobs:
139168
prepare_manifest package.json
140169
fi
141170
142-
echo "Installing dependencies..."
143-
yarn install --no-immutable
171+
- name: Install dependencies
172+
run: yarn install --no-immutable
144173

145-
- name: Build
174+
- name: Build (post-rename)
175+
if: ${{ !inputs.rename-after-install-and-build }}
176+
env: ${{ fromJSON(secrets.BUILD_ENV || '{}') }}
146177
run: ${{ inputs.build-command }}
147178

148179
- name: Upload build artifacts (monorepo)

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `rename-after-install-and-build` input to the `publish-preview` reusable workflow ([#254](https://github.com/MetaMask/github-tools/pull/254))
13+
- 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.
14+
- Defaults to `false` to preserve existing behavior for non-snap consumers.
15+
- Add `BUILD_ENV` secret input to the `publish-preview` reusable workflow
16+
- 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.
17+
1018
## [1.12.0]
1119

1220
### Changed

0 commit comments

Comments
 (0)