Skip to content

Commit

Permalink
chore: publish to right tag with right version
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Jun 16, 2020
1 parent a6b2e96 commit 8bc7406
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"prisma": {
"version": "41f8d9863f1e0f6bfdb24def858e520f99bc2479",
"prismaCommit": "f3e006e1f72f38a3fe532755ac1a45e6b89bdb0a"
"prismaCommit": "a6b2e963b5eb83261175980594d2a3871044de1e"
},
"devDependencies": {
"@apexearth/copy": "1.4.5",
Expand Down
54 changes: 32 additions & 22 deletions src/scripts/ci/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import redis from 'redis'
import fetch from 'node-fetch'
import { promisify } from 'util'
import { cloneOrPull } from '../setup'
import { unique } from './unique'

export type Commit = {
date: Date
Expand Down Expand Up @@ -361,17 +362,20 @@ async function getNewPatchDevVersion(
const minor = getMinorFromPatchBranch(patchBranch)
const currentPatch = await getCurrentPatchForMinor(minor)
const newPatch = currentPatch + 1
const newVersion = `2.${minor}.${newPatch}`
const versions = [
...(await getAllVersions(packages, 'patch-dev', `2.${minor}.${newPatch}`)),
...(await getAllVersions(packages, 'patch-beta', `2.${minor}.${newPatch}`)), // TODO: remove this
...(await getAllVersions(packages, 'patch-dev', newVersion)),
...(await getAllVersions(packages, 'patch-beta', newVersion)), // TODO: remove this
]
const maxIncrement = getMaxPatchVersionIncrement(versions)
console.log({ versions, maxIncrement })

return `2.${minor}.${newPatch}-dev.${maxIncrement + 1}`
return `${newVersion}-dev.${maxIncrement + 1}`
}

function getDevVersionIncrements(versions: string[]): number[] {
const regex = /2\.\d+\.\d+-dev\.(\d+)/
console.log({ versionss: versions })
return versions
.filter((v) => v.trim().length > 0)
.map((v) => {
Expand All @@ -386,7 +390,7 @@ function getDevVersionIncrements(versions: string[]): number[] {

// TODO: Adjust this for stable releases
function getMaxPatchVersionIncrement(versions: string[]): number {
const regex = /2\.\d+\.x-dev\.(\d+)/
const regex = /2\.\d+\.\d+-dev\.(\d+)/
const increments = versions
.filter((v) => v.trim().length > 0)
.map((v) => {
Expand All @@ -406,24 +410,30 @@ async function getAllVersions(
channel: string,
prefix: string,
): Promise<string[]> {
return flatten(
await Promise.all(
Object.values(packages).map(async (pkg) => {
const pkgVersions = [pkg.version]
const remoteVersion = await runResult(
'.',
`npm info ${pkg.name}@${channel} version`,
)
if (
remoteVersion &&
remoteVersion.length > 0 &&
remoteVersion.startsWith(prefix)
) {
pkgVersions.push(remoteVersion)
}

return pkgVersions
}),
return unique(
flatten(
await Promise.all(
Object.values(packages).map(async (pkg) => {
const pkgVersions = []
if (pkg.version.startsWith(prefix)) {
pkgVersions.push(pkg.version)
}
const remoteVersion = await runResult(
'.',
`npm info ${pkg.name}@${channel} version`,
)
if (
remoteVersion &&
remoteVersion.length > 0 &&
remoteVersion.startsWith(prefix) &&
!pkgVersions.includes(remoteVersion)
) {
pkgVersions.push(remoteVersion)
}

return pkgVersions
}),
),
),
)
}
Expand Down
21 changes: 21 additions & 0 deletions src/scripts/ci/unique.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Returns unique elements of array
* @param arr Array
*/

export function unique<T>(arr: T[]): T[] {
const { length } = arr
const result: T[] = []
const seen = new Set() // just a cache

loop: for (let i = 0; i < length; i++) {
const value = arr[i]
if (seen.has(value)) {
continue loop
}
seen.add(value)
result.push(value)
}

return result
}

0 comments on commit 8bc7406

Please sign in to comment.