Skip to content

Commit

Permalink
chore: add v4 branch to release scripts (#6247)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianOsipiuk authored Oct 26, 2023
1 parent 0938492 commit 7a9d2d0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'alpha'
- 'beta'
- 'rc'
- 'v4'

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

jobs:
test-and-publish:
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')
if: github.repository == 'TanStack/query'
name: 'Test & Publish'
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export const branchConfigs = {
rc: {
prerelease: true,
},
v4: {
prerelease: false,
previousVersion: true,
},
}

const __dirname = fileURLToPath(new URL('.', import.meta.url))
Expand Down
22 changes: 13 additions & 9 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ async function run() {
const branchName = /** @type {string} */ (
process.env.BRANCH ?? currentGitBranch()
)
/** @type {import('./types.js').BranchConfig | undefined} */
const branchConfig = branchConfigs[branchName]

const isMainBranch = branchName === 'main'
const isPreviousRelease = branchConfig?.previousVersion
const npmTag = isMainBranch ? 'latest' : branchName

// Get tags
Expand All @@ -33,6 +36,10 @@ async function run() {
tags = tags
.filter((tag) => semver.valid(tag))
.filter((tag) => {
// If this is an older release, filter to only include that version
if (isPreviousRelease) {
return tag.startsWith(branchName)
}
if (semver.prerelease(tag) === null) {
return isMainBranch
} else {
Expand Down Expand Up @@ -300,9 +307,6 @@ async function run() {
recommendedReleaseLevel = 0
}

/** @type {import('./types.js').BranchConfig | undefined} */
const branchConfig = branchConfigs[branchName]

if (!branchConfig) {
console.log(`No publish config found for branch: ${branchName}`)
console.log('Exiting...')
Expand Down Expand Up @@ -374,15 +378,15 @@ async function run() {
}

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

// Publish each package
changedPackages.forEach((pkg) => {
const packageDir = path.join(rootDir, pkg.packageDir)
const cmd = `cd ${packageDir} && pnpm publish --tag ${npmTag} --access=public --no-git-checks`
console.info(
` Publishing ${pkg.name}@${version} to npm with tag "${npmTag}"...`,
)
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}"...`)
execSync(cmd, {
stdio: [process.stdin, process.stdout, process.stderr],
})
Expand Down Expand Up @@ -412,7 +416,7 @@ async function run() {
// Stringify the markdown to excape any quotes
execSync(
`gh release create v${version} ${
!isMainBranch ? '--prerelease' : ''
branchConfig.prerelease ? '--prerelease' : ''
} --notes '${changelogMd.replace(/'/g, '"')}'`,
)
console.info(` Github release created.`)
Expand Down
1 change: 1 addition & 0 deletions scripts/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export type Package = {

export type BranchConfig = {
prerelease: boolean
previousVersion?: boolean
}

0 comments on commit 7a9d2d0

Please sign in to comment.