2018-07-19 18:48:13 +00:00
|
|
|
if (!process.env.CI) require('dotenv-safe').load()
|
2018-07-11 18:02:03 +00:00
|
|
|
|
2017-09-23 21:26:04 +00:00
|
|
|
const GitHub = require('github')
|
|
|
|
const github = new GitHub()
|
2018-09-13 16:10:51 +00:00
|
|
|
github.authenticate({ type: 'token', token: process.env.ELECTRON_GITHUB_TOKEN })
|
2017-09-23 21:26:04 +00:00
|
|
|
|
2018-08-16 15:57:12 +00:00
|
|
|
if (process.argv.length < 6) {
|
2017-10-05 20:31:54 +00:00
|
|
|
console.log('Usage: upload-to-github filePath fileName releaseId')
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2018-10-02 01:56:31 +00:00
|
|
|
const filePath = process.argv[2]
|
|
|
|
const fileName = process.argv[3]
|
|
|
|
const releaseId = process.argv[4]
|
|
|
|
const releaseVersion = process.argv[5]
|
2018-08-16 15:57:12 +00:00
|
|
|
|
|
|
|
const targetRepo = releaseVersion.indexOf('nightly') > 0 ? 'nightlies' : 'electron'
|
2017-09-23 21:26:04 +00:00
|
|
|
|
2018-10-02 01:56:31 +00:00
|
|
|
const githubOpts = {
|
2017-09-23 21:26:04 +00:00
|
|
|
owner: 'electron',
|
2018-08-16 15:57:12 +00:00
|
|
|
repo: targetRepo,
|
2017-09-23 21:26:04 +00:00
|
|
|
id: releaseId,
|
|
|
|
filePath: filePath,
|
|
|
|
name: fileName
|
|
|
|
}
|
2017-10-04 14:33:27 +00:00
|
|
|
|
2017-10-05 20:31:54 +00:00
|
|
|
let retry = 0
|
2017-10-04 14:33:27 +00:00
|
|
|
|
|
|
|
function uploadToGitHub () {
|
|
|
|
github.repos.uploadAsset(githubOpts).then(() => {
|
2017-10-05 20:31:54 +00:00
|
|
|
console.log(`Successfully uploaded ${fileName} to GitHub.`)
|
2017-10-04 14:33:27 +00:00
|
|
|
process.exit()
|
|
|
|
}).catch((err) => {
|
2017-10-05 20:31:54 +00:00
|
|
|
if (retry < 4) {
|
2017-10-04 14:33:27 +00:00
|
|
|
console.log(`Error uploading ${fileName} to GitHub, will retry. Error was:`, err)
|
2017-10-05 20:31:54 +00:00
|
|
|
retry++
|
2017-10-23 15:02:50 +00:00
|
|
|
github.repos.getRelease(githubOpts).then(release => {
|
2019-01-04 21:14:41 +00:00
|
|
|
console.log('Got list of assets for existing release:')
|
|
|
|
console.log(JSON.stringify(release.data.assets, null, ' '))
|
2018-10-02 01:56:31 +00:00
|
|
|
const existingAssets = release.data.assets.filter(asset => asset.name === fileName)
|
2017-10-18 20:49:32 +00:00
|
|
|
if (existingAssets.length > 0) {
|
|
|
|
console.log(`${fileName} already exists; will delete before retrying upload.`)
|
|
|
|
github.repos.deleteAsset({
|
|
|
|
owner: 'electron',
|
2018-08-16 15:57:12 +00:00
|
|
|
repo: targetRepo,
|
2017-10-18 20:49:32 +00:00
|
|
|
id: existingAssets[0].id
|
2019-01-04 21:14:41 +00:00
|
|
|
}).catch((deleteErr) => {
|
|
|
|
console.log(`Failed to delete existing asset ${fileName}. Error was:`, deleteErr)
|
|
|
|
}).then(uploadToGitHub)
|
2017-10-18 20:49:32 +00:00
|
|
|
} else {
|
2019-01-04 21:14:41 +00:00
|
|
|
console.log(`Current asset ${fileName} not found in existing assets; retrying upload.`)
|
2017-10-18 20:49:32 +00:00
|
|
|
uploadToGitHub()
|
|
|
|
}
|
2019-01-04 21:14:41 +00:00
|
|
|
}).catch((getReleaseErr) => {
|
|
|
|
console.log(`Fatal: Unable to get current release assets via getRelease! Error was:`, getReleaseErr)
|
2017-10-18 20:49:32 +00:00
|
|
|
})
|
2017-10-04 14:33:27 +00:00
|
|
|
} else {
|
|
|
|
console.log(`Error retrying uploading ${fileName} to GitHub:`, err)
|
|
|
|
process.exitCode = 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadToGitHub()
|