build: fix individual asset downloading in release script (#16493)

* Revert "build: fix release asset download for now (#16486)"

This reverts commit 7df531bc4e.

* build: clean up asset downloading
This commit is contained in:
Shelley Vohr 2019-01-23 11:47:36 -08:00 коммит произвёл Samuel Attard
Родитель ad3ea6ec53
Коммит f431ce4971
3 изменённых файлов: 43 добавлений и 89 удалений

51
package-lock.json сгенерированный
Просмотреть файл

@ -672,16 +672,6 @@
"integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==",
"dev": true
},
"axios": {
"version": "0.18.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz",
"integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=",
"dev": true,
"requires": {
"follow-redirects": "^1.3.0",
"is-buffer": "^1.1.5"
}
},
"babel-code-frame": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz",
@ -1560,7 +1550,7 @@
"circular-json": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz",
"integrity": "sha1-gVyZ6oT2gJUp0vRXkb34JxE1LWY=",
"integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==",
"dev": true
},
"clang-format": {
@ -1944,15 +1934,6 @@
"integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=",
"dev": true
},
"content-disposition": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
"integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==",
"dev": true,
"requires": {
"safe-buffer": "5.1.2"
}
},
"content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
@ -4166,7 +4147,7 @@
"find-root": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz",
"integrity": "sha1-q8/Iunb3CMQql7PWhbfpRQv7nOQ=",
"integrity": "sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==",
"dev": true
},
"find-up": {
@ -4249,26 +4230,6 @@
}
}
},
"follow-redirects": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.6.1.tgz",
"integrity": "sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==",
"dev": true,
"requires": {
"debug": "=3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
}
}
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
@ -5269,7 +5230,7 @@
"gunzip-maybe": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/gunzip-maybe/-/gunzip-maybe-1.4.1.tgz",
"integrity": "sha512-qtutIKMthNJJgeHQS7kZ9FqDq59/Wn0G2HYCRNjpup7yKfVI6/eqwpmroyZGFoCYaG+sW6psNVb4zoLADHpp2g==",
"integrity": "sha1-Occu2J0bSbpwjhh3ZQBIiQKlICc=",
"dev": true,
"requires": {
"browserify-zlib": "^0.1.4",
@ -10321,7 +10282,7 @@
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==",
"integrity": "sha1-KBYjTiN4vdxOU1T6tcqold9xANk=",
"dev": true,
"optional": true
},
@ -10827,7 +10788,7 @@
"split": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
"integrity": "sha1-YFvZvjA6pZ+zX5Ip++oN3snqB9k=",
"dev": true,
"requires": {
"through": "2"
@ -10845,7 +10806,7 @@
"split2": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz",
"integrity": "sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==",
"integrity": "sha1-GGsldbz4PoW30YRldWI47k7kJJM=",
"dev": true,
"requires": {
"through2": "^2.0.2"

Просмотреть файл

@ -7,12 +7,10 @@
"@octokit/rest": "^16.3.2",
"aliasify": "^2.1.0",
"asar": "^0.11.0",
"axios": "^0.18.0",
"browserify": "^13.1.0",
"check-for-leaks": "^1.0.2",
"clang-format": "^1.2.3",
"colors": "^1.1.2",
"content-disposition": "^0.5.3",
"dotenv-safe": "^4.0.4",
"dugite": "^1.45.0",
"electron-docs-linter": "^2.4.0",

Просмотреть файл

@ -6,11 +6,15 @@ const args = require('minimist')(process.argv.slice(2), {
boolean: [
'validateRelease',
'skipVersionCheck',
'automaticRelease'
]
'automaticRelease',
'verboseNugget'
],
default: { 'verboseNugget': false }
})
const fs = require('fs')
const { execSync } = require('child_process')
const nugget = require('nugget')
const got = require('got')
const pkg = require('../package.json')
const pkgVersion = `v${pkg.version}`
const pass = '\u2713'.green
@ -19,8 +23,6 @@ const fail = '\u2717'.red
const sumchecker = require('sumchecker')
const temp = require('temp').track()
const { URL } = require('url')
const axios = require('axios')
const contentDisposition = require('content-disposition')
const octokit = require('@octokit/rest')()
octokit.authenticate({
@ -45,11 +47,11 @@ async function getDraftRelease (version, skipValidation) {
const draft = drafts[0]
if (!skipValidation) {
failureCount = 0
check(drafts.length === 1, 'Draft exists.', true)
check(drafts.length === 1, 'one draft exists', true)
if (versionToCheck.indexOf('beta') > -1) {
check(draft.prerelease, 'Draft is a prerelease.')
check(draft.prerelease, 'draft is a prerelease')
}
check(draft.body.length > 50 && !draft.body.includes('(placeholder)'), 'Draft has release notes.')
check(draft.body.length > 50 && !draft.body.includes('(placeholder)'), 'draft has release notes')
check((failureCount === 0), `Draft release looks good to go.`, true)
}
return draft
@ -309,13 +311,25 @@ async function verifyAssets (release) {
const shaSumFile = 'SHASUMS256.txt'
let filesToCheck = await Promise.all(release.assets.map(async asset => {
const assetDetails = await octokit.repos.getReleaseAsset({
const requestOptions = await octokit.repos.getReleaseAsset.endpoint({
owner: 'electron',
repo: targetRepo,
asset_id: asset.id
asset_id: asset.id,
headers: {
Accept: 'application/octet-stream'
}
})
const downloadURL = assetDetails.data.url.replace('://', '://' + process.env.ELECTRON_GITHUB_TOKEN + ':@')
await downloadFiles(downloadURL, downloadDir, asset.name)
const { url, headers } = requestOptions
headers.authorization = `token ${process.env.ELECTRON_GITHUB_TOKEN}`
const response = await got(url, {
followRedirect: false,
method: 'HEAD',
headers
})
await downloadFiles(response.headers.location, downloadDir, asset.name)
return asset.name
})).catch(err => {
console.log(`${fail} Error downloading files from GitHub`, err)
@ -334,40 +348,21 @@ async function verifyAssets (release) {
})
}
async function downloadFiles (urls, directory, targetName) {
const allUrls = Array.isArray(urls) ? urls : [urls]
function downloadFiles (urls, directory, targetName) {
return new Promise((resolve, reject) => {
const nuggetOpts = { dir: directory }
nuggetOpts.quiet = !args.verboseNugget
if (targetName) nuggetOpts.target = targetName
await Promise.all(allUrls.map(async (targetUrl) => {
const axiosResponse = await axios.get(targetUrl, {
responseType: 'stream',
headers: {
Accept: 'application/octet-stream'
nugget(urls, nuggetOpts, (err) => {
if (err) {
reject(err)
} else {
console.log(`${pass} all files downloaded successfully!`)
resolve()
}
})
if (axiosResponse.status !== 200) {
throw new Error(`Expected 200 status fetching "${targetUrl}" but got "${axiosResponse.status}"`)
}
let fileName = targetName
if (!fileName) {
if (axiosResponse.headers['content-disposition']) {
const parsed = contentDisposition.parse(axiosResponse.headers['content-disposition'])
fileName = parsed.parameters.filename
}
}
if (!fileName) {
const url = new URL(targetUrl)
fileName = path.basename(url.pathname)
}
if (!fileName) throw new Error(`Unknown filename for request: "${targetUrl}"`)
const writeStream = fs.createWriteStream(path.resolve(directory, fileName))
axiosResponse.data.pipe(writeStream)
return new Promise((resolve, reject) => {
writeStream.on('error', reject)
axiosResponse.data.on('error', reject)
writeStream.on('close', resolve)
})
}))
})
}
async function verifyShasums (urls, isS3) {