-
Notifications
You must be signed in to change notification settings - Fork 72
/
upload.js
executable file
·51 lines (39 loc) · 1.62 KB
/
upload.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
#!/usr/bin/env node
'use strict'
const exec = require('child_process').execSync
const fs = require('fs')
const config = require('./lib/config')
const info = require('./ci-services')()
const hasLockfileCommit = require('./lib/git-helpers').hasLockfileCommit
module.exports = function upload () {
if (!info.branchName) {
return console.error('No branch details set, so assuming not a Greenkeeper branch')
}
// legacy support
if (config.branchPrefix === 'greenkeeper/' && info.branchName.startsWith('greenkeeper-')) {
config.branchPrefix = 'greenkeeper-'
}
if (!info.branchName.startsWith(config.branchPrefix)) {
return console.error(`'${info.branchName}' is not a Greenkeeper branch`)
}
const isInitial = info.branchName === (config.branchPrefix + 'initial') ||
info.branchName === (config.branchPrefix + 'update-all')
if (isInitial) {
return console.error('Not running on the initial Greenkeeper branch. Will only run on Greenkeeper branches that update a specific dependency')
}
if (!info.uploadBuild) {
return console.error('Only uploading on one build job')
}
if (hasLockfileCommit(info)) { // Note: this has a side-effect that is required for the exec('git push') below
return console.error('greenkeeper-lockfile already has a commit on this branch')
}
const err = fs.openSync('gk-lockfile-git-push.err', 'w')
exec(`git push${process.env.GK_LOCK_COMMIT_AMEND ? ` --force-with-lease=${info.branchName}:origin/${info.branchName}` : ''} gk-origin HEAD:${info.branchName}`, {
stdio: [
'pipe',
'pipe',
err
]
})
}
if (require.main === module) module.exports()