2017-10-23 15:02:50 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
import { BlobServiceClient } from '@azure/storage-blob';
|
|
|
|
import { Octokit } from '@octokit/rest';
|
2024-10-01 18:09:28 +00:00
|
|
|
import * as chalk from 'chalk';
|
2024-10-01 10:04:22 +00:00
|
|
|
import got from 'got';
|
|
|
|
import { execSync, ExecSyncOptions } from 'node:child_process';
|
|
|
|
import { statSync, createReadStream, writeFileSync, close } from 'node:fs';
|
|
|
|
import { join } from 'node:path';
|
|
|
|
import { gte } from 'semver';
|
|
|
|
import { track as trackTemp } from 'temp';
|
|
|
|
|
|
|
|
import { ELECTRON_DIR } from '../lib/utils';
|
|
|
|
import { getElectronVersion } from '../lib/get-version';
|
|
|
|
import { getUrlHash } from './get-url-hash';
|
|
|
|
import { createGitHubTokenStrategy } from './github-token';
|
2024-10-01 21:08:15 +00:00
|
|
|
import { ELECTRON_ORG, ELECTRON_REPO, ElectronReleaseRepo, NIGHTLY_REPO } from './types';
|
2024-10-01 10:04:22 +00:00
|
|
|
|
|
|
|
const temp = trackTemp();
|
2020-03-20 20:28:31 +00:00
|
|
|
|
2024-10-01 18:09:28 +00:00
|
|
|
const pass = chalk.green('✓');
|
|
|
|
const fail = chalk.red('✗');
|
2020-03-20 20:28:31 +00:00
|
|
|
|
2022-10-25 06:44:43 +00:00
|
|
|
const pkgVersion = `v${getElectronVersion()}`;
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
function getRepo (): ElectronReleaseRepo {
|
|
|
|
return pkgVersion.indexOf('nightly') > 0 ? NIGHTLY_REPO : ELECTRON_REPO;
|
2024-05-31 17:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const targetRepo = getRepo();
|
2019-01-08 20:05:58 +00:00
|
|
|
let failureCount = 0;
|
2017-10-23 15:02:50 +00:00
|
|
|
|
2024-09-23 18:07:20 +00:00
|
|
|
const octokit = new Octokit({
|
|
|
|
authStrategy: createGitHubTokenStrategy(targetRepo)
|
|
|
|
});
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function getDraftRelease (
|
|
|
|
version?: string,
|
|
|
|
skipValidation: boolean = false
|
|
|
|
) {
|
2019-01-08 20:05:58 +00:00
|
|
|
const releaseInfo = await octokit.repos.listReleases({
|
2024-10-01 21:08:15 +00:00
|
|
|
owner: ELECTRON_ORG,
|
2019-01-08 20:05:58 +00:00
|
|
|
repo: targetRepo
|
|
|
|
});
|
|
|
|
|
|
|
|
const versionToCheck = version || pkgVersion;
|
2024-10-01 10:04:22 +00:00
|
|
|
const drafts = releaseInfo.data.filter((release) => {
|
2019-01-08 20:05:58 +00:00
|
|
|
return release.tag_name === versionToCheck && release.draft === true;
|
|
|
|
});
|
|
|
|
|
2017-10-23 15:02:50 +00:00
|
|
|
const draft = drafts[0];
|
|
|
|
if (!skipValidation) {
|
|
|
|
failureCount = 0;
|
2019-01-23 19:47:36 +00:00
|
|
|
check(drafts.length === 1, 'one draft exists', true);
|
2023-07-24 10:32:54 +00:00
|
|
|
if (versionToCheck.includes('beta')) {
|
2019-01-23 19:47:36 +00:00
|
|
|
check(draft.prerelease, 'draft is a prerelease');
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
2024-10-01 10:04:22 +00:00
|
|
|
check(
|
|
|
|
!!draft.body &&
|
|
|
|
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
|
|
|
}
|
|
|
|
return draft;
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
type MinimalRelease = {
|
|
|
|
id: number;
|
|
|
|
tag_name: string;
|
|
|
|
draft: boolean;
|
|
|
|
prerelease: boolean;
|
|
|
|
assets: {
|
|
|
|
name: string;
|
|
|
|
browser_download_url: string;
|
|
|
|
id: number;
|
|
|
|
}[];
|
|
|
|
};
|
|
|
|
|
|
|
|
async function validateReleaseAssets (
|
|
|
|
release: MinimalRelease,
|
|
|
|
validatingRelease: boolean = false
|
|
|
|
) {
|
|
|
|
const requiredAssets = assetsForVersion(
|
|
|
|
release.tag_name,
|
|
|
|
validatingRelease
|
|
|
|
).sort();
|
|
|
|
const extantAssets = release.assets.map((asset) => asset.name).sort();
|
|
|
|
const downloadUrls = release.assets
|
|
|
|
.map((asset) => ({ url: asset.browser_download_url, file: asset.name }))
|
|
|
|
.sort((a, b) => a.file.localeCompare(b.file));
|
2017-10-23 15:02:50 +00:00
|
|
|
|
|
|
|
failureCount = 0;
|
2023-08-31 14:36:43 +00:00
|
|
|
for (const asset of requiredAssets) {
|
2017-10-23 15:02:50 +00:00
|
|
|
check(extantAssets.includes(asset), asset);
|
2023-08-31 14:36:43 +00:00
|
|
|
}
|
2024-10-01 10:04:22 +00:00
|
|
|
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) {
|
2021-05-11 16:30:35 +00:00
|
|
|
await verifyDraftGitHubReleaseAssets(release);
|
2018-02-22 13:53:32 +00:00
|
|
|
} else {
|
2024-10-01 10:04:22 +00:00
|
|
|
await verifyShasumsForRemoteFiles(downloadUrls).catch((err) => {
|
|
|
|
console.error(`${fail} error verifyingShasums`, err);
|
|
|
|
});
|
2018-02-22 13:53:32 +00:00
|
|
|
}
|
2022-04-04 09:32:57 +00:00
|
|
|
const azRemoteFiles = azRemoteFilesForVersion(release.tag_name);
|
2022-04-27 17:37:26 +00:00
|
|
|
await verifyShasumsForRemoteFiles(azRemoteFiles, true);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
function check (condition: boolean, statement: string, exitIfFail = false) {
|
2017-10-23 15:02:50 +00:00
|
|
|
if (condition) {
|
|
|
|
console.log(`${pass} ${statement}`);
|
|
|
|
} else {
|
|
|
|
failureCount++;
|
2023-06-07 23:49:12 +00:00
|
|
|
console.error(`${fail} ${statement}`);
|
2017-10-23 15:02:50 +00:00
|
|
|
if (exitIfFail) process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
function assetsForVersion (version: string, validatingRelease: boolean) {
|
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-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`,
|
2022-03-07 23:47:58 +00:00
|
|
|
`electron-${version}-darwin-x64-dsym-snapshot.zip`,
|
2017-10-23 15:02:50 +00:00
|
|
|
`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`,
|
2022-03-07 23:47:58 +00:00
|
|
|
`electron-${version}-darwin-arm64-dsym-snapshot.zip`,
|
2020-07-21 11:55:00 +00:00
|
|
|
`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`,
|
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`,
|
2022-03-07 23:47:58 +00:00
|
|
|
`electron-${version}-mas-x64-dsym-snapshot.zip`,
|
2017-10-23 15:02:50 +00:00
|
|
|
`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`,
|
2022-03-07 23:47:58 +00:00
|
|
|
`electron-${version}-mas-arm64-dsym-snapshot.zip`,
|
2020-07-21 11:55:00 +00:00
|
|
|
`electron-${version}-mas-arm64-symbols.zip`,
|
|
|
|
`electron-${version}-mas-arm64.zip`,
|
2022-07-27 04:33:07 +00:00
|
|
|
`electron-${version}-win32-ia32-pdb.zip`,
|
|
|
|
`electron-${version}-win32-ia32-symbols.zip`,
|
2017-10-23 15:02:50 +00:00
|
|
|
`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',
|
2021-05-22 18:48:38 +00:00
|
|
|
'libcxx_headers.zip',
|
|
|
|
'libcxxabi_headers.zip',
|
|
|
|
`libcxx-objects-${version}-linux-arm64.zip`,
|
|
|
|
`libcxx-objects-${version}-linux-armv7l.zip`,
|
|
|
|
`libcxx-objects-${version}-linux-x64.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-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-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`
|
2017-10-23 15:02:50 +00:00
|
|
|
];
|
2018-01-31 23:40:38 +00:00
|
|
|
if (!validatingRelease) {
|
|
|
|
patterns.push('SHASUMS256.txt');
|
|
|
|
}
|
2017-10-23 15:02:50 +00:00
|
|
|
return patterns;
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
const cloudStoreFilePaths = (version: string) => [
|
2022-04-04 09:32:57 +00:00
|
|
|
`iojs-${version}-headers.tar.gz`,
|
|
|
|
`iojs-${version}.tar.gz`,
|
|
|
|
`node-${version}.tar.gz`,
|
|
|
|
'node.lib',
|
|
|
|
'x64/node.lib',
|
|
|
|
'win-x64/iojs.lib',
|
|
|
|
'win-x86/iojs.lib',
|
|
|
|
'win-arm64/iojs.lib',
|
|
|
|
'win-x64/node.lib',
|
|
|
|
'win-x86/node.lib',
|
|
|
|
'win-arm64/node.lib',
|
|
|
|
'arm64/node.lib',
|
|
|
|
'SHASUMS.txt',
|
|
|
|
'SHASUMS256.txt'
|
|
|
|
];
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
function azRemoteFilesForVersion (version: string) {
|
2022-04-04 09:32:57 +00:00
|
|
|
const azCDN = 'https://artifacts.electronjs.org/headers/';
|
|
|
|
const versionPrefix = `${azCDN}dist/${version}/`;
|
|
|
|
return cloudStoreFilePaths(version).map((filePath) => ({
|
2021-05-11 16:30:35 +00:00
|
|
|
file: filePath,
|
|
|
|
url: `${versionPrefix}${filePath}`
|
|
|
|
}));
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
function runScript (scriptName: string, scriptArgs: string[], cwd?: string) {
|
2018-10-02 01:56:31 +00:00
|
|
|
const scriptCommand = `${scriptName} ${scriptArgs.join(' ')}`;
|
2024-10-01 10:04:22 +00:00
|
|
|
const scriptOptions: ExecSyncOptions = {
|
|
|
|
encoding: 'utf-8'
|
2017-10-23 15:02:50 +00:00
|
|
|
};
|
2019-01-08 20:05:58 +00:00
|
|
|
if (cwd) scriptOptions.cwd = cwd;
|
2017-10-23 15:02:50 +00:00
|
|
|
try {
|
|
|
|
return execSync(scriptCommand, scriptOptions);
|
|
|
|
} catch (err) {
|
2023-06-07 23:49:12 +00:00
|
|
|
console.error(`${fail} Error running ${scriptName}`, err);
|
2017-10-23 15:02:50 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadNodeShasums () {
|
2022-04-04 09:32:57 +00:00
|
|
|
console.log('Uploading Node SHASUMS file to artifacts.electronjs.org.');
|
2024-10-01 10:04:22 +00:00
|
|
|
const scriptPath = join(
|
|
|
|
ELECTRON_DIR,
|
|
|
|
'script',
|
|
|
|
'release',
|
|
|
|
'uploaders',
|
|
|
|
'upload-node-checksums.py'
|
|
|
|
);
|
2017-10-23 15:02:50 +00:00
|
|
|
runScript(scriptPath, ['-v', pkgVersion]);
|
2024-10-01 10:04:22 +00:00
|
|
|
console.log(
|
|
|
|
`${pass} Done uploading Node SHASUMS file to artifacts.electronjs.org.`
|
|
|
|
);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function uploadIndexJson () {
|
2022-04-04 09:32:57 +00:00
|
|
|
console.log('Uploading index.json to artifacts.electronjs.org.');
|
2024-10-01 10:04:22 +00:00
|
|
|
const scriptPath = join(
|
|
|
|
ELECTRON_DIR,
|
|
|
|
'script',
|
|
|
|
'release',
|
|
|
|
'uploaders',
|
|
|
|
'upload-index-json.py'
|
|
|
|
);
|
2018-08-17 05:23:46 +00:00
|
|
|
runScript(scriptPath, [pkgVersion]);
|
2022-04-04 09:32:57 +00:00
|
|
|
console.log(`${pass} Done uploading index.json to artifacts.electronjs.org.`);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function mergeShasums (pkgVersion: string) {
|
2022-04-04 09:32:57 +00:00
|
|
|
// Download individual checksum files for Electron zip files from artifact storage,
|
2020-09-30 20:30:10 +00:00
|
|
|
// concatenate them, and upload to GitHub.
|
|
|
|
|
2022-04-04 09:32:57 +00:00
|
|
|
const connectionString = process.env.ELECTRON_ARTIFACTS_BLOB_STORAGE;
|
|
|
|
if (!connectionString) {
|
2024-10-01 10:04:22 +00:00
|
|
|
throw new Error(
|
|
|
|
'Please set the $ELECTRON_ARTIFACTS_BLOB_STORAGE environment variable'
|
|
|
|
);
|
2020-09-30 20:30:10 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
const blobServiceClient =
|
|
|
|
BlobServiceClient.fromConnectionString(connectionString);
|
|
|
|
const containerClient = blobServiceClient.getContainerClient(
|
|
|
|
'checksums-scratchpad'
|
|
|
|
);
|
2022-04-04 09:32:57 +00:00
|
|
|
const blobsIter = containerClient.listBlobsFlat({
|
|
|
|
prefix: `${pkgVersion}/`
|
2020-09-30 20:30:10 +00:00
|
|
|
});
|
|
|
|
const shasums = [];
|
2022-04-04 09:32:57 +00:00
|
|
|
for await (const blob of blobsIter) {
|
|
|
|
if (blob.name.endsWith('.sha256sum')) {
|
|
|
|
const blobClient = containerClient.getBlockBlobClient(blob.name);
|
|
|
|
const response = await blobClient.downloadToBuffer();
|
|
|
|
shasums.push(response.toString('ascii').trim());
|
2020-09-30 20:30:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return shasums.join('\n');
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function createReleaseShasums (release: MinimalRelease) {
|
2018-10-02 01:56:31 +00:00
|
|
|
const fileName = 'SHASUMS256.txt';
|
2024-10-01 10:04:22 +00:00
|
|
|
const existingAssets = release.assets.filter(
|
|
|
|
(asset) => asset.name === fileName
|
|
|
|
);
|
2017-10-23 15:02:50 +00:00
|
|
|
if (existingAssets.length > 0) {
|
2024-10-01 10:04:22 +00:00
|
|
|
console.log(
|
|
|
|
`${fileName} already exists on GitHub; deleting before creating new file.`
|
|
|
|
);
|
|
|
|
await octokit.repos
|
|
|
|
.deleteReleaseAsset({
|
2024-10-01 21:08:15 +00:00
|
|
|
owner: ELECTRON_ORG,
|
2024-10-01 10:04:22 +00:00
|
|
|
repo: targetRepo,
|
|
|
|
asset_id: existingAssets[0].id
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(`${fail} Error deleting ${fileName} on GitHub:`, err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
console.log(`Creating and uploading the release ${fileName}.`);
|
2020-09-30 20:30:10 +00:00
|
|
|
const checksums = await mergeShasums(pkgVersion);
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2017-10-23 15:02:50 +00:00
|
|
|
console.log(`${pass} Generated release SHASUMS.`);
|
2018-10-02 01:56:31 +00:00
|
|
|
const filePath = await saveShaSumFile(checksums, fileName);
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2017-10-23 15:02:50 +00:00
|
|
|
console.log(`${pass} Created ${fileName} file.`);
|
2019-01-08 20:05:58 +00:00
|
|
|
await uploadShasumFile(filePath, fileName, release.id);
|
|
|
|
|
2017-10-23 15:02:50 +00:00
|
|
|
console.log(`${pass} Successfully uploaded ${fileName} to GitHub.`);
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function uploadShasumFile (
|
|
|
|
filePath: string,
|
|
|
|
fileName: string,
|
|
|
|
releaseId: number
|
|
|
|
) {
|
2019-01-08 20:05:58 +00:00
|
|
|
const uploadUrl = `https://uploads.github.com/repos/electron/${targetRepo}/releases/${releaseId}/assets{?name,label}`;
|
2024-10-01 10:04:22 +00:00
|
|
|
return octokit.repos
|
|
|
|
.uploadReleaseAsset({
|
|
|
|
url: uploadUrl,
|
|
|
|
headers: {
|
|
|
|
'content-type': 'text/plain',
|
|
|
|
'content-length': statSync(filePath).size
|
|
|
|
},
|
|
|
|
data: createReadStream(filePath),
|
|
|
|
name: fileName
|
|
|
|
} as any)
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(`${fail} Error uploading ${filePath} to GitHub:`, err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
function saveShaSumFile (checksums: string, fileName: string) {
|
|
|
|
return new Promise<string>((resolve) => {
|
2017-10-23 15:02:50 +00:00
|
|
|
temp.open(fileName, (err, info) => {
|
|
|
|
if (err) {
|
2023-06-07 23:49:12 +00:00
|
|
|
console.error(`${fail} Could not create ${fileName} file`);
|
2017-10-23 15:02:50 +00:00
|
|
|
process.exit(1);
|
|
|
|
} else {
|
2024-10-01 10:04:22 +00:00
|
|
|
writeFileSync(info.fd, checksums);
|
|
|
|
close(info.fd, (err) => {
|
2017-10-23 15:02:50 +00:00
|
|
|
if (err) {
|
2023-06-07 23:49:12 +00:00
|
|
|
console.error(`${fail} Could close ${fileName} file`);
|
2017-10-23 15:02:50 +00:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
resolve(info.path);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function publishRelease (release: MinimalRelease) {
|
2023-02-15 05:12:07 +00:00
|
|
|
let makeLatest = false;
|
|
|
|
if (!release.prerelease) {
|
|
|
|
const currentLatest = await octokit.repos.getLatestRelease({
|
2024-10-01 21:08:15 +00:00
|
|
|
owner: ELECTRON_ORG,
|
2023-02-15 05:12:07 +00:00
|
|
|
repo: targetRepo
|
|
|
|
});
|
2023-02-13 09:16:27 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
makeLatest = gte(release.tag_name, currentLatest.data.tag_name);
|
2023-02-15 05:12:07 +00:00
|
|
|
}
|
2023-02-13 09:16:27 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
return octokit.repos
|
|
|
|
.updateRelease({
|
2024-10-01 21:08:15 +00:00
|
|
|
owner: ELECTRON_ORG,
|
2024-10-01 10:04:22 +00:00
|
|
|
repo: targetRepo,
|
|
|
|
release_id: release.id,
|
|
|
|
tag_name: release.tag_name,
|
|
|
|
draft: false,
|
|
|
|
make_latest: makeLatest ? 'true' : 'false'
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(`${fail} Error publishing release:`, err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 21:08:15 +00:00
|
|
|
export async function validateRelease () {
|
|
|
|
console.log(`Validating release ${pkgVersion}`);
|
|
|
|
const release = await getDraftRelease(pkgVersion);
|
|
|
|
await validateReleaseAssets(release, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function makeRelease () {
|
|
|
|
let draftRelease = await getDraftRelease();
|
|
|
|
uploadNodeShasums();
|
|
|
|
await createReleaseShasums(draftRelease);
|
|
|
|
|
|
|
|
// Fetch latest version of release before verifying
|
|
|
|
draftRelease = await getDraftRelease(pkgVersion, true);
|
|
|
|
await validateReleaseAssets(draftRelease);
|
|
|
|
// index.json goes live once uploaded so do these uploads as
|
|
|
|
// late as possible to reduce the chances it contains a release
|
|
|
|
// which fails to publish. It has to be done before the final
|
|
|
|
// publish to ensure there aren't published releases not contained
|
|
|
|
// in index.json, which causes other problems in downstream projects
|
|
|
|
uploadIndexJson();
|
|
|
|
await publishRelease(draftRelease);
|
|
|
|
console.log(
|
|
|
|
`${pass} SUCCESS!!! Release has been published. Please run ` +
|
|
|
|
'"npm run publish-to-npm" to publish release to npm.'
|
|
|
|
);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 16:30:35 +00:00
|
|
|
const SHASUM_256_FILENAME = 'SHASUMS256.txt';
|
|
|
|
const SHASUM_1_FILENAME = 'SHASUMS.txt';
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function verifyDraftGitHubReleaseAssets (release: MinimalRelease) {
|
2021-05-11 16:30:35 +00:00
|
|
|
console.log('Fetching authenticated GitHub artifact URLs to verify shasums');
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
const remoteFilesToHash = await Promise.all(
|
|
|
|
release.assets.map(async (asset) => {
|
|
|
|
const requestOptions = octokit.repos.getReleaseAsset.endpoint({
|
2024-10-01 21:08:15 +00:00
|
|
|
owner: ELECTRON_ORG,
|
2024-10-01 10:04:22 +00:00
|
|
|
repo: targetRepo,
|
|
|
|
asset_id: asset.id,
|
|
|
|
headers: {
|
|
|
|
Accept: 'application/octet-stream'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const { url, headers } = requestOptions;
|
|
|
|
headers.authorization = `token ${
|
|
|
|
((await octokit.auth()) as { token: string }).token
|
|
|
|
}`;
|
|
|
|
|
|
|
|
const response = await got(url, {
|
|
|
|
followRedirect: false,
|
|
|
|
method: 'HEAD',
|
|
|
|
headers: headers as any,
|
|
|
|
throwHttpErrors: false
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response.statusCode !== 302 && response.statusCode !== 301) {
|
|
|
|
console.error('Failed to HEAD github asset: ' + url);
|
|
|
|
throw new Error(
|
|
|
|
"Unexpected status HEAD'ing github asset: " + response.statusCode
|
|
|
|
);
|
2019-01-23 19:47:36 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
return { url: response.headers.location!, file: asset.name };
|
|
|
|
})
|
|
|
|
).catch((err) => {
|
2023-06-07 23:49:12 +00:00
|
|
|
console.error(`${fail} Error downloading files from GitHub`, err);
|
2017-10-23 15:02:50 +00:00
|
|
|
process.exit(1);
|
|
|
|
});
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2021-05-11 16:30:35 +00:00
|
|
|
await verifyShasumsForRemoteFiles(remoteFilesToHash);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function getShaSumMappingFromUrl (
|
|
|
|
shaSumFileUrl: string,
|
|
|
|
fileNamePrefix: string
|
|
|
|
) {
|
2024-09-17 22:27:27 +00:00
|
|
|
const response = await got(shaSumFileUrl, {
|
|
|
|
throwHttpErrors: false
|
|
|
|
});
|
|
|
|
|
|
|
|
if (response.statusCode !== 200) {
|
|
|
|
console.error('Failed to fetch SHASUM mapping: ' + shaSumFileUrl);
|
|
|
|
console.error('Bad SHASUM mapping response: ' + response.body.trim());
|
2024-10-01 10:04:22 +00:00
|
|
|
throw new Error(
|
|
|
|
'Unexpected status fetching SHASUM mapping: ' + response.statusCode
|
|
|
|
);
|
2024-09-17 22:27:27 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 16:30:35 +00:00
|
|
|
const raw = response.body;
|
2024-10-01 10:04:22 +00:00
|
|
|
return raw
|
|
|
|
.split('\n')
|
|
|
|
.map((line) => line.trim())
|
|
|
|
.filter(Boolean)
|
|
|
|
.reduce((map, line) => {
|
|
|
|
const [sha, file] = line.replace(' ', ' ').split(' ');
|
|
|
|
map[file.slice(fileNamePrefix.length)] = sha;
|
|
|
|
return map;
|
|
|
|
}, Object.create(null) as Record<string, string>);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
type HashedFile = HashableFile & {
|
|
|
|
hash: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
type HashableFile = {
|
|
|
|
file: string;
|
|
|
|
url: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
async function validateFileHashesAgainstShaSumMapping (
|
|
|
|
remoteFilesWithHashes: HashedFile[],
|
|
|
|
mapping: Record<string, string>
|
|
|
|
) {
|
2021-05-11 16:30:35 +00:00
|
|
|
for (const remoteFileWithHash of remoteFilesWithHashes) {
|
2024-10-01 10:04:22 +00:00
|
|
|
check(
|
|
|
|
remoteFileWithHash.hash === mapping[remoteFileWithHash.file],
|
|
|
|
`Release asset ${remoteFileWithHash.file} should have hash of ${
|
|
|
|
mapping[remoteFileWithHash.file]
|
|
|
|
} but found ${remoteFileWithHash.hash}`,
|
|
|
|
true
|
|
|
|
);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
async function verifyShasumsForRemoteFiles (
|
|
|
|
remoteFilesToHash: HashableFile[],
|
|
|
|
filesAreNodeJSArtifacts = false
|
|
|
|
) {
|
|
|
|
console.log(
|
|
|
|
`Generating SHAs for ${remoteFilesToHash.length} files to verify shasums`
|
|
|
|
);
|
2021-05-11 16:30:35 +00:00
|
|
|
|
|
|
|
// Only used for node.js artifact uploads
|
2024-10-01 10:04:22 +00:00
|
|
|
const shaSum1File = remoteFilesToHash.find(
|
|
|
|
({ file }) => file === SHASUM_1_FILENAME
|
|
|
|
)!;
|
2021-05-11 16:30:35 +00:00
|
|
|
// Used for both node.js artifact uploads and normal electron artifacts
|
2024-10-01 10:04:22 +00:00
|
|
|
const shaSum256File = remoteFilesToHash.find(
|
|
|
|
({ file }) => file === SHASUM_256_FILENAME
|
|
|
|
)!;
|
|
|
|
remoteFilesToHash = remoteFilesToHash.filter(
|
|
|
|
({ file }) => file !== SHASUM_1_FILENAME && file !== SHASUM_256_FILENAME
|
|
|
|
);
|
|
|
|
|
|
|
|
const remoteFilesWithHashes = await Promise.all(
|
|
|
|
remoteFilesToHash.map(async (file) => {
|
2021-05-11 16:30:35 +00:00
|
|
|
return {
|
2024-10-01 10:04:22 +00:00
|
|
|
hash: await getUrlHash(file.url, 'sha256'),
|
2021-05-11 16:30:35 +00:00
|
|
|
...file
|
|
|
|
};
|
2024-10-01 10:04:22 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await validateFileHashesAgainstShaSumMapping(
|
|
|
|
remoteFilesWithHashes,
|
|
|
|
await getShaSumMappingFromUrl(
|
|
|
|
shaSum256File.url,
|
|
|
|
filesAreNodeJSArtifacts ? '' : '*'
|
|
|
|
)
|
|
|
|
);
|
2021-05-11 16:30:35 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
if (filesAreNodeJSArtifacts) {
|
|
|
|
const remoteFilesWithSha1Hashes = await Promise.all(
|
|
|
|
remoteFilesToHash.map(async (file) => {
|
|
|
|
return {
|
|
|
|
hash: await getUrlHash(file.url, 'sha1'),
|
|
|
|
...file
|
|
|
|
};
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
await validateFileHashesAgainstShaSumMapping(
|
|
|
|
remoteFilesWithSha1Hashes,
|
|
|
|
await getShaSumMappingFromUrl(
|
|
|
|
shaSum1File.url,
|
|
|
|
filesAreNodeJSArtifacts ? '' : '*'
|
|
|
|
)
|
|
|
|
);
|
2021-05-11 16:30:35 +00:00
|
|
|
}
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|