Skip to content

Commit 9521b10

Browse files
committed
Releases: per-package pipeline with namespaced tags
Implements the release half of the monorepo migration decided in today's interview: each package releases independently, and release tags carry the package name — [email protected], @tailwind-merge/[email protected] — instead of the repo-wide v* scheme. Plain v-prefixed tags remain valid history and are owned by tailwind-merge everywhere in the tooling, so the first namespaced release compares cleanly against v3.6.0. Tag creation needs no new tooling: each publishable package gets an .npmrc with tag-version-prefix and message, which npm version reads when pnpm version runs in the package directory. Verified in scratch git repos for both the plain and the scoped package name: the tag and the version commit message come out namespaced, lifecycle scripts still run in order, and files staged by the version script still join the version commit. The .npmrc files carry a comment preempting their deletion as stale, since pnpm itself deliberately reads no settings from .npmrc. Release drafting splits into one config per package, selected via the action's config-name input: tag-prefix scopes previous-release lookup and version resolution to the package's own tags (option existence verified against release-drafter's schema.json), and include-paths keeps unrelated PRs out of each draft. A PR touching both packages appears in both drafts on purpose; a PR touching neither appears in none. The autolabeler section stays only in the tailwind-merge config because labels are repo-wide. Known transition wrinkle, documented in the release guide: the first namespaced release per package resolves no previous tag, so its draft version and compare line need a manual fix at publish time. npm-publish routes release events by tag prefix in a case statement (tailwind-merge@* and legacy v* build and publish packages/tailwind-merge, @tailwind-merge/vite@* packages/vite, anything else fails the run), threading the resolved package name and directory through job outputs into the build filter, the artifact path, and the publish working directory. test:exports runs with --if-present since only the library ships packaged-exports smoke tests so far, and npm publish gains --access public for the future first publish of the scoped package. The dev-release flow on main pushes stays tailwind-merge-only; its synthetic commenter head tag becomes tailwind-merge@<version>-dev.<sha>. The release-commenter action learns package-namespaced tags: parseTag splits an optional package prefix at the last @ (so scoped names like @tailwind-merge/vite parse too) and carries packageName through ParsedTag, with a fallback-package-name input (default tailwind-merge) owning un-prefixed legacy tags and plain npm version strings. Every comparison site is now package-scoped — base-tag selection considers only same-package releases (legacy v* included for tailwind-merge), the stable-release duplicate guard and the prerelease skip filter ignore comments left by other packages' releases (a PR touching two packages legitimately receives one comment per package), npm URL and packument lookups derive the package name from the tag prefix, and the release marker keeps embedding the full namespaced tag so future runs can re-derive the package. A brand-new package's very first release fails base resolution by design and is documented as such. Five new tests cover the parser matrix, npm-version derivation, package-scoped base picking including the v3.6.0 transition case, cross-package guard tolerance, and the prerelease filter; the suite is now 252 tests. update-readme.mjs stamps generated README links with the namespaced tag derived from the package manifest's own name field. agents/release-workflow.md is rewritten around the per-package model — tag scheme, drafting, publish routing, commenter semantics, first-release wrinkles, and the updated changelog compare-link format — and the internals guide records the publish routing. All edited workflow and drafter YAML parses cleanly; repo-wide lint and the full suite stay green.
1 parent 64590df commit 9521b10

13 files changed

Lines changed: 457 additions & 77 deletions

File tree

‎.github/actions/release-commenter/action.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ inputs:
2828
required: false
2929
default: 'false'
3030
npm-package-name:
31-
description: 'Optional npm package name for SHA-based prerelease base resolution'
31+
description: 'Optional npm package name override; defaults to the package resolved from the tag prefix'
3232
required: false
33+
fallback-package-name:
34+
description: 'Package that owns tags without a package prefix (the pre-monorepo v* history)'
35+
required: false
36+
default: 'tailwind-merge'
3337
runs:
3438
using: 'node24'
3539
main: 'index.js'

‎.github/actions/release-commenter/index.js‎

Lines changed: 131 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if (require.main === module) {
2828

2929
/**
3030
* @typedef {{
31+
* packageName: string | null
3132
* major: number
3233
* minor: number
3334
* patch: number
@@ -245,12 +246,17 @@ async function main() {
245246
}
246247
const shaPrereleaseContext = getShaPrereleaseContext(currentVersion)
247248

249+
// Releases are per package with namespaced tags; un-prefixed tags (legacy v* history) belong to the fallback package. All base-tag selection and existing-comment guards are scoped to the current tag's package so the packages release independently of each other.
250+
const fallbackPackageName = getInput('fallback-package-name', 'tailwind-merge')
251+
const currentPackageName = resolveTagPackageName(currentVersion, fallbackPackageName)
252+
248253
log(`Current tag: ${currentTag}`)
254+
log(`Current package: ${currentPackageName}`)
249255
log(`Dry run: ${dryRun}`)
250256

251257
const currentRelease = await getCurrentRelease(token, owner, repo, currentTag, payload?.release)
252258
const releaseLabel = currentRelease.name || currentRelease.tag
253-
const npmPackageName = npmPackageNameInput || repo
259+
const npmPackageName = npmPackageNameInput || currentPackageName
254260
const releaseUrl = shaPrereleaseContext
255261
? npmVersionUrl(npmPackageName, currentTag)
256262
: currentRelease.htmlUrl
@@ -282,6 +288,7 @@ async function main() {
282288
shaPrereleaseContext,
283289
baseTagInput,
284290
npmPackageName,
291+
fallbackPackageName,
285292
)
286293

287294
log(`Base ref: ${baseRef}`)
@@ -313,16 +320,27 @@ async function main() {
313320
}
314321

315322
if (currentVersion.isPrerelease) {
316-
targets = await filterTargetsWithoutReleaseComments(targets, async (issueNumber) =>
317-
requestPaginated(token, `/repos/${owner}/${repo}/issues/${issueNumber}/comments`),
323+
targets = await filterTargetsWithoutReleaseComments(
324+
targets,
325+
currentPackageName,
326+
fallbackPackageName,
327+
async (issueNumber) =>
328+
requestPaginated(token, `/repos/${owner}/${repo}/issues/${issueNumber}/comments`),
318329
)
319330
if (!targets.length) {
320331
log('All prerelease targets already have release comments. Nothing to do.')
321332
return
322333
}
323334
}
324335

325-
const guardViolations = await checkGuardViolations(token, owner, repo, targets, currentVersion)
336+
const guardViolations = await checkGuardViolations(
337+
token,
338+
owner,
339+
repo,
340+
targets,
341+
currentVersion,
342+
fallbackPackageName,
343+
)
326344
if (guardViolations.length > 0) {
327345
const details = guardViolations
328346
.slice(0, 20)
@@ -371,6 +389,7 @@ async function main() {
371389
* @param {ShaPrereleaseContext | null} shaPrereleaseContext
372390
* @param {string} baseTagInput
373391
* @param {string} npmPackageName
392+
* @param {string} fallbackPackageName
374393
* @returns {Promise<CompareRefs>}
375394
*/
376395
async function resolveCompareRefs(
@@ -382,6 +401,7 @@ async function resolveCompareRefs(
382401
shaPrereleaseContext,
383402
baseTagInput,
384403
npmPackageName,
404+
fallbackPackageName,
385405
) {
386406
let baseRef = ''
387407
let headRef = currentTag
@@ -410,7 +430,7 @@ async function resolveCompareRefs(
410430
const releases = await requestPaginated(token, `/repos/${owner}/${repo}/releases`)
411431
/** @type {ReleaseRecord[]} */
412432
const publishedReleases = releases.filter((release) => !release.draft)
413-
baseRef = pickBaseTag(currentTag, currentVersion, publishedReleases, '')
433+
baseRef = pickBaseTag(currentTag, currentVersion, publishedReleases, '', fallbackPackageName)
414434
}
415435

416436
return { baseRef, headRef }
@@ -560,25 +580,38 @@ async function collectLinkedIssuesAndPrs(token, owner, repo, commits, skipLabels
560580
}
561581

562582
/**
563-
* Removes targets that already received any release-commenter comment.
583+
* Removes targets that already received a release-commenter comment for the same package.
564584
*
565585
* Prerelease runs can cover an overlapping compare range after a version bump because their
566586
* base is resolved from npm-published SHA prereleases. The first prerelease comment is the useful
567587
* signal for a PR or issue; later prerelease passes should keep moving without adding more noise.
588+
* Comments for other packages don't count: a PR touching two packages legitimately receives one
589+
* comment per package release.
568590
*
569591
* @param {number[]} targetNumbers
592+
* @param {string} currentPackageName
593+
* @param {string} fallbackPackageName
570594
* @param {(issueNumber: number) => Promise<IssueComment[]>} loadComments
571595
* @returns {Promise<number[]>}
572596
*/
573-
async function filterTargetsWithoutReleaseComments(targetNumbers, loadComments) {
597+
async function filterTargetsWithoutReleaseComments(
598+
targetNumbers,
599+
currentPackageName,
600+
fallbackPackageName,
601+
loadComments,
602+
) {
574603
/** @type {number[]} */
575604
const nextTargets = []
576605
/** @type {SkippedTarget[]} */
577606
const skippedTargets = []
578607

579608
for (const issueNumber of targetNumbers) {
580609
const comments = await loadComments(issueNumber)
581-
const existingReleaseComment = findReleaseComment(comments)
610+
const existingReleaseComment = findReleaseComment(
611+
comments,
612+
currentPackageName,
613+
fallbackPackageName,
614+
)
582615

583616
if (existingReleaseComment) {
584617
skippedTargets.push({
@@ -604,15 +637,23 @@ async function filterTargetsWithoutReleaseComments(targetNumbers, loadComments)
604637
}
605638

606639
/**
607-
* Finds the first release-commenter marker or legacy release URL in a list of comments.
640+
* Finds the first release-commenter marker or legacy release URL in a list of comments that belongs to the given package.
608641
*
609642
* @param {IssueComment[]} comments
643+
* @param {string} currentPackageName
644+
* @param {string} fallbackPackageName
610645
* @returns {ReleaseComment | null}
611646
*/
612-
function findReleaseComment(comments) {
647+
function findReleaseComment(comments, currentPackageName, fallbackPackageName) {
613648
for (const comment of comments) {
614649
const existingTag = extractReleaseTagFromComment(comment.body || '')
615-
if (!existingTag || !parseTag(existingTag)) continue
650+
if (!existingTag) continue
651+
652+
const existingVersion = parseTag(existingTag)
653+
if (!existingVersion) continue
654+
if (resolveTagPackageName(existingVersion, fallbackPackageName) !== currentPackageName) {
655+
continue
656+
}
616657

617658
return {
618659
tag: existingTag,
@@ -644,21 +685,31 @@ function formatSkippedTargetDetails(skippedTargets) {
644685
}
645686

646687
/**
647-
* Validates that targets do not already have release comments that would make this run unsafe.
688+
* Validates that targets do not already have release comments that would make this run unsafe. The guard is scoped to the current tag's package: comments left by another package's releases are expected on pull requests that touched both packages and never count as violations.
648689
*
649690
* @param {string} token
650691
* @param {string} owner
651692
* @param {string} repo
652693
* @param {number[]} targetNumbers
653694
* @param {ParsedTag} currentVersion
695+
* @param {string} fallbackPackageName
654696
* @returns {Promise<GuardViolation[]>}
655697
*/
656-
async function checkGuardViolations(token, owner, repo, targetNumbers, currentVersion) {
698+
async function checkGuardViolations(
699+
token,
700+
owner,
701+
repo,
702+
targetNumbers,
703+
currentVersion,
704+
fallbackPackageName,
705+
) {
657706
if (currentVersion.isPrerelease) {
658707
log('Current release is a prerelease, skipping stable-release duplicate guard')
659708
return []
660709
}
661710

711+
const currentPackageName = resolveTagPackageName(currentVersion, fallbackPackageName)
712+
662713
/** @type {GuardViolation[]} */
663714
const violations = []
664715

@@ -676,6 +727,11 @@ async function checkGuardViolations(token, owner, repo, targetNumbers, currentVe
676727

677728
const existingVersion = parseTag(existingTag)
678729
if (!existingVersion) continue
730+
if (
731+
resolveTagPackageName(existingVersion, fallbackPackageName) !== currentPackageName
732+
) {
733+
continue
734+
}
679735

680736
if (compareSemver(existingVersion, currentVersion) === 0) {
681737
violations.push({
@@ -851,22 +907,60 @@ function parseBooleanInput(rawValue) {
851907
}
852908

853909
/**
854-
* Parses a semver tag with optional `v` or `refs/tags/` prefixes.
910+
* @typedef {{
911+
* packageName: string | null
912+
* versionText: string
913+
* }} TagNameSplit
914+
*/
915+
916+
/**
917+
* Splits an optional package prefix off a tag and normalizes the version text. Monorepo release tags are `<package-name>@<version>` where the package name may itself be scoped (`@scope/name`), so the split happens at the last `@` past position 0; tags without a package prefix are the repo's pre-monorepo history and keep the legacy leading-`v` handling.
855918
*
856-
* @param {string | null | undefined} tag
857-
* @returns {ParsedTag | null}
919+
* @param {string} rawTag
920+
* @returns {TagNameSplit}
858921
*/
859-
function parseTag(tag) {
860-
if (!tag) return null
861-
let normalized = tag.trim()
922+
function splitTagPackageName(rawTag) {
923+
let normalized = rawTag.trim()
862924
if (normalized.startsWith('refs/tags/')) {
863925
normalized = normalized.slice('refs/tags/'.length)
864926
}
865-
if (normalized.startsWith('v')) {
866-
normalized = normalized.slice(1)
927+
928+
const separatorIndex = normalized.lastIndexOf('@')
929+
if (separatorIndex > 0) {
930+
return {
931+
packageName: normalized.slice(0, separatorIndex),
932+
versionText: normalized.slice(separatorIndex + 1),
933+
}
867934
}
868935

869-
const match = normalized.match(
936+
return {
937+
packageName: null,
938+
versionText: normalized.startsWith('v') ? normalized.slice(1) : normalized,
939+
}
940+
}
941+
942+
/**
943+
* Resolves which package a parsed tag belongs to. Tags without a package prefix (legacy `v*` and plain npm version strings) belong to the fallback package, so the pre-monorepo release history stays attached to it.
944+
*
945+
* @param {ParsedTag} version
946+
* @param {string} fallbackPackageName
947+
* @returns {string}
948+
*/
949+
function resolveTagPackageName(version, fallbackPackageName) {
950+
return version.packageName ?? fallbackPackageName
951+
}
952+
953+
/**
954+
* Parses a semver tag with an optional `<package-name>@` namespace prefix and optional legacy `v` or `refs/tags/` prefixes.
955+
*
956+
* @param {string | null | undefined} tag
957+
* @returns {ParsedTag | null}
958+
*/
959+
function parseTag(tag) {
960+
if (!tag) return null
961+
const { packageName, versionText } = splitTagPackageName(tag)
962+
963+
const match = versionText.match(
870964
/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+([0-9A-Za-z.-]+))?$/,
871965
)
872966
if (!match) return null
@@ -875,6 +969,7 @@ function parseTag(tag) {
875969
const prerelease = prereleaseRaw ? prereleaseRaw.split('.') : []
876970

877971
return {
972+
packageName,
878973
major: Number.parseInt(majorRaw, 10),
879974
minor: Number.parseInt(minorRaw, 10),
880975
patch: Number.parseInt(patchRaw, 10),
@@ -1227,20 +1322,13 @@ function npmRegistryPath(packageName) {
12271322
}
12281323

12291324
/**
1230-
* Converts a git-like tag string into an npm version string.
1325+
* Converts a git-like tag string into an npm version string, dropping any package namespace prefix.
12311326
*
12321327
* @param {string} tag
12331328
* @returns {string}
12341329
*/
12351330
function npmVersionFromTag(tag) {
1236-
let normalized = tag
1237-
if (normalized.startsWith('refs/tags/')) {
1238-
normalized = normalized.slice('refs/tags/'.length)
1239-
}
1240-
if (normalized.startsWith('v')) {
1241-
normalized = normalized.slice(1)
1242-
}
1243-
return normalized
1331+
return splitTagPackageName(tag).versionText
12441332
}
12451333

12461334
/**
@@ -1568,15 +1656,16 @@ async function getCurrentRelease(token, owner, repo, currentTag, payloadRelease)
15681656
}
15691657

15701658
/**
1571-
* Picks the most recent semver-compatible base tag for comparison.
1659+
* Picks the most recent semver-compatible base tag for comparison, considering only releases of the same package. Legacy un-prefixed tags count as the fallback package's releases, so the first namespaced release still finds the pre-monorepo history as its base. A brand-new package has no release history at all, so its very first release fails here by design — run the workflow manually with a base-tag input if comments are wanted for it.
15721660
*
15731661
* @param {string} currentTag
15741662
* @param {ParsedTag} currentVersion
15751663
* @param {ReleaseRecord[]} allReleases
15761664
* @param {string} manualBaseTag
1665+
* @param {string} fallbackPackageName
15771666
* @returns {string}
15781667
*/
1579-
function pickBaseTag(currentTag, currentVersion, allReleases, manualBaseTag) {
1668+
function pickBaseTag(currentTag, currentVersion, allReleases, manualBaseTag, fallbackPackageName) {
15801669
if (manualBaseTag) {
15811670
const parsedManualTag = parseTag(manualBaseTag)
15821671
if (!parsedManualTag) {
@@ -1585,11 +1674,14 @@ function pickBaseTag(currentTag, currentVersion, allReleases, manualBaseTag) {
15851674
return manualBaseTag
15861675
}
15871676

1677+
const currentPackageName = resolveTagPackageName(currentVersion, fallbackPackageName)
1678+
15881679
/** @type {Array<{tag: string, version: ParsedTag}>} */
15891680
const parsedReleases = []
15901681
for (const release of allReleases) {
15911682
const version = parseTag(release.tag_name)
15921683
if (!version) continue
1684+
if (resolveTagPackageName(version, fallbackPackageName) !== currentPackageName) continue
15931685
parsedReleases.push({ tag: release.tag_name, version })
15941686
}
15951687

@@ -1601,7 +1693,9 @@ function pickBaseTag(currentTag, currentVersion, allReleases, manualBaseTag) {
16011693

16021694
if (!candidates.length) {
16031695
const mode = currentVersion.isPrerelease ? 'all semver tags' : 'stable tags'
1604-
throw new Error(`Could not find previous release tag for ${currentTag} in ${mode}`)
1696+
throw new Error(
1697+
`Could not find previous release tag for ${currentTag} (package ${currentPackageName}) in ${mode}`,
1698+
)
16051699
}
16061700

16071701
return candidates[0].tag
@@ -1621,12 +1715,15 @@ function shouldSkipPr(skipLabels, prLabels) {
16211715

16221716
module.exports = {
16231717
__testing: {
1718+
checkGuardViolations,
16241719
compareCoreVersion,
16251720
filterTargetsWithoutReleaseComments,
16261721
findReleaseComment,
16271722
formatPostedCommentsSummary,
16281723
getIssueCommentUrl,
1724+
npmVersionFromTag,
16291725
parseTag,
1726+
pickBaseTag,
16301727
pickShaPrereleaseCandidatePool,
16311728
postCommentsAndLabels,
16321729
releaseCommentMarker,

0 commit comments

Comments
 (0)