Skip to content

Commit e44f40d

Browse files
committed
feat: add --remove option to delete tags and GitHub releases
1 parent d171cec commit e44f40d

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

scripts/release.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,52 @@ async function main() {
4141
const args = process.argv.slice(2);
4242

4343
if (args.includes('--help') || args.includes('-h')) {
44-
console.log('\n🚀 Plexus Release Script');
44+
console.log('\nPlexus Release Script');
4545
console.log('--------------------------');
4646
console.log('\nUsage:');
4747
console.log(` bun scripts/release.ts [options]`);
4848
console.log('\nOptions:');
49-
console.log(' --help, -h Show this help message');
49+
console.log(' --help, -h Show this help message');
50+
console.log(' --remove <tag> Delete tag locally, remotely, and its GitHub release');
5051
console.log(
5152
'\nUses CalVer (YYYY.MM.DD.N) format. Release notes are handled by GitHub Actions.\n'
5253
);
5354
process.exit(0);
5455
}
5556

56-
console.log('\n🚀 Plexus Release Process');
57+
const removeIndex = args.indexOf('--remove');
58+
if (removeIndex !== -1) {
59+
const tag = args[removeIndex + 1];
60+
if (!tag) {
61+
console.error('--remove requires a tag argument');
62+
process.exit(1);
63+
}
64+
65+
console.log(`Removing tag and release: ${tag}`);
66+
67+
try {
68+
execSync(`git tag -d ${tag}`, { stdio: 'inherit' });
69+
} catch {
70+
console.warn(`Local tag ${tag} not found, skipping`);
71+
}
72+
73+
try {
74+
execSync(`git push origin :refs/tags/${tag}`, { stdio: 'inherit' });
75+
} catch {
76+
console.warn(`Remote tag ${tag} not found, skipping`);
77+
}
78+
79+
try {
80+
execSync(`gh release delete ${tag} --yes`, { stdio: 'inherit' });
81+
} catch {
82+
console.warn(`GitHub release for ${tag} not found, skipping`);
83+
}
84+
85+
console.log('Done.');
86+
process.exit(0);
87+
}
88+
89+
console.log('\nPlexus Release Process');
5790
console.log('--------------------------\n');
5891

5992
// Get GitHub token
@@ -119,7 +152,7 @@ async function main() {
119152
const owner = 'mcowger';
120153
const repo = 'plexus';
121154

122-
console.log('\n📦 Creating tag on remote main...');
155+
console.log('\nCreating tag on remote main...');
123156
try {
124157
// Get the latest commit SHA on main
125158
const { data: ref } = await octokit.request('GET /repos/{owner}/{repo}/git/ref/{ref}', {
@@ -129,7 +162,7 @@ async function main() {
129162
});
130163

131164
const mainSha = ref.object.sha;
132-
console.log(`📌 Target commit: ${mainSha.slice(0, 7)}`);
165+
console.log(`Target commit: ${mainSha.slice(0, 7)}`);
133166

134167
// Create the tag on the remote
135168
await octokit.request('POST /repos/{owner}/{repo}/git/refs', {
@@ -140,7 +173,7 @@ async function main() {
140173
});
141174

142175
console.log(`✅ Created tag ${version} at origin/main\n`);
143-
console.log('🎊 Release tag created! GitHub Actions will handle the rest.\n');
176+
console.log('Release tag created! GitHub Actions will handle the rest.\n');
144177
} catch (e) {
145178
console.error('\n❌ GitHub API operation failed:', e);
146179
process.exit(1);

0 commit comments

Comments
 (0)