/
homebrew.js
56 lines (45 loc) · 1.47 KB
/
homebrew.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const execa = require('execa')
const mkdirp = require('mkdirp')
const path = require('path')
const rm = require('rimraf')
const {ROLLBACK_VERSION, SKIP_GIT_PUSH} = process.env
async function setupGit() {
const githubSetupPath = path.join(__dirname, '..', 'utils', '_github_setup')
await execa(githubSetupPath)
}
async function rollbackHomebrew() {
const tmp = path.join(__dirname, 'tmp')
const homebrewDir = path.join(tmp, 'homebrew-brew')
mkdirp.sync(tmp)
rm.sync(homebrewDir)
await setupGit()
console.log(`cloning https://github.com/heroku/homebrew-brew to ${homebrewDir}`)
await execa('git',
[
'clone',
'git@github.com:heroku/homebrew-brew.git',
homebrewDir,
],
)
console.log(`done cloning heroku/homebrew-brew to ${homebrewDir}`)
// run in git in cloned heroku/homebrew-brew git directory
const git = async (args, opts = {}) => {
await execa('git', ['-C', homebrewDir, ...args], opts)
}
console.log('updating local git...')
// get commit to revert
const commitToRevert = await git(['log', `--grep=v${ROLLBACK_VERSION}`])
if (commitToRevert.contains('revert')) {
console.log(`${ROLLBACK_VERSION} has already been reverted`)
process.exit(1)
}
// revert commit
await git(['revert', commitToRevert])
if (SKIP_GIT_PUSH === undefined) {
await git(['push', 'origin', 'main'])
}
}
rollbackHomebrew().catch(error => {
console.error('error running scripts/release/homebrew.js', error)
process.exit(1)
})