Skip to content

Commit

Permalink
ci: prepare for major bump (#8240)
Browse files Browse the repository at this point in the history
* ci: prepare for major bump

Related prisma/prisma-private#147

* fix TS errors

* ci(publish.ts): revert undefined to null

* fix getSemverFromPatchBranch

* fix type error
  • Loading branch information
Jolg42 committed Aug 3, 2021
1 parent 9852edb commit 8b1cfa6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"setup": "ts-node scripts/setup.ts",
"build": "ts-node scripts/setup.ts --build",
"dry": "ts-node scripts/ci/publish.ts --dry-run",
"publish-all-dryrun": "ts-node scripts/ci/publish.ts --publish --dry-run",
"publish-all": "ts-node scripts/ci/publish.ts --publish",
"bump-engines": "ts-node scripts/bump-engines.ts",
"test": "ts-node scripts/ci/publish.ts --test",
Expand Down
66 changes: 28 additions & 38 deletions scripts/ci/publish.ts
Expand Up @@ -306,7 +306,7 @@ function zeroOutPatch(version: string): string {

/**
* Takes the max dev version + 1
* For now supporting 2.Y.Z-dev.#
* For now supporting X.Y.Z-dev.#
* @param packages Local package definitions
*/
async function getNewDevVersion(packages: Packages): Promise<string> {
Expand All @@ -329,7 +329,7 @@ async function getNewDevVersion(packages: Packages): Promise<string> {

/**
* Takes the max dev version + 1
* For now supporting 2.Y.Z-dev.#
* For now supporting X.Y.Z-dev.#
* @param packages Local package definitions
*/
async function getNewIntegrationVersion(
Expand Down Expand Up @@ -407,10 +407,10 @@ async function getNewPatchDevVersion(
packages: Packages,
patchBranch: string,
): Promise<string> {
const minor = getMinorFromPatchBranch(patchBranch)!
const { minor, major } = getSemverFromPatchBranch(patchBranch)!
const currentPatch = await getCurrentPatchForMinor(minor)
const newPatch = currentPatch + 1
const newVersion = `2.${minor}.${newPatch}`
const newVersion = `${major}.${minor}.${newPatch}`
const versions = [...(await getAllVersions(packages, 'dev', newVersion))]
const maxIncrement = getMaxPatchVersionIncrement(versions)

Expand Down Expand Up @@ -514,13 +514,17 @@ async function getNextMinorStable() {
return increaseMinor(remoteVersion)
}

// TODO: Adjust this for stable release
function getMinorFromPatchBranch(version: string): number | null {
const regex = /2\.(\d+)\.x/
function getSemverFromPatchBranch(
version: string,
): { major: number; minor: number } | null {
const regex = /(\d+)\.(\d+)\.x/
const match = regex.exec(version)

if (match) {
return Number(match[1])
return {
major: Number(match[0]),
minor: Number(match[1]),
}
}

return null
Expand All @@ -531,7 +535,7 @@ async function publish() {
'--publish': Boolean,
'--repo': String,
'--dry-run': Boolean,
'--release': String,
'--release': String, // TODO What does that do?
'--test': Boolean,
})

Expand Down Expand Up @@ -583,16 +587,13 @@ async function publish() {
)} is not a valid semver version.`,
)
}
const releaseRegex = /2\.\d{1,2}\.\d{1,2}/
if (
!args['--release'].startsWith('2.') ||
!releaseRegex.test(args['--release'])
) {
const releaseRegex = /\d{1,2}\.\d{1,2}\.\d{1,2}/
if (!releaseRegex.test(args['--release'])) {
throw new Error(
`New release version ${chalk.bold.underline(
args['--release'],
)} does not follow the stable naming scheme: ${chalk.bold.underline(
'2.x.y',
'x.y.z',
)}`,
)
}
Expand Down Expand Up @@ -632,10 +633,14 @@ async function publish() {
let tagForE2ECheck: undefined | string
const patchBranch = getPatchBranch()
const branch = await getPrismaBranch()

// For branches that are named "integration/" we publish to the integration npm tag
if (branch && branch.startsWith('integration/')) {
prisma2Version = await getNewIntegrationVersion(packages, branch)
tag = 'integration'
} else if (patchBranch) {
}
// Is it a patch branch? (Like 2.20.x)
else if (patchBranch) {
prisma2Version = await getNewPatchDevVersion(packages, patchBranch)
tag = 'patch-dev'
if (args['--release']) {
Expand Down Expand Up @@ -717,7 +722,6 @@ Check them out at https://github.com/prisma/e2e-tests/actions?query=workflow%3At
prisma2Version,
tag,
args['--release'],
patchBranch,
)
console.log(`Waiting 5 sec so you can check it out first...`)
await new Promise((r) => setTimeout(r, 5000))
Expand All @@ -731,7 +735,6 @@ Check them out at https://github.com/prisma/e2e-tests/actions?query=workflow%3At
prisma2Version,
tag,
args['--release'],
patchBranch,
)

const enginesCommit = await getEnginesCommit()
Expand Down Expand Up @@ -994,7 +997,6 @@ async function publishPackages(
prisma2Version: string,
tag: string,
releaseVersion?: string,
patchBranch?: string,
): Promise<void> {
// we need to release a new `prisma` CLI in all cases.
// if there is a change in prisma-client-js, it will also use this new version
Expand Down Expand Up @@ -1079,13 +1081,7 @@ async function publishPackages(

const pkgDir = path.dirname(pkg.path)

let newVersion = prisma2Version
if (
pkgName === '@prisma/engine-core' &&
process.env.BUILDKITE_TAG === '2.0.1'
) {
newVersion = '2.0.1-1'
}
const newVersion = prisma2Version

console.log(
`\nPublishing ${chalk.magentaBright(
Expand Down Expand Up @@ -1124,14 +1120,8 @@ async function publishPackages(
if (process.env.BUILDKITE) {
await run(pkgDir, `pnpm run build`, dryRun)
}
const skipPackages =
process.env.BUILDKITE_TAG === '2.0.1'
? [
'@prisma/debug',
'@prisma/generator-helper',
'@prisma/ink-components',
]
: []

const skipPackages: string[] = []
if (!skipPackages.includes(pkgName)) {
await run(pkgDir, `pnpm publish --no-git-checks --tag ${tag}`, dryRun)
}
Expand Down Expand Up @@ -1295,19 +1285,19 @@ async function areEndToEndTestsPassing(tag: string): Promise<boolean> {
return res.includes('passing')
}

function getPatchBranch(): string | undefined {
function getPatchBranch() {
if (process.env.PATCH_BRANCH) {
return process.env.PATCH_BRANCH
}

if (process.env.BUILDKITE_BRANCH) {
const minor = getMinorFromPatchBranch(process.env.BUILDKITE_BRANCH)
if (minor !== null) {
const versions = getSemverFromPatchBranch(process.env.BUILDKITE_BRANCH)
if (versions?.minor !== null) {
return process.env.BUILDKITE_BRANCH
}
}

return undefined
return null
}

type CommitInfo = {
Expand Down

0 comments on commit 8b1cfa6

Please sign in to comment.