Skip to content

chore: Fix incorrect npm tag for previous version release (v4) #6659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2024
Merged
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
30 changes: 12 additions & 18 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import type { PackageJson } from 'type-fest'
const releaseCommitMsg = (version: string) => `release: v${version}`

async function run() {
const branchName: string =
process.env.BRANCH ??
// (process.env.PR_NUMBER ? `pr-${process.env.PR_NUMBER}` : currentGitBranch())
currentGitBranch()
const branchConfig: BranchConfig | undefined = branchConfigs[branchName]

const branchName: string = process.env.BRANCH ?? currentGitBranch()
const isMainBranch = branchName === 'main'
const isPreviousRelease = branchConfig?.previousVersion
const npmTag = isMainBranch ? 'latest' : branchName

const branchConfig: BranchConfig | undefined = branchConfigs[branchName]

if (!branchConfig) {
throw new Error(`No publish config found for branch: ${branchName}`)
}

// Get tags
let tags: string[] = execSync('git tag').toString().split('\n')

Expand All @@ -36,7 +36,7 @@ async function run() {
.filter((tag) => semver.valid(tag))
.filter((tag) => {
// If this is an older release, filter to only include that version
if (isPreviousRelease) {
if (branchConfig.previousVersion) {
return tag.startsWith(branchName)
}
if (semver.prerelease(tag) === null) {
Expand Down Expand Up @@ -292,12 +292,6 @@ async function run() {
recommendedReleaseLevel = 0
}

if (!branchConfig) {
console.log(`No publish config found for branch: ${branchName}`)
console.log('Exiting...')
process.exit(0)
}

const releaseType = branchConfig.prerelease
? 'prerelease'
: ({ 0: 'patch', 1: 'minor', 2: 'major' } as const)[recommendedReleaseLevel]
Expand Down Expand Up @@ -371,14 +365,14 @@ async function run() {
}

console.info()
console.info(`Publishing all packages to npm`)
console.info(`Publishing all packages to npm with tag "${npmTag}"`)

// Publish each package
changedPackages.forEach((pkg) => {
const packageDir = path.join(rootDir, 'packages', pkg.packageDir)
const tagParam = branchConfig.previousVersion ? `` : `--tag ${npmTag}`
const cmd = `cd ${packageDir} && pnpm publish ${tagParam} --access=public --no-git-checks`
console.info(` Publishing ${pkg.name}@${version} to npm "${tagParam}"...`)

const cmd = `cd ${packageDir} && pnpm publish --tag ${npmTag} --access=public --no-git-checks`
console.info(` Publishing ${pkg.name}@${version} to npm...`)
execSync(cmd, {
stdio: [process.stdin, process.stdout, process.stderr],
})
Expand Down