|
@@ -15,35 +15,47 @@ const releaseVersion = process.argv[5]
|
|
|
|
|
|
const targetRepo = releaseVersion.indexOf('nightly') > 0 ? 'nightlies' : 'electron'
|
|
|
|
|
|
-const githubOpts = {
|
|
|
- owner: 'electron',
|
|
|
- repo: targetRepo,
|
|
|
- id: releaseId,
|
|
|
- filePath: filePath,
|
|
|
- name: fileName
|
|
|
-}
|
|
|
-
|
|
|
let retry = 0
|
|
|
|
|
|
function uploadToGitHub () {
|
|
|
- github.repos.uploadAsset(githubOpts).then(() => {
|
|
|
- console.log(`Successfully uploaded ${fileName} to GitHub.`)
|
|
|
- process.exit()
|
|
|
+ const fakeFileNamePrefix = `fake-${fileName}-fake-`
|
|
|
+ const fakeFileName = `${fakeFileNamePrefix}${Date.now()}`
|
|
|
+ const githubOpts = {
|
|
|
+ owner: 'electron',
|
|
|
+ repo: targetRepo,
|
|
|
+ id: releaseId,
|
|
|
+ filePath: filePath,
|
|
|
+ name: fakeFileName
|
|
|
+ }
|
|
|
+
|
|
|
+ github.repos.uploadAsset(githubOpts).then((uploadResponse) => {
|
|
|
+ console.log(`Successfully uploaded ${fileName} to GitHub as ${fakeFileName}. Going for the rename now.`)
|
|
|
+ return github.repos.updateAsset({
|
|
|
+ owner: 'electron',
|
|
|
+ repo: 'electron',
|
|
|
+ asset_id: uploadResponse.data.id,
|
|
|
+ name: fileName
|
|
|
+ }).then(() => {
|
|
|
+ console.log(`Successfully renamed ${fakeFileName} to ${fileName}. All done now.`)
|
|
|
+ process.exit(0)
|
|
|
+ })
|
|
|
}).catch((err) => {
|
|
|
if (retry < 4) {
|
|
|
- console.log(`Error uploading ${fileName} to GitHub, will retry. Error was:`, err)
|
|
|
+ console.log(`Error uploading ${fileName} as ${fakeFileName} to GitHub, will retry. Error was:`, err)
|
|
|
retry++
|
|
|
github.repos.getRelease(githubOpts).then(release => {
|
|
|
console.log('Got list of assets for existing release:')
|
|
|
console.log(JSON.stringify(release.data.assets, null, ' '))
|
|
|
- const existingAssets = release.data.assets.filter(asset => asset.name === fileName)
|
|
|
+ const existingAssets = release.data.assets.filter(asset => asset.name.startsWith(fakeFileNamePrefix) || asset.name === fileName)
|
|
|
if (existingAssets.length > 0) {
|
|
|
console.log(`${fileName} already exists; will delete before retrying upload.`)
|
|
|
- github.repos.deleteAsset({
|
|
|
- owner: 'electron',
|
|
|
- repo: targetRepo,
|
|
|
- id: existingAssets[0].id
|
|
|
- }).catch((deleteErr) => {
|
|
|
+ Promise.all(
|
|
|
+ existingAssets.map(existingAsset => github.repos.deleteAsset({
|
|
|
+ owner: 'electron',
|
|
|
+ repo: targetRepo,
|
|
|
+ asset_id: existingAsset.id
|
|
|
+ }))
|
|
|
+ ).catch((deleteErr) => {
|
|
|
console.log(`Failed to delete existing asset ${fileName}. Error was:`, deleteErr)
|
|
|
}).then(uploadToGitHub)
|
|
|
} else {
|