Skip to content

Commit

Permalink
Undo (#16690)
Browse files Browse the repository at this point in the history
* Revert "fix asset fail workaround (#16680)"

This reverts commit e61c854.

* Revert "build: hack around GitHub upload API failure / flake (#16667)"

This reverts commit 1098d0f.
  • Loading branch information
codebytere committed Feb 2, 2019
1 parent 27ff318 commit 0dd8fd5
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions script/upload-to-github.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,35 @@ 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 () {
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.editAsset({
owner: 'electron',
repo: 'electron',
id: uploadResponse.data.id,
name: fileName
}).then(() => {
console.log(`Successfully renamed ${fakeFileName} to ${fileName}. All done now.`)
process.exit(0)
})
github.repos.uploadAsset(githubOpts).then(() => {
console.log(`Successfully uploaded ${fileName} to GitHub.`)
process.exit()
}).catch((err) => {
if (retry < 4) {
console.log(`Error uploading ${fileName} as ${fakeFileName} to GitHub, will retry. Error was:`, err)
console.log(`Error uploading ${fileName} 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.startsWith(fakeFileNamePrefix) || asset.name === fileName)
const existingAssets = release.data.assets.filter(asset => asset.name === fileName)
if (existingAssets.length > 0) {
console.log(`${fileName} already exists; will delete before retrying upload.`)
Promise.all(
existingAssets.map(existingAsset => github.repos.deleteAsset({
owner: 'electron',
repo: targetRepo,
id: existingAsset.id
}))
).catch((deleteErr) => {
github.repos.deleteAsset({
owner: 'electron',
repo: targetRepo,
id: existingAssets[0].id
}).catch((deleteErr) => {
console.log(`Failed to delete existing asset ${fileName}. Error was:`, deleteErr)
}).then(uploadToGitHub)
} else {
Expand Down

0 comments on commit 0dd8fd5

Please sign in to comment.