Skip to content

Commit

Permalink
chore: fix publish script for v4
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianOsipiuk committed Oct 25, 2023
1 parent 01436d4 commit acc8ac8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export const packages: Package[] = [
},
]

export const latestBranch = 'main'

export const branchConfigs: Record<string, BranchConfig> = {
main: {
prerelease: false,
Expand All @@ -95,6 +93,10 @@ export const branchConfigs: Record<string, BranchConfig> = {
rc: {
prerelease: true,
},
v4: {
prerelease: false,
previousVersion: true,
},
}

export const rootDir = path.resolve(__dirname, '..')
14 changes: 9 additions & 5 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import log from 'git-log-parser'
import streamToArray from 'stream-to-array'
import axios from 'axios'
import { DateTime } from 'luxon'
import { branchConfigs, latestBranch, packages, rootDir } from './config'
import type { BranchConfig, Commit, Package } from './types'
import { branchConfigs, packages, rootDir } from './config'
import type { BranchConfig, Commit } from './types'

import type { PackageJson } from 'type-fest'

Expand All @@ -22,8 +22,10 @@ async function run() {
process.env.BRANCH ??
// (process.env.PR_NUMBER ? `pr-${process.env.PR_NUMBER}` : currentGitBranch())
currentGitBranch()
const branchConfig: BranchConfig | undefined = branchConfigs[branchName]

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

// Get tags
Expand All @@ -33,6 +35,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 @@ -286,8 +292,6 @@ async function run() {
recommendedReleaseLevel = 0
}

const branchConfig: BranchConfig | undefined = branchConfigs[branchName]

if (!branchConfig) {
console.log(`No publish config found for branch: ${branchName}`)
console.log('Exiting...')
Expand Down Expand Up @@ -405,7 +409,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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ export type Package = {

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

0 comments on commit acc8ac8

Please sign in to comment.