| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | #!/usr/bin/env node
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-19 11:48:13 -07:00
										 |  |  | if (!process.env.CI) require('dotenv-safe').load() | 
					
						
							| 
									
										
										
										
											2019-08-29 07:46:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-19 20:36:01 -07:00
										 |  |  | const args = require('minimist')(process.argv.slice(2), { | 
					
						
							|  |  |  |   boolean: [ | 
					
						
							|  |  |  |     'validateRelease', | 
					
						
							|  |  |  |     'skipVersionCheck', | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |     'automaticRelease', | 
					
						
							|  |  |  |     'verboseNugget' | 
					
						
							|  |  |  |   ], | 
					
						
							|  |  |  |   default: { 'verboseNugget': false } | 
					
						
							| 
									
										
										
										
											2018-12-19 20:36:01 -07:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | const fs = require('fs') | 
					
						
							|  |  |  | const { execSync } = require('child_process') | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  | const nugget = require('nugget') | 
					
						
							|  |  |  | const got = require('got') | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  | const pkg = require('../../package.json') | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | const pkgVersion = `v${pkg.version}` | 
					
						
							|  |  |  | const path = require('path') | 
					
						
							|  |  |  | const sumchecker = require('sumchecker') | 
					
						
							|  |  |  | const temp = require('temp').track() | 
					
						
							|  |  |  | const { URL } = require('url') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-29 07:46:54 -07:00
										 |  |  | require('colors') | 
					
						
							|  |  |  | const pass = '✓'.green | 
					
						
							|  |  |  | const fail = '✗'.red | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  | const { ELECTRON_DIR } = require('../lib/utils') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-07 18:48:40 -07:00
										 |  |  | const octokit = require('@octokit/rest')({ | 
					
						
							|  |  |  |   auth: process.env.ELECTRON_GITHUB_TOKEN | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const targetRepo = pkgVersion.indexOf('nightly') > 0 ? 'nightlies' : 'electron' | 
					
						
							|  |  |  | let failureCount = 0 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | async function getDraftRelease (version, skipValidation) { | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |   const releaseInfo = await octokit.repos.listReleases({ | 
					
						
							|  |  |  |     owner: 'electron', | 
					
						
							|  |  |  |     repo: targetRepo | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const versionToCheck = version || pkgVersion | 
					
						
							|  |  |  |   const drafts = releaseInfo.data.filter(release => { | 
					
						
							|  |  |  |     return release.tag_name === versionToCheck && release.draft === true | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   const draft = drafts[0] | 
					
						
							|  |  |  |   if (!skipValidation) { | 
					
						
							|  |  |  |     failureCount = 0 | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |     check(drafts.length === 1, 'one draft exists', true) | 
					
						
							| 
									
										
										
										
											2018-01-30 17:35:16 -07:00
										 |  |  |     if (versionToCheck.indexOf('beta') > -1) { | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |       check(draft.prerelease, 'draft is a prerelease') | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |     check(draft.body.length > 50 && !draft.body.includes('(placeholder)'), 'draft has release notes') | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     check((failureCount === 0), `Draft release looks good to go.`, true) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return draft | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-31 16:40:38 -07:00
										 |  |  | async function validateReleaseAssets (release, validatingRelease) { | 
					
						
							|  |  |  |   const requiredAssets = assetsForVersion(release.tag_name, validatingRelease).sort() | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   const extantAssets = release.assets.map(asset => asset.name).sort() | 
					
						
							|  |  |  |   const downloadUrls = release.assets.map(asset => asset.browser_download_url).sort() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   failureCount = 0 | 
					
						
							|  |  |  |   requiredAssets.forEach(asset => { | 
					
						
							|  |  |  |     check(extantAssets.includes(asset), asset) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   check((failureCount === 0), `All required GitHub assets exist for release`, true) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-22 08:53:32 -05:00
										 |  |  |   if (!validatingRelease || !release.draft) { | 
					
						
							|  |  |  |     if (release.draft) { | 
					
						
							|  |  |  |       await verifyAssets(release) | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       await verifyShasums(downloadUrls) | 
					
						
							|  |  |  |         .catch(err => { | 
					
						
							|  |  |  |           console.log(`${fail} error verifyingShasums`, err) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     const s3Urls = s3UrlsForVersion(release.tag_name) | 
					
						
							|  |  |  |     await verifyShasums(s3Urls, true) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function check (condition, statement, exitIfFail = false) { | 
					
						
							|  |  |  |   if (condition) { | 
					
						
							|  |  |  |     console.log(`${pass} ${statement}`) | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     failureCount++ | 
					
						
							|  |  |  |     console.log(`${fail} ${statement}`) | 
					
						
							|  |  |  |     if (exitIfFail) process.exit(1) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-31 16:40:38 -07:00
										 |  |  | function assetsForVersion (version, validatingRelease) { | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   const patterns = [ | 
					
						
							| 
									
										
										
										
											2019-09-04 14:24:46 -04:00
										 |  |  |     `chromedriver-${version}-darwin-x64.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-linux-arm64.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-linux-armv7l.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-linux-ia32.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-linux-x64.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-mas-x64.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-win32-ia32.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-win32-x64.zip`, | 
					
						
							|  |  |  |     `chromedriver-${version}-win32-arm64.zip`, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     `electron-${version}-darwin-x64-dsym.zip`, | 
					
						
							|  |  |  |     `electron-${version}-darwin-x64-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-darwin-x64.zip`, | 
					
						
							| 
									
										
										
										
											2019-01-22 16:14:01 -05:00
										 |  |  |     `electron-${version}-linux-arm64-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-linux-arm64.zip`, | 
					
						
							|  |  |  |     `electron-${version}-linux-armv7l-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-linux-armv7l.zip`, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     `electron-${version}-linux-ia32-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-linux-ia32.zip`, | 
					
						
							| 
									
										
										
										
											2019-11-20 17:21:44 -08:00
										 |  |  |     `electron-${version}-linux-x64-debug.zip`, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     `electron-${version}-linux-x64-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-linux-x64.zip`, | 
					
						
							|  |  |  |     `electron-${version}-mas-x64-dsym.zip`, | 
					
						
							|  |  |  |     `electron-${version}-mas-x64-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-mas-x64.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-ia32-pdb.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-ia32-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-ia32.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-x64-pdb.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-x64-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-x64.zip`, | 
					
						
							| 
									
										
										
										
											2019-09-04 14:24:46 -04:00
										 |  |  |     `electron-${version}-win32-arm64-pdb.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-arm64-symbols.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-arm64.zip`, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     `electron-api.json`, | 
					
						
							|  |  |  |     `electron.d.ts`, | 
					
						
							| 
									
										
										
										
											2019-10-31 13:11:51 -07:00
										 |  |  |     `hunspell_dictionaries.zip`, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     `ffmpeg-${version}-darwin-x64.zip`, | 
					
						
							| 
									
										
										
										
											2019-01-22 16:14:01 -05:00
										 |  |  |     `ffmpeg-${version}-linux-arm64.zip`, | 
					
						
							|  |  |  |     `ffmpeg-${version}-linux-armv7l.zip`, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     `ffmpeg-${version}-linux-ia32.zip`, | 
					
						
							|  |  |  |     `ffmpeg-${version}-linux-x64.zip`, | 
					
						
							|  |  |  |     `ffmpeg-${version}-mas-x64.zip`, | 
					
						
							|  |  |  |     `ffmpeg-${version}-win32-ia32.zip`, | 
					
						
							| 
									
										
										
										
											2019-09-04 14:24:46 -04:00
										 |  |  |     `ffmpeg-${version}-win32-x64.zip`, | 
					
						
							|  |  |  |     `ffmpeg-${version}-win32-arm64.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-darwin-x64.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-linux-arm64-x64.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-linux-armv7l-x64.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-linux-ia32.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-linux-x64.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-mas-x64.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-win32-ia32.zip`, | 
					
						
							|  |  |  |     `mksnapshot-${version}-win32-x64.zip`, | 
					
						
							| 
									
										
										
										
											2020-01-13 20:40:13 +00:00
										 |  |  |     `mksnapshot-${version}-win32-arm64-x64.zip`, | 
					
						
							| 
									
										
										
										
											2020-01-14 17:10:08 -05:00
										 |  |  |     `electron-${version}-win32-ia32-toolchain-profile.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-x64-toolchain-profile.zip`, | 
					
						
							|  |  |  |     `electron-${version}-win32-arm64-toolchain-profile.zip` | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   ] | 
					
						
							| 
									
										
										
										
											2018-01-31 16:40:38 -07:00
										 |  |  |   if (!validatingRelease) { | 
					
						
							|  |  |  |     patterns.push('SHASUMS256.txt') | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   return patterns | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function s3UrlsForVersion (version) { | 
					
						
							|  |  |  |   const bucket = `https://gh-contractor-zcbenz.s3.amazonaws.com/` | 
					
						
							|  |  |  |   const patterns = [ | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/iojs-${version}-headers.tar.gz`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/iojs-${version}.tar.gz`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/node-${version}.tar.gz`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/node.lib`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/win-x64/iojs.lib`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/win-x86/iojs.lib`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/x64/node.lib`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/SHASUMS.txt`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/${version}/SHASUMS256.txt`, | 
					
						
							|  |  |  |     `${bucket}atom-shell/dist/index.json` | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  |   return patterns | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function runScript (scriptName, scriptArgs, cwd) { | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const scriptCommand = `${scriptName} ${scriptArgs.join(' ')}` | 
					
						
							|  |  |  |   const scriptOptions = { | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     encoding: 'UTF-8' | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |   if (cwd) scriptOptions.cwd = cwd | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   try { | 
					
						
							|  |  |  |     return execSync(scriptCommand, scriptOptions) | 
					
						
							|  |  |  |   } catch (err) { | 
					
						
							|  |  |  |     console.log(`${fail} Error running ${scriptName}`, err) | 
					
						
							|  |  |  |     process.exit(1) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function uploadNodeShasums () { | 
					
						
							|  |  |  |   console.log('Uploading Node SHASUMS file to S3.') | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |   const scriptPath = path.join(ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-node-checksums.py') | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   runScript(scriptPath, ['-v', pkgVersion]) | 
					
						
							|  |  |  |   console.log(`${pass} Done uploading Node SHASUMS file to S3.`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function uploadIndexJson () { | 
					
						
							|  |  |  |   console.log('Uploading index.json to S3.') | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |   const scriptPath = path.join(ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-index-json.py') | 
					
						
							| 
									
										
										
										
											2018-08-16 22:23:46 -07:00
										 |  |  |   runScript(scriptPath, [pkgVersion]) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   console.log(`${pass} Done uploading index.json to S3.`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function createReleaseShasums (release) { | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const fileName = 'SHASUMS256.txt' | 
					
						
							|  |  |  |   const existingAssets = release.assets.filter(asset => asset.name === fileName) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   if (existingAssets.length > 0) { | 
					
						
							|  |  |  |     console.log(`${fileName} already exists on GitHub; deleting before creating new file.`) | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |     await octokit.repos.deleteReleaseAsset({ | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |       owner: 'electron', | 
					
						
							| 
									
										
										
										
											2018-08-16 08:57:12 -07:00
										 |  |  |       repo: targetRepo, | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |       asset_id: existingAssets[0].id | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     }).catch(err => { | 
					
						
							|  |  |  |       console.log(`${fail} Error deleting ${fileName} on GitHub:`, err) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   console.log(`Creating and uploading the release ${fileName}.`) | 
					
						
							| 
									
										
										
										
											2019-06-24 10:18:04 -07:00
										 |  |  |   const scriptPath = path.join(ELECTRON_DIR, 'script', 'release', 'merge-electron-checksums.py') | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const checksums = runScript(scriptPath, ['-v', pkgVersion]) | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   console.log(`${pass} Generated release SHASUMS.`) | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const filePath = await saveShaSumFile(checksums, fileName) | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   console.log(`${pass} Created ${fileName} file.`) | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |   await uploadShasumFile(filePath, fileName, release.id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   console.log(`${pass} Successfully uploaded ${fileName} to GitHub.`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | async function uploadShasumFile (filePath, fileName, releaseId) { | 
					
						
							|  |  |  |   const uploadUrl = `https://uploads.github.com/repos/electron/${targetRepo}/releases/${releaseId}/assets{?name,label}` | 
					
						
							|  |  |  |   return octokit.repos.uploadReleaseAsset({ | 
					
						
							|  |  |  |     url: uploadUrl, | 
					
						
							|  |  |  |     headers: { | 
					
						
							|  |  |  |       'content-type': 'text/plain', | 
					
						
							| 
									
										
										
										
											2019-01-11 09:53:13 -08:00
										 |  |  |       'content-length': fs.statSync(filePath).size | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |     }, | 
					
						
							|  |  |  |     file: fs.createReadStream(filePath), | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     name: fileName | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |   }).catch(err => { | 
					
						
							|  |  |  |     console.log(`${fail} Error uploading ${filePath} to GitHub:`, err) | 
					
						
							|  |  |  |     process.exit(1) | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function saveShaSumFile (checksums, fileName) { | 
					
						
							|  |  |  |   return new Promise((resolve, reject) => { | 
					
						
							|  |  |  |     temp.open(fileName, (err, info) => { | 
					
						
							|  |  |  |       if (err) { | 
					
						
							|  |  |  |         console.log(`${fail} Could not create ${fileName} file`) | 
					
						
							|  |  |  |         process.exit(1) | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         fs.writeFileSync(info.fd, checksums) | 
					
						
							|  |  |  |         fs.close(info.fd, (err) => { | 
					
						
							|  |  |  |           if (err) { | 
					
						
							|  |  |  |             console.log(`${fail} Could close ${fileName} file`) | 
					
						
							|  |  |  |             process.exit(1) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           resolve(info.path) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function publishRelease (release) { | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |   return octokit.repos.updateRelease({ | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     owner: 'electron', | 
					
						
							| 
									
										
										
										
											2018-08-16 08:57:12 -07:00
										 |  |  |     repo: targetRepo, | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |     release_id: release.id, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     tag_name: release.tag_name, | 
					
						
							|  |  |  |     draft: false | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |   }).catch(err => { | 
					
						
							|  |  |  |     console.log(`${fail} Error publishing release:`, err) | 
					
						
							|  |  |  |     process.exit(1) | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function makeRelease (releaseToValidate) { | 
					
						
							|  |  |  |   if (releaseToValidate) { | 
					
						
							| 
									
										
										
										
											2018-01-31 16:40:38 -07:00
										 |  |  |     if (releaseToValidate === true) { | 
					
						
							|  |  |  |       releaseToValidate = pkgVersion | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       console.log('Release to validate !=== true') | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     console.log(`Validating release ${releaseToValidate}`) | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |     const release = await getDraftRelease(releaseToValidate) | 
					
						
							| 
									
										
										
										
											2018-01-31 16:40:38 -07:00
										 |  |  |     await validateReleaseAssets(release, true) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     let draftRelease = await getDraftRelease() | 
					
						
							|  |  |  |     uploadNodeShasums() | 
					
						
							| 
									
										
										
										
											2018-08-16 22:23:46 -07:00
										 |  |  |     uploadIndexJson() | 
					
						
							| 
									
										
										
										
											2018-08-16 16:15:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     await createReleaseShasums(draftRelease) | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     // Fetch latest version of release before verifying
 | 
					
						
							|  |  |  |     draftRelease = await getDraftRelease(pkgVersion, true) | 
					
						
							|  |  |  |     await validateReleaseAssets(draftRelease) | 
					
						
							|  |  |  |     await publishRelease(draftRelease) | 
					
						
							|  |  |  |     console.log(`${pass} SUCCESS!!! Release has been published. Please run ` + | 
					
						
							|  |  |  |       `"npm run publish-to-npm" to publish release to npm.`) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function makeTempDir () { | 
					
						
							|  |  |  |   return new Promise((resolve, reject) => { | 
					
						
							|  |  |  |     temp.mkdir('electron-publish', (err, dirPath) => { | 
					
						
							|  |  |  |       if (err) { | 
					
						
							|  |  |  |         reject(err) | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         resolve(dirPath) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function verifyAssets (release) { | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const downloadDir = await makeTempDir() | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   console.log(`Downloading files from GitHub to verify shasums`) | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const shaSumFile = 'SHASUMS256.txt' | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let filesToCheck = await Promise.all(release.assets.map(async asset => { | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |     const requestOptions = await octokit.repos.getReleaseAsset.endpoint({ | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |       owner: 'electron', | 
					
						
							|  |  |  |       repo: targetRepo, | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |       asset_id: asset.id, | 
					
						
							|  |  |  |       headers: { | 
					
						
							|  |  |  |         Accept: 'application/octet-stream' | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     return asset.name | 
					
						
							|  |  |  |   })).catch(err => { | 
					
						
							|  |  |  |     console.log(`${fail} Error downloading files from GitHub`, err) | 
					
						
							|  |  |  |     process.exit(1) | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2019-01-08 12:05:58 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   filesToCheck = filesToCheck.filter(fileName => fileName !== shaSumFile) | 
					
						
							|  |  |  |   let checkerOpts | 
					
						
							|  |  |  |   await validateChecksums({ | 
					
						
							|  |  |  |     algorithm: 'sha256', | 
					
						
							|  |  |  |     filesToCheck, | 
					
						
							|  |  |  |     fileDirectory: downloadDir, | 
					
						
							|  |  |  |     shaSumFile, | 
					
						
							|  |  |  |     checkerOpts, | 
					
						
							|  |  |  |     fileSource: 'GitHub' | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  | function downloadFiles (urls, directory, targetName) { | 
					
						
							|  |  |  |   return new Promise((resolve, reject) => { | 
					
						
							|  |  |  |     const nuggetOpts = { dir: directory } | 
					
						
							|  |  |  |     nuggetOpts.quiet = !args.verboseNugget | 
					
						
							|  |  |  |     if (targetName) nuggetOpts.target = targetName | 
					
						
							| 
									
										
										
										
											2019-01-22 08:53:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |     nugget(urls, nuggetOpts, (err) => { | 
					
						
							|  |  |  |       if (err) { | 
					
						
							|  |  |  |         reject(err) | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         console.log(`${pass} all files downloaded successfully!`) | 
					
						
							|  |  |  |         resolve() | 
					
						
							| 
									
										
										
										
											2019-01-22 08:53:52 -08:00
										 |  |  |       } | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2019-01-23 11:47:36 -08:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function verifyShasums (urls, isS3) { | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const fileSource = isS3 ? 'S3' : 'GitHub' | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   console.log(`Downloading files from ${fileSource} to verify shasums`) | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const downloadDir = await makeTempDir() | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |   let filesToCheck = [] | 
					
						
							|  |  |  |   try { | 
					
						
							|  |  |  |     if (!isS3) { | 
					
						
							|  |  |  |       await downloadFiles(urls, downloadDir) | 
					
						
							|  |  |  |       filesToCheck = urls.map(url => { | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |         const currentUrl = new URL(url) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |         return path.basename(currentUrl.pathname) | 
					
						
							|  |  |  |       }).filter(file => file.indexOf('SHASUMS') === -1) | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       const s3VersionPath = `/atom-shell/dist/${pkgVersion}/` | 
					
						
							|  |  |  |       await Promise.all(urls.map(async (url) => { | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |         const currentUrl = new URL(url) | 
					
						
							|  |  |  |         const dirname = path.dirname(currentUrl.pathname) | 
					
						
							|  |  |  |         const filename = path.basename(currentUrl.pathname) | 
					
						
							|  |  |  |         const s3VersionPathIdx = dirname.indexOf(s3VersionPath) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |         if (s3VersionPathIdx === -1 || dirname === s3VersionPath) { | 
					
						
							|  |  |  |           if (s3VersionPathIdx !== -1 && filename.indexof('SHASUMS') === -1) { | 
					
						
							|  |  |  |             filesToCheck.push(filename) | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-12-19 20:36:01 -07:00
										 |  |  |           await downloadFiles(url, downloadDir) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |           const subDirectory = dirname.substr(s3VersionPathIdx + s3VersionPath.length) | 
					
						
							|  |  |  |           const fileDirectory = path.join(downloadDir, subDirectory) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |           try { | 
					
						
							|  |  |  |             fs.statSync(fileDirectory) | 
					
						
							|  |  |  |           } catch (err) { | 
					
						
							|  |  |  |             fs.mkdirSync(fileDirectory) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           filesToCheck.push(path.join(subDirectory, filename)) | 
					
						
							| 
									
										
										
										
											2018-12-19 20:36:01 -07:00
										 |  |  |           await downloadFiles(url, fileDirectory) | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |       })) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } catch (err) { | 
					
						
							|  |  |  |     console.log(`${fail} Error downloading files from ${fileSource}`, err) | 
					
						
							|  |  |  |     process.exit(1) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   console.log(`${pass} Successfully downloaded the files from ${fileSource}.`) | 
					
						
							|  |  |  |   let checkerOpts | 
					
						
							|  |  |  |   if (isS3) { | 
					
						
							|  |  |  |     checkerOpts = { defaultTextEncoding: 'binary' } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await validateChecksums({ | 
					
						
							|  |  |  |     algorithm: 'sha256', | 
					
						
							|  |  |  |     filesToCheck, | 
					
						
							|  |  |  |     fileDirectory: downloadDir, | 
					
						
							|  |  |  |     shaSumFile: 'SHASUMS256.txt', | 
					
						
							|  |  |  |     checkerOpts, | 
					
						
							|  |  |  |     fileSource | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (isS3) { | 
					
						
							|  |  |  |     await validateChecksums({ | 
					
						
							|  |  |  |       algorithm: 'sha1', | 
					
						
							|  |  |  |       filesToCheck, | 
					
						
							|  |  |  |       fileDirectory: downloadDir, | 
					
						
							|  |  |  |       shaSumFile: 'SHASUMS.txt', | 
					
						
							|  |  |  |       checkerOpts, | 
					
						
							|  |  |  |       fileSource | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | async function validateChecksums (validationArgs) { | 
					
						
							|  |  |  |   console.log(`Validating checksums for files from ${validationArgs.fileSource} ` + | 
					
						
							|  |  |  |     `against ${validationArgs.shaSumFile}.`) | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |   const shaSumFilePath = path.join(validationArgs.fileDirectory, validationArgs.shaSumFile) | 
					
						
							|  |  |  |   const checker = new sumchecker.ChecksumValidator(validationArgs.algorithm, | 
					
						
							| 
									
										
										
										
											2017-10-23 11:02:50 -04:00
										 |  |  |     shaSumFilePath, validationArgs.checkerOpts) | 
					
						
							|  |  |  |   await checker.validate(validationArgs.fileDirectory, validationArgs.filesToCheck) | 
					
						
							|  |  |  |     .catch(err => { | 
					
						
							|  |  |  |       if (err instanceof sumchecker.ChecksumMismatchError) { | 
					
						
							|  |  |  |         console.error(`${fail} The checksum of ${err.filename} from ` + | 
					
						
							|  |  |  |           `${validationArgs.fileSource} did not match the shasum in ` + | 
					
						
							|  |  |  |           `${validationArgs.shaSumFile}`) | 
					
						
							|  |  |  |       } else if (err instanceof sumchecker.ChecksumParseError) { | 
					
						
							|  |  |  |         console.error(`${fail} The checksum file ${validationArgs.shaSumFile} ` + | 
					
						
							|  |  |  |           `from ${validationArgs.fileSource} could not be parsed.`, err) | 
					
						
							|  |  |  |       } else if (err instanceof sumchecker.NoChecksumFoundError) { | 
					
						
							|  |  |  |         console.error(`${fail} The file ${err.filename} from ` + | 
					
						
							|  |  |  |           `${validationArgs.fileSource} was not in the shasum file ` + | 
					
						
							|  |  |  |           `${validationArgs.shaSumFile}.`) | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         console.error(`${fail} Error matching files from ` + | 
					
						
							|  |  |  |           `${validationArgs.fileSource} shasums in ${validationArgs.shaSumFile}.`, err) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       process.exit(1) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   console.log(`${pass} All files from ${validationArgs.fileSource} match ` + | 
					
						
							|  |  |  |     `shasums defined in ${validationArgs.shaSumFile}.`) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | makeRelease(args.validateRelease) |