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