-
Notifications
You must be signed in to change notification settings - Fork 2
/
release-checks.js
58 lines (49 loc) · 1.35 KB
/
release-checks.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
57
58
'use strict'
// Release checks inspired by np
// https://github.com/sindresorhus/np/blob/master/source/git-util.js
const execa = require('execa')
function init() {
verifyCurrentBranchIsMaster()
verifyWorkingTreeIsClean()
verifyRemoteHistoryIsClean()
verifyCommitsPushedUpstream()
console.log('Release checks passed.')
}
function run(command) {
return execa.commandSync(command)
}
function verifyCommitsPushedUpstream() {
const { stdout: cherry } = run('git cherry')
if (cherry) {
throw new Error(
'Remote history is behind. Push commits upstream before releasing.'
)
}
}
function verifyCurrentBranchIsMaster() {
const { stdout: branch } = run('git symbolic-ref --short HEAD')
if (branch !== 'master') {
throw new Error(
'Not on the master branch. Move to the master branch first before releasing.'
)
}
}
function verifyRemoteHistoryIsClean() {
const { stdout: historyCount } = run(
'git rev-list --count --left-only @{u}...HEAD'
)
if (historyCount !== '0') {
throw new Error(
'Remote history is ahead. Pull changes from remote before releasing.'
)
}
}
function verifyWorkingTreeIsClean() {
const { stdout: status } = run('git status --porcelain')
if (status) {
throw new Error(
'Working tree has uncommitted changes. Commit or remove changes before releasing.'
)
}
}
init()