-
Notifications
You must be signed in to change notification settings - Fork 6
/
deploy-checks
executable file
·76 lines (59 loc) · 1.85 KB
/
deploy-checks
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
console.log('Checking deploy prerequisites...')
console.log('')
const { execSync } = require('child_process')
const version = require('./package.json')
.version.toString()
.replace(/[^a-zA-Z0-9.-]/g, '')
const { readFileSync } = require('fs')
process.chdir(__dirname)
function run(cmd) {
return execSync(cmd)
.toString()
.trim()
}
// Check for uncommitted changes
const uncommittedChanges = run('git status --porcelain')
if (uncommittedChanges.length > 0) {
console.error('ERROR: Project has uncommitted changes.')
process.exit(1)
}
// Check remote history
const remoteChanges = run("git rev-list --count --left-only '@{u}...HEAD'")
if (remoteChanges !== '0') {
console.error('ERROR: Remote has unmerged changes.')
process.exit(1)
}
// Check changelog
const readmeContents = readFileSync('CHANGELOG.md', 'utf8')
const changelogPattern = new RegExp(
`^## \\[${version.replace(/\./g, '\\.')}\\] - `,
'm'
)
if (!changelogPattern.test(readmeContents)) {
console.error(`ERROR: No changelog entry was created for version ${version}.`)
process.exit(1)
}
// Check for version bump
const changedFiles = run('git diff-tree --no-commit-id --name-only -r HEAD')
let versionBump = false
if (/^package\.json$/m.test(changedFiles)) {
const latestPackageJsonChanges = run('git diff HEAD^ HEAD package.json')
if (
/^-\s*"version": "[0-9a-zA-Z.-]+",?$/m.test(latestPackageJsonChanges) &&
/^\+\s*"version": "[0-9a-zA-Z.-]+",?$/m.test(latestPackageJsonChanges)
) {
versionBump = true
}
}
if (!versionBump) {
console.error('ERROR: Latest commit does not contain a version bump.')
process.exit(1)
}
// Check for tag
const hasTag = run('git tag -l ' + version)
if (hasTag.length === 0) {
console.error(`ERROR: git tag with current version ${version} is not set.`)
process.exit(1)
}
console.log('All good, continue to deploy.')