Skip to content

Commit

Permalink
ci: UPDATE_STUDIO should commit changes - fix git push [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Apr 28, 2020
1 parent 47e5f46 commit d692219
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/scripts/ci/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,32 @@ async function commitChanges(
await run(dir, `git commit -am "${message}"`, dry)
}

async function push(dir: string, dry = false): Promise<void> {
async function pull(dir: string, dry = false): Promise<void> {
const branch = await getBranch(dir)
if (process.env.BUILDKITE) {
if (!process.env.GITHUB_TOKEN) {
throw new Error(`Missing env var GITHUB_TOKEN`)
}
const remotes = (await runResult(dir, `git remote`)).trim().split('\n')
if (!remotes.includes('origin-push')) {
await run(
dir,
`git remote add origin-push https://${process.env.GITHUB_TOKEN}@github.com/prisma/${dir}.git`,
dry,
)
await run(
dir,
`git remote set-url origin https://${process.env.GITHUB_TOKEN}@github.com/prisma/prisma.git`,
dry,
)
}
await run(dir, `git pull origin ${branch} --no-edit`)
}

async function push(dir: string, dry = false): Promise<void> {
const branch = await getBranch(dir)
if (process.env.BUILDKITE) {
if (!process.env.GITHUB_TOKEN) {
throw new Error(`Missing env var GITHUB_TOKEN`)
}
await run(
dir,
`git remote set-url origin https://${process.env.GITHUB_TOKEN}@github.com/prisma/prisma.git`,
dry,
)
await run(dir, `git push --quiet --set-upstream origin-push ${branch}`, dry)
} else {
await run(dir, `git push origin ${branch}`, dry)
Expand Down Expand Up @@ -784,12 +796,7 @@ async function publishPackages(
const repo = '.'
// commit and push it :)
// we try catch this, as this is not necessary for CI to succeed
await run(
repo,
`git remote set-url origin https://${process.env.GITHUB_TOKEN}@github.com/prisma/prisma.git`,
dryRun,
)
await run(repo, `git pull origin master --no-edit`)
await pull(repo, dryRun)
try {
const unsavedChanges = await getUnsavedChanges(repo)
if (!unsavedChanges) {
Expand Down

0 comments on commit d692219

Please sign in to comment.