build: hack around GitHub upload API failure / flake (#16663)
This commit is contained in:
parent
c8c1be7ae5
commit
ab503c7e43
1 changed files with 24 additions and 11 deletions
|
@ -36,17 +36,28 @@ const uploadUrl = `https://uploads.github.com/repos/electron/${targetRepo}/relea
|
||||||
let retry = 0
|
let retry = 0
|
||||||
|
|
||||||
function uploadToGitHub () {
|
function uploadToGitHub () {
|
||||||
|
const fakeFileNamePrefix = `fake-${fileName}-fake-`
|
||||||
|
const fakeFileName = `${fakeFileNamePrefix}${Date.now()}`
|
||||||
|
|
||||||
octokit.repos.uploadReleaseAsset({
|
octokit.repos.uploadReleaseAsset({
|
||||||
url: uploadUrl,
|
url: uploadUrl,
|
||||||
headers: getHeaders(filePath, fileName),
|
headers: getHeaders(filePath, fileName),
|
||||||
file: fs.createReadStream(filePath),
|
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
|
name: fileName
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log(`Successfully uploaded ${fileName} to GitHub.`)
|
console.log(`Successfully renamed ${fakeFileName} to ${fileName}. All done now.`)
|
||||||
process.exit()
|
process.exit(0)
|
||||||
|
})
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
if (retry < 4) {
|
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++
|
retry++
|
||||||
|
|
||||||
octokit.repos.listAssetsForRelease({
|
octokit.repos.listAssetsForRelease({
|
||||||
|
@ -56,15 +67,17 @@ function uploadToGitHub () {
|
||||||
}).then(assets => {
|
}).then(assets => {
|
||||||
console.log('Got list of assets for existing release:')
|
console.log('Got list of assets for existing release:')
|
||||||
console.log(JSON.stringify(assets.data, null, ' '))
|
console.log(JSON.stringify(assets.data, null, ' '))
|
||||||
const existingAssets = assets.data.filter(asset => asset.name === fileName)
|
const existingAssets = assets.data.filter(asset => asset.name.startsWith(fakeFileNamePrefix) || asset.name === fileName)
|
||||||
|
|
||||||
if (existingAssets.length > 0) {
|
if (existingAssets.length > 0) {
|
||||||
console.log(`${fileName} already exists; will delete before retrying upload.`)
|
console.log(`${fileName} already exists; will delete before retrying upload.`)
|
||||||
octokit.repos.deleteReleaseAsset({
|
Promise.all(
|
||||||
|
existingAssets.map(existingAsset => octokit.repos.deleteReleaseAsset({
|
||||||
owner: 'electron',
|
owner: 'electron',
|
||||||
repo: targetRepo,
|
repo: targetRepo,
|
||||||
asset_id: existingAssets[0].id
|
asset_id: existingAsset.id
|
||||||
}).catch((deleteErr) => {
|
}))
|
||||||
|
).catch((deleteErr) => {
|
||||||
console.log(`Failed to delete existing asset ${fileName}. Error was:`, deleteErr)
|
console.log(`Failed to delete existing asset ${fileName}. Error was:`, deleteErr)
|
||||||
}).then(uploadToGitHub)
|
}).then(uploadToGitHub)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue