-
Notifications
You must be signed in to change notification settings - Fork 73
/
upload.js
executable file
·65 lines (49 loc) · 1.78 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
'use strict'
const exec = require('child_process').execSync
const url = require('url')
const fs = require('fs')
const config = require('./lib/config')
const info = require('./ci-services')()
const env = process.env
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.firstPush) {
return console.error('Only running on first push of a new branch')
}
if (!info.uploadBuild) {
return console.error('Only uploading on one build job')
}
let remote = `git@github.com:${info.repoSlug}`
if (info.gitUrl) remote = info.gitUrl
if (env.GH_TOKEN) {
if (remote.slice(0, 5) !== 'https') remote = `https://github.com/${info.repoSlug}`
const urlParsed = url.parse(remote)
urlParsed.auth = env.GH_TOKEN
remote = url.format(urlParsed)
}
const err = fs.openSync('gk-lockfile-git-push.err', 'w')
exec(`git remote add gk-origin ${remote} || git remote set-url gk-origin ${remote}`)
exec(`git push gk-origin HEAD:${info.branchName}`, {
stdio: [
'pipe',
'pipe',
err
]
})
}
if (require.main === module) module.exports()