Skip to content

Commit

Permalink
fix(ci): UPDATE_STUDIO should commit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Apr 28, 2020
1 parent 2809a74 commit 2255f6f
Showing 1 changed file with 33 additions and 63 deletions.
96 changes: 33 additions & 63 deletions src/scripts/ci/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ async function getLatestCommit(dir: string): Promise<Commit> {

async function commitChanges(
dir: string,
messages: string[],
message: string,
dry = false,
): Promise<void> {
await run(
dir,
`git commit -a ${messages.map((m) => `-m "${m}"`).join(' ')}`,
dry,
)
await run(dir, `git commit -am "${message}"`, dry)
}

async function push(dir: string, dry = false): Promise<void> {
Expand Down Expand Up @@ -296,29 +292,6 @@ async function getNewPackageVersions(
)
}

function getCommitMessages(dir: string, packages: Packages): string[] {
const messages = Object.values(packages)
.sort((a, b) => {
if (['@prisma/client', 'prisma'].includes(a.name)) {
return -1
}

if (['@prisma/client', 'prisma'].includes(b.name)) {
return 1
}

return a.name < b.name ? -1 : 1
})
.filter((p) => p.path.startsWith(dir))
.map((p) => `${p.name}@${p.version}`)

if (messages.length > 0) {
messages[messages.length - 1] += ' [skip ci]'
}

return messages
}

export function getPublishOrder(packages: Packages): string[][] {
const dag: { [pkg: string]: string[] } = Object.values(packages).reduce(
(acc, curr) => {
Expand Down Expand Up @@ -810,41 +783,38 @@ async function publishPackages(
if (!process.env.BUILDKITE || process.env.UPDATE_STUDIO) {
const repo = '.'
// commit and push it :)
const messages = await getCommitMessages(repo, changedPackages)
if (messages.length > 0) {
// we try catch this, as this is not necessary for CI to succeed
await run(repo, `git pull origin master --no-edit`)
try {
const unsavedChanges = await getUnsavedChanges(repo)
if (!unsavedChanges) {
console.log(
`\n${chalk.bold(
'Skipping',
)} commiting changes, as they're already commited`,
)
} else {
console.log(`\nCommiting changes`)
await commitChanges(repo, messages, dryRun)
}
const unpushedCommitCount = await getUnpushedCommitCount(repo)
if (unpushedCommitCount === 0) {
console.log(
`${chalk.bold(
'Skipping',
)} pushing commits, as they're already pushed`,
)
} else {
console.log(
`There are ${unpushedCommitCount} unpushed local commits in ${chalk.cyanBright(
`./`,
)}`,
)
await push(repo, dryRun)
}
} catch (e) {
console.error(e)
console.error(`Ignoring this error, continuing`)
// we try catch this, as this is not necessary for CI to succeed
await run(repo, `git pull origin master --no-edit`)
try {
const unsavedChanges = await getUnsavedChanges(repo)
if (!unsavedChanges) {
console.log(
`\n${chalk.bold(
'Skipping',
)} commiting changes, as they're already commited`,
)
} else {
console.log(`\nCommiting changes`)
await commitChanges(repo, 'Bump Studio [skip ci]', dryRun)
}
const unpushedCommitCount = await getUnpushedCommitCount(repo)
if (unpushedCommitCount === 0) {
console.log(
`${chalk.bold(
'Skipping',
)} pushing commits, as they're already pushed`,
)
} else {
console.log(
`There are ${unpushedCommitCount} unpushed local commits in ${chalk.cyanBright(
`./`,
)}`,
)
await push(repo, dryRun)
}
} catch (e) {
console.error(e)
console.error(`Ignoring this error, continuing`)
}
}
}
Expand Down

0 comments on commit 2255f6f

Please sign in to comment.