Files
electron/script/release/release-artifact-cleanup.js
Keeley Hammond f2e2fc34f2 build: determine electron version from tags not files (#36137)
* build: determine electron version from tags not files (#36106)

* build: determine electron version from tags not files

* build: make electron_version dependent on packed-refs and git HEAD

* build: do not delete electron/.git

* build: do not revert a commit we didn't make

* build: gen version file instead of just writing it

* build: update cache and ninja targets

* build: copy resource.h to generated electron.rc

* build: electron_win32_resources should be public deps

* build: also copy the icon

Co-authored-by: MarshallOfSound <marshallofsound@electronjs.org>

* chore: fixup patches

* chore: update patches

* build: ensure get-version runs in the electron git checkout (#36128)

* build: strip v in the getElectronVersion helper

* build: use npm@7 for npm view command

Co-authored-by: Samuel Attard <sam@electronjs.org>
Co-authored-by: MarshallOfSound <marshallofsound@electronjs.org>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: Samuel Attard <sattard@salesforce.com>
2022-10-30 15:38:01 -07:00

88 lines
2.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
if (!process.env.CI) require('dotenv-safe').load();
const args = require('minimist')(process.argv.slice(2), {
string: ['tag', 'releaseID'],
default: { releaseID: '' }
});
const { execSync } = require('child_process');
const { GitProcess } = require('dugite');
const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils.js');
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({
auth: process.env.ELECTRON_GITHUB_TOKEN
});
require('colors');
const pass = '✓'.green;
const fail = '✗'.red;
async function deleteDraft (releaseId, targetRepo) {
try {
const result = await octokit.repos.getRelease({
owner: 'electron',
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',
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, targetRepo) {
try {
await octokit.git.deleteRef({
owner: 'electron',
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 = args.releaseID.length > 0 ? args.releaseID : null;
const isNightly = args.tag.includes('nightly');
if (releaseId) {
if (isNightly) {
await deleteDraft(releaseId, 'nightlies');
// We only need to delete the Electron tag since the
// nightly tag is only created at publish-time.
await deleteTag(args.tag, 'electron');
} else {
const deletedElectronDraft = await deleteDraft(releaseId, 'electron');
// don't delete tag unless draft deleted successfully
if (deletedElectronDraft) {
await deleteTag(args.tag, 'electron');
}
}
} else {
await Promise.all([
deleteTag(args.tag, 'electron'),
deleteTag(args.tag, 'nightlies')
]);
}
console.log(`${pass} failed release artifact cleanup complete`);
}
cleanReleaseArtifacts();