Permalink
Browse files

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

#16802)

This reverts commit ab503c7.
  • Loading branch information...
codebytere committed Feb 7, 2019
1 parent c8a1231 commit c6fc5a23fcaf14a9a5eac27e9b0a1ad873f89683
Showing with 11 additions and 24 deletions.
  1. +11 −24 script/upload-to-github.js
@@ -36,28 +36,17 @@ const uploadUrl = `https://uploads.github.com/repos/electron/${targetRepo}/relea
let retry = 0

function uploadToGitHub () {
const fakeFileNamePrefix = `fake-${fileName}-fake-`
const fakeFileName = `${fakeFileNamePrefix}${Date.now()}`

octokit.repos.uploadReleaseAsset({
url: uploadUrl,
headers: getHeaders(filePath, fileName),
file: fs.createReadStream(filePath),
name: fakeFileName
}).then((uploadResponse) => {
console.log(`Successfully uploaded ${fileName} to GitHub as ${fakeFileName}. Going for the rename now.`)
return octokit.repos.updateReleaseAsset({
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)
})
name: fileName
}).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++

octokit.repos.listAssetsForRelease({
@@ -67,17 +56,15 @@ function uploadToGitHub () {
}).then(assets => {
console.log('Got list of assets for existing release:')
console.log(JSON.stringify(assets.data, null, ' '))
const existingAssets = assets.data.filter(asset => asset.name.startsWith(fakeFileNamePrefix) || asset.name === fileName)
const existingAssets = assets.data.filter(asset => asset.name === fileName)

if (existingAssets.length > 0) {
console.log(`${fileName} already exists; will delete before retrying upload.`)
Promise.all(
existingAssets.map(existingAsset => octokit.repos.deleteReleaseAsset({
owner: 'electron',
repo: targetRepo,
asset_id: existingAsset.id
}))
).catch((deleteErr) => {
octokit.repos.deleteReleaseAsset({
owner: 'electron',
repo: targetRepo,
asset_id: existingAssets[0].id
}).catch((deleteErr) => {
console.log(`Failed to delete existing asset ${fileName}. Error was:`, deleteErr)
}).then(uploadToGitHub)
} else {

0 comments on commit c6fc5a2

Please sign in to comment.