Skip to content

Commit

Permalink
meta: fix release process (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 9, 2022
1 parent 2be8cec commit 3974905
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions private/release/commit-and-open-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ import { fileURLToPath } from 'node:url'
import prompts from 'prompts'
import { REPO_NAME, REPO_OWNER } from './config.js'

function runProcessOrThrow (...args) {
const cp = spawnSync(...args)

if (cp.status) {
console.log(cp.stdout.toString())
console.error(cp.stderr.toString())
throw new Error(`Non-zero status: ${cp.status}. ${args}`)
}

return cp
}

function getContentFromProcessSync (...args) {
return runProcessOrThrow(...args).stdout.toString().trim()
}

export default async function commit (spawnOptions, STABLE_HEAD, ...files) {
console.log(`Now is the time to do manual edits to ${files.join(',')}.`)
await prompts({
Expand All @@ -15,9 +31,12 @@ export default async function commit (spawnOptions, STABLE_HEAD, ...files) {
})

spawnSync('git', ['add', ...files.map(url => fileURLToPath(url))], spawnOptions)
const remoteHeadSha = spawnSync('git', ['rev-parse', 'HEAD'], spawnOptions).stdout.toString().trim()
spawnSync('git', ['commit', '-n', '-m', 'Prepare next release'], { ...spawnOptions, stdio: 'inherit' })
const releaseSha = spawnSync('git', ['rev-parse', 'HEAD'], spawnOptions).stdout.toString().trim()

// Reverting to the remote head before starting the merge. We keep the git sha
// in a variable to cherry-pick it later.
const releaseSha = getContentFromProcessSync('git', ['rev-parse', 'HEAD'], spawnOptions)
runProcessOrThrow('git', ['reset', 'HEAD^', '--hard'])

console.log('Attempting to merge changes from stable branch...')
{
Expand Down Expand Up @@ -61,12 +80,9 @@ export default async function commit (spawnOptions, STABLE_HEAD, ...files) {
}
}
}
const mergeSha = spawnSync('git', ['rev-parse', 'HEAD'], spawnOptions).stdout.toString().trim()

spawnSync('git', ['reset', remoteHeadSha, '--hard'], spawnOptions)
spawnSync('git', ['cherry-pick', mergeSha, '--hard'], spawnOptions)
spawnSync('git', ['cherry-pick', releaseSha, '--hard'], spawnOptions)
const sha = spawnSync('git', ['rev-parse', 'HEAD'], spawnOptions).stdout.toString().trim()
runProcessOrThrow('git', ['cherry-pick', releaseSha], spawnOptions)
const sha = getContentFromProcessSync('git', ['rev-parse', 'HEAD'], spawnOptions)

const getRemoteCommamnd = `git remote -v | grep '${REPO_OWNER}/${REPO_NAME}' | awk '($3 == "(push)") { print $1; exit }'`
const remote = spawnSync('/bin/sh', ['-c', getRemoteCommamnd]).stdout.toString().trim()
Expand Down

0 comments on commit 3974905

Please sign in to comment.