build: cleanup release scripts, separate cli entrypoints from logic (#44082)
* build: cleanup release scripts, separate cli entrypoints from logic Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> * build: use repo/org constants Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
This commit is contained in:
parent
7b14a305f8
commit
6074f7ed31
17 changed files with 410 additions and 300 deletions
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue