build: convert all release scripts to typescript (#44060)
* build: run gha on tag not branch (#42490) * build: convert all release scripts to typescript (#44035) * build: convert all release scripts to typescript * fix test imports * build: fix version bumper export * refactor: use as const * spec: fix bad type spec * build: use ts-node to spawn the version-bumper (#44057) Missed this in the tsification, we should probably call this via API instead of spawning a sub-proc? * build: still colors
This commit is contained in:
parent
956677b66a
commit
2e84985439
22 changed files with 1173 additions and 779 deletions
110
script/release/release-artifact-cleanup.ts
Executable file
110
script/release/release-artifact-cleanup.ts
Executable file
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { parseArgs } from 'node:util';
|
||||
|
||||
import { createGitHubTokenStrategy } from './github-token';
|
||||
import { ELECTRON_ORG, ELECTRON_REPO, ElectronReleaseRepo, NIGHTLY_REPO } from './types';
|
||||
|
||||
const { values: { tag: _tag, releaseID } } = parseArgs({
|
||||
options: {
|
||||
tag: {
|
||||
type: 'string'
|
||||
},
|
||||
releaseID: {
|
||||
type: 'string',
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!_tag) {
|
||||
console.error('Missing --tag argument');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const tag = _tag;
|
||||
|
||||
require('colors');
|
||||
const pass = '✓'.green;
|
||||
const fail = '✗'.red;
|
||||
|
||||
async function deleteDraft (releaseId: string, targetRepo: ElectronReleaseRepo) {
|
||||
const octokit = new Octokit({
|
||||
authStrategy: createGitHubTokenStrategy(targetRepo)
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await octokit.repos.getRelease({
|
||||
owner: ELECTRON_ORG,
|
||||
repo: targetRepo,
|
||||
release_id: parseInt(releaseId, 10)
|
||||
});
|
||||
if (!result.data.draft) {
|
||||
console.log(`${fail} published releases cannot be deleted.`);
|
||||
return false;
|
||||
} else {
|
||||
await octokit.repos.deleteRelease({
|
||||
owner: ELECTRON_ORG,
|
||||
repo: targetRepo,
|
||||
release_id: result.data.id
|
||||
});
|
||||
}
|
||||
console.log(`${pass} successfully deleted draft with id ${releaseId} from ${targetRepo}`);
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error(`${fail} couldn't delete draft with id ${releaseId} from ${targetRepo}: `, err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteTag (tag: string, targetRepo: ElectronReleaseRepo) {
|
||||
const octokit = new Octokit({
|
||||
authStrategy: createGitHubTokenStrategy(targetRepo)
|
||||
});
|
||||
|
||||
try {
|
||||
await octokit.git.deleteRef({
|
||||
owner: ELECTRON_ORG,
|
||||
repo: targetRepo,
|
||||
ref: `tags/${tag}`
|
||||
});
|
||||
console.log(`${pass} successfully deleted tag ${tag} from ${targetRepo}`);
|
||||
} catch (err) {
|
||||
console.log(`${fail} couldn't delete tag ${tag} from ${targetRepo}: `, err);
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanReleaseArtifacts () {
|
||||
const releaseId = releaseID && releaseID.length > 0 ? releaseID : null;
|
||||
const isNightly = tag.includes('nightly');
|
||||
|
||||
if (releaseId) {
|
||||
if (isNightly) {
|
||||
await deleteDraft(releaseId, NIGHTLY_REPO);
|
||||
|
||||
// We only need to delete the Electron tag since the
|
||||
// nightly tag is only created at publish-time.
|
||||
await deleteTag(tag, ELECTRON_REPO);
|
||||
} else {
|
||||
const deletedElectronDraft = await deleteDraft(releaseId, ELECTRON_REPO);
|
||||
// don't delete tag unless draft deleted successfully
|
||||
if (deletedElectronDraft) {
|
||||
await deleteTag(tag, ELECTRON_REPO);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
await Promise.all([
|
||||
deleteTag(tag, ELECTRON_REPO),
|
||||
deleteTag(tag, NIGHTLY_REPO)
|
||||
]);
|
||||
}
|
||||
|
||||
console.log(`${pass} failed release artifact cleanup complete`);
|
||||
}
|
||||
|
||||
cleanReleaseArtifacts()
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue