build: cleanup release scripts, separate cli entrypoints from logic (#44058)

* build: cleanup release scripts, separate cli entrypoints from logic

* build: use repo/org constants
This commit is contained in:
Samuel Attard 2024-10-01 13:51:40 -07:00 committed by GitHub
parent 15c8759ee0
commit f4ffd018e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 410 additions and 300 deletions

View file

@ -14,8 +14,7 @@ import { ELECTRON_DIR } from '../lib/utils';
import { getElectronVersion } from '../lib/get-version';
import { getUrlHash } from './get-url-hash';
import { createGitHubTokenStrategy } from './github-token';
import { ELECTRON_REPO, ElectronReleaseRepo, NIGHTLY_REPO } from './types';
import { parseArgs } from 'node:util';
import { ELECTRON_ORG, ELECTRON_REPO, ElectronReleaseRepo, NIGHTLY_REPO } from './types';
const temp = trackTemp();
@ -40,7 +39,7 @@ async function getDraftRelease (
skipValidation: boolean = false
) {
const releaseInfo = await octokit.repos.listReleases({
owner: 'electron',
owner: ELECTRON_ORG,
repo: targetRepo
});
@ -316,7 +315,7 @@ async function createReleaseShasums (release: MinimalRelease) {
);
await octokit.repos
.deleteReleaseAsset({
owner: 'electron',
owner: ELECTRON_ORG,
repo: targetRepo,
asset_id: existingAssets[0].id
})
@ -383,7 +382,7 @@ async function publishRelease (release: MinimalRelease) {
let makeLatest = false;
if (!release.prerelease) {
const currentLatest = await octokit.repos.getLatestRelease({
owner: 'electron',
owner: ELECTRON_ORG,
repo: targetRepo
});
@ -392,7 +391,7 @@ async function publishRelease (release: MinimalRelease) {
return octokit.repos
.updateRelease({
owner: 'electron',
owner: ELECTRON_ORG,
repo: targetRepo,
release_id: release.id,
tag_name: release.tag_name,
@ -405,36 +404,31 @@ async function publishRelease (release: MinimalRelease) {
});
}
async function makeRelease (releaseToValidate: string | boolean) {
if (releaseToValidate) {
if (releaseToValidate === true) {
releaseToValidate = pkgVersion;
} else {
console.log('Release to validate !=== true');
}
console.log(`Validating release ${releaseToValidate}`);
const release = await getDraftRelease(releaseToValidate);
await validateReleaseAssets(release, true);
} else {
let draftRelease = await getDraftRelease();
uploadNodeShasums();
await createReleaseShasums(draftRelease);
export async function validateRelease () {
console.log(`Validating release ${pkgVersion}`);
const release = await getDraftRelease(pkgVersion);
await validateReleaseAssets(release, true);
}
// 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.'
);
}
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.'
);
}
const SHASUM_256_FILENAME = 'SHASUMS256.txt';
@ -446,7 +440,7 @@ async function verifyDraftGitHubReleaseAssets (release: MinimalRelease) {
const remoteFilesToHash = await Promise.all(
release.assets.map(async (asset) => {
const requestOptions = octokit.repos.getReleaseAsset.endpoint({
owner: 'electron',
owner: ELECTRON_ORG,
repo: targetRepo,
asset_id: asset.id,
headers: {
@ -591,18 +585,3 @@ async function verifyShasumsForRemoteFiles (
);
}
}
const {
values: { validateRelease }
} = parseArgs({
options: {
validateRelease: {
type: 'boolean'
}
}
});
makeRelease(!!validateRelease).catch((err) => {
console.error('Error occurred while making release:', err);
process.exit(1);
});