Skip to content

Commit 6b899df

Browse files
balzssclaude
andcommitted
refactor(ui-scripts): fold tagged-release into pr-snapshot workflow
Drops the standalone `tagged-release` workflow_dispatch choice and reusable workflow. Instead, the existing `pr-snapshot` path accepts two optional inputs — `custom_version` and `dist_tag` — that, when set, override the auto-computed snapshot version and dist-tag. Behavior is identical from the operator's perspective: pick `pr-snapshot` in the GitHub UI, fill in `custom_version` (e.g. `11.7.3-SECURITY.0`) and `dist_tag` (e.g. `security`), and the job publishes that exact prerelease to npmjs under that tag. The `publishCustomVersion` function is removed; the snapshot path now takes an optional `customVersion` that, if set, replaces `calculateNextSnapshotVersion()` and the operator-supplied `distTag` replaces the default `pr-snapshot` / `snapshot` tag. Validation moves to a single `validateCustomVersionInputs()` helper that runs before anything else. Net diff: -1 workflow file, ~50 fewer lines, same guard rails. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0af5a27 commit 6b899df

4 files changed

Lines changed: 81 additions & 129 deletions

File tree

.github/workflows/_pr-release-reusable.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
name: PR release to npm (Reusable)
22
on:
33
workflow_call:
4+
inputs:
5+
custom_version:
6+
description: 'Optional: exact semver prerelease version to publish, overriding the auto-computed snapshot version.'
7+
required: false
8+
type: string
9+
default: ''
10+
dist_tag:
11+
description: 'Optional: npm dist-tag override. Required when custom_version is set. Cannot be "latest".'
12+
required: false
13+
type: string
14+
default: ''
415

516
permissions:
617
id-token: write
@@ -11,6 +22,20 @@ jobs:
1122
runs-on: ubuntu-latest
1223
name: Release to npm
1324
steps:
25+
- name: Validate custom-version inputs
26+
if: inputs.custom_version != ''
27+
env:
28+
CUSTOM_VERSION: ${{ inputs.custom_version }}
29+
DIST_TAG: ${{ inputs.dist_tag }}
30+
run: |
31+
if [ -z "$DIST_TAG" ]; then
32+
echo "::error::dist_tag is required when custom_version is set"
33+
exit 1
34+
fi
35+
if [ "$DIST_TAG" = "latest" ]; then
36+
echo "::error::dist_tag cannot be 'latest'"
37+
exit 1
38+
fi
1439
- uses: actions/checkout@v4
1540
with:
1641
fetch-depth: 0
@@ -25,7 +50,15 @@ jobs:
2550
- name: Set up project
2651
run: pnpm run bootstrap
2752
- name: Release to NPM
28-
run: pnpm run release --prRelease
53+
env:
54+
CUSTOM_VERSION: ${{ inputs.custom_version }}
55+
DIST_TAG: ${{ inputs.dist_tag }}
56+
run: |
57+
if [ -n "$CUSTOM_VERSION" ]; then
58+
pnpm run release --prRelease --customVersion="$CUSTOM_VERSION" --distTag="$DIST_TAG"
59+
else
60+
pnpm run release --prRelease
61+
fi
2962
- name: Get commit message
3063
run: | # puts the first line of the last commit message to the commmit_message env var
3164
echo "commmit_message=$(git log --format=%B -n 1 ${{ github.event.after }} | head -n 1)" >> $GITHUB_ENV

.github/workflows/_tagged-release-reusable.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

.github/workflows/release_to_npm.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ on:
1313
options:
1414
- manual
1515
- pr-snapshot
16-
- tagged-release
1716
default: 'manual'
1817
custom_version:
19-
description: 'Exact semver prerelease version to publish (only for "tagged-release"). Example: 11.7.3-SECURITY.0'
18+
description: 'Optional: exact semver prerelease version to publish (pr-snapshot only). Overrides the auto-computed snapshot version. Example: 11.7.3-SECURITY.0'
2019
required: false
2120
type: string
2221
default: ''
2322
dist_tag:
24-
description: 'npm dist-tag to publish under (only for "tagged-release"). Cannot be "latest".'
23+
description: 'Optional: npm dist-tag override (pr-snapshot only). Required when custom_version is set. Cannot be "latest".'
2524
required: false
2625
type: string
27-
default: 'security'
26+
default: ''
2827

2928
permissions:
3029
id-token: write # Required for OIDC token generation
@@ -49,20 +48,12 @@ jobs:
4948
contents: write
5049
secrets: inherit
5150

52-
# PR snapshot release
51+
# PR snapshot release. Optionally accepts custom_version + dist_tag to mirror
52+
# a previously-published private security release onto the public registry
53+
# under a non-latest dist-tag.
5354
pr-release:
5455
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'pr-snapshot'
5556
uses: ./.github/workflows/_pr-release-reusable.yml
56-
permissions:
57-
id-token: write
58-
contents: write
59-
secrets: inherit
60-
61-
# Tagged release at an operator-supplied prerelease version (e.g. to mirror
62-
# a private security release onto the public registry under a non-latest tag).
63-
tagged-release:
64-
if: github.event_name == 'workflow_dispatch' && inputs.release_type == 'tagged-release'
65-
uses: ./.github/workflows/_tagged-release-reusable.yml
6657
with:
6758
custom_version: ${{ inputs.custom_version }}
6859
dist_tag: ${{ inputs.dist_tag }}

packages/ui-scripts/lib/commands/publish.js

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,15 @@ async function publish({
9292
}) {
9393
const isRegularRelease = isReleaseCommit(version)
9494

95+
validateCustomVersionInputs({ customVersion, distTag })
96+
9597
checkNpmAuth()
9698

9799
try {
98100
checkWorkingDirectory()
99101
const packages = pkgUtils.getPackages().filter((pkg) => !pkg.private)
100102

101-
if (customVersion) {
102-
await publishCustomVersion({
103-
packageName,
104-
customVersion,
105-
distTag,
106-
packages
107-
})
108-
} else if (isRegularRelease) {
103+
if (isRegularRelease) {
109104
// If on legacy branch, and it is a release, its tag should say vx_maintenance
110105
const tag = isMaintenance
111106
? `v${version.split('.')[0]}_maintenance`
@@ -117,14 +112,15 @@ async function publish({
117112
packages
118113
})
119114
} else {
120-
const tag = prRelease ? 'pr-snapshot' : 'snapshot'
115+
const tag = distTag || (prRelease ? 'pr-snapshot' : 'snapshot')
121116
info(`📦 Version: ${version}, Tag: ${tag}`)
122117
await publishSnapshotVersion({
123118
version,
124119
packageName,
125120
packages,
126121
tag,
127-
prRelease
122+
prRelease,
123+
customVersion
128124
})
129125
}
130126
} finally {
@@ -133,63 +129,53 @@ async function publish({
133129
}
134130

135131
/**
136-
* Publishes each package to pnpm.
137-
*/
138-
async function publishRegularVersion(arg) {
139-
const { version, packages, tag } = arg
140-
for await (const pkg of publishPackages(packages, version, tag)) {
141-
info(`📦 Version ${version} of ${pkg.name} was successfully published!`)
142-
}
143-
}
144-
145-
/**
146-
* Bumps all packages to an exact, operator-supplied prerelease version
147-
* (e.g. 11.7.3-SECURITY.0) and publishes them under a non-`latest` dist-tag.
148-
* Used to mirror a previously-published private security release onto the
149-
* public registry so open-source consumers can install the same version
150-
* without needing access to the private registry.
132+
* Validates the optional --customVersion / --distTag pair used to mirror a
133+
* private security release onto the public registry under a non-latest tag.
134+
* Throws if the inputs are inconsistent or unsafe.
151135
*/
152-
async function publishCustomVersion(arg) {
153-
const { packageName, customVersion, distTag, packages } = arg
136+
function validateCustomVersionInputs({ customVersion, distTag }) {
137+
if (!customVersion && !distTag) return
154138

155-
if (!semver.valid(customVersion)) {
156-
throw new Error(
157-
`--customVersion must be a valid semver, got: "${customVersion}"`
158-
)
159-
}
160-
if (!semver.prerelease(customVersion)) {
161-
throw new Error(
162-
`--customVersion must be a prerelease (e.g. 11.7.3-SECURITY.0); got "${customVersion}". Refusing to take over a stable version slot.`
163-
)
164-
}
165-
if (!distTag) {
166-
throw new Error('--distTag is required when --customVersion is set.')
139+
if (customVersion) {
140+
if (!semver.valid(customVersion)) {
141+
throw new Error(
142+
`--customVersion must be a valid semver, got: "${customVersion}"`
143+
)
144+
}
145+
if (!semver.prerelease(customVersion)) {
146+
throw new Error(
147+
`--customVersion must be a prerelease (e.g. 11.7.3-SECURITY.0); got "${customVersion}". Refusing to take over a stable version slot.`
148+
)
149+
}
150+
if (!distTag) {
151+
throw new Error('--distTag is required when --customVersion is set.')
152+
}
167153
}
154+
168155
if (distTag === 'latest') {
169-
throw new Error(
170-
'--distTag cannot be "latest" for a custom-version publish.'
171-
)
156+
throw new Error('--distTag cannot be "latest".')
172157
}
158+
}
173159

174-
info(`📦 Custom version: ${customVersion}, Tag: ${distTag}`)
175-
176-
await bumpPackages(packageName, customVersion)
177-
178-
for await (const pkg of publishPackages(packages, customVersion, distTag)) {
179-
info(
180-
`📦 Version ${customVersion} of ${pkg.name} was successfully published!`
181-
)
160+
/**
161+
* Publishes each package to pnpm.
162+
*/
163+
async function publishRegularVersion(arg) {
164+
const { version, packages, tag } = arg
165+
for await (const pkg of publishPackages(packages, version, tag)) {
166+
info(`📦 Version ${version} of ${pkg.name} was successfully published!`)
182167
}
183168
}
184169

185170
/**
186-
* Calculates the new snapshot version based on the latest tag
187-
* and the current commit, then publishes each package to npm
188-
* with the new snapshot version.
171+
* Bumps packages to a snapshot/prerelease version (either operator-supplied
172+
* via --customVersion, or auto-computed from the commit history) and
173+
* publishes them under the given dist-tag.
189174
*/
190175
async function publishSnapshotVersion(arg) {
191-
const { version, packageName, packages, tag, prRelease } = arg
192-
const snapshotVersion = calculateNextSnapshotVersion(version, prRelease)
176+
const { version, packageName, packages, tag, prRelease, customVersion } = arg
177+
const snapshotVersion =
178+
customVersion || calculateNextSnapshotVersion(version, prRelease)
193179

194180
info(`applying new snapshot version (${snapshotVersion}) to each package`)
195181

0 commit comments

Comments
 (0)