Skip to content

Commit 7a9d2d0

Browse files
chore: add v4 branch to release scripts (#6247)
1 parent 0938492 commit 7a9d2d0

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- 'alpha'
1313
- 'beta'
1414
- 'rc'
15+
- 'v4'
1516

1617
concurrency:
1718
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
@@ -23,7 +24,7 @@ env:
2324

2425
jobs:
2526
test-and-publish:
26-
if: github.repository == 'TanStack/query' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/rc')
27+
if: github.repository == 'TanStack/query'
2728
name: 'Test & Publish'
2829
runs-on: ubuntu-latest
2930
steps:

scripts/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ export const branchConfigs = {
120120
rc: {
121121
prerelease: true,
122122
},
123+
v4: {
124+
prerelease: false,
125+
previousVersion: true,
126+
},
123127
}
124128

125129
const __dirname = fileURLToPath(new URL('.', import.meta.url))

scripts/publish.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ async function run() {
2121
const branchName = /** @type {string} */ (
2222
process.env.BRANCH ?? currentGitBranch()
2323
)
24+
/** @type {import('./types.js').BranchConfig | undefined} */
25+
const branchConfig = branchConfigs[branchName]
2426

2527
const isMainBranch = branchName === 'main'
28+
const isPreviousRelease = branchConfig?.previousVersion
2629
const npmTag = isMainBranch ? 'latest' : branchName
2730

2831
// Get tags
@@ -33,6 +36,10 @@ async function run() {
3336
tags = tags
3437
.filter((tag) => semver.valid(tag))
3538
.filter((tag) => {
39+
// If this is an older release, filter to only include that version
40+
if (isPreviousRelease) {
41+
return tag.startsWith(branchName)
42+
}
3643
if (semver.prerelease(tag) === null) {
3744
return isMainBranch
3845
} else {
@@ -300,9 +307,6 @@ async function run() {
300307
recommendedReleaseLevel = 0
301308
}
302309

303-
/** @type {import('./types.js').BranchConfig | undefined} */
304-
const branchConfig = branchConfigs[branchName]
305-
306310
if (!branchConfig) {
307311
console.log(`No publish config found for branch: ${branchName}`)
308312
console.log('Exiting...')
@@ -374,15 +378,15 @@ async function run() {
374378
}
375379

376380
console.info()
377-
console.info(`Publishing all packages to npm with tag "${npmTag}"`)
381+
console.info(`Publishing all packages to npm`)
378382

379383
// Publish each package
380384
changedPackages.forEach((pkg) => {
381385
const packageDir = path.join(rootDir, pkg.packageDir)
382-
const cmd = `cd ${packageDir} && pnpm publish --tag ${npmTag} --access=public --no-git-checks`
383-
console.info(
384-
` Publishing ${pkg.name}@${version} to npm with tag "${npmTag}"...`,
385-
)
386+
const tagParam = branchConfig.previousVersion ? `` : `--tag ${npmTag}`
387+
388+
const cmd = `cd ${packageDir} && pnpm publish ${tagParam} --access=public --no-git-checks`
389+
console.info(` Publishing ${pkg.name}@${version} to npm "${tagParam}"...`)
386390
execSync(cmd, {
387391
stdio: [process.stdin, process.stdout, process.stderr],
388392
})
@@ -412,7 +416,7 @@ async function run() {
412416
// Stringify the markdown to excape any quotes
413417
execSync(
414418
`gh release create v${version} ${
415-
!isMainBranch ? '--prerelease' : ''
419+
branchConfig.prerelease ? '--prerelease' : ''
416420
} --notes '${changelogMd.replace(/'/g, '"')}'`,
417421
)
418422
console.info(` Github release created.`)

scripts/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ export type Package = {
4444

4545
export type BranchConfig = {
4646
prerelease: boolean
47+
previousVersion?: boolean
4748
}

0 commit comments

Comments
 (0)