Skip to content

Commit c5f4b29

Browse files
committed
Restructure release process
1 parent 05a59b9 commit c5f4b29

File tree

2 files changed

+113
-40
lines changed

2 files changed

+113
-40
lines changed

scripts/release.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* eslint-disable no-console */
2+
// scripts/release.js
3+
const { execSync } = require('child_process');
4+
const fs = require('fs');
5+
const readline = require('readline');
6+
const chalk = require('chalk');
7+
const which = require('which');
8+
9+
// Function to get the current version from package.json
10+
function getCurrentVersion() {
11+
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
12+
return packageJson.version;
13+
}
14+
15+
// Function to prompt user for confirmation
16+
function promptUser(question) {
17+
const rl = readline.createInterface({
18+
input: process.stdin,
19+
output: process.stdout,
20+
});
21+
22+
return new Promise((resolve) => {
23+
rl.question(question, (answer) => {
24+
rl.close();
25+
resolve(answer);
26+
});
27+
});
28+
}
29+
30+
// Main function to run the release process
31+
async function release() {
32+
const currVersion = getCurrentVersion();
33+
console.log('');
34+
35+
const choice = await promptUser(
36+
`Publish a release for deadbolt v${currVersion}? (y/N) `,
37+
);
38+
if (!['y', 'Y'].includes(choice)) {
39+
console.log(chalk.yellow('Aborting!'));
40+
process.exit();
41+
}
42+
43+
/**
44+
* This whole section depends on execSync throwing if a process times out or has a non-zero exit code
45+
*/
46+
47+
// Check for unpushed changes
48+
try {
49+
execSync('git status --porcelain', { stdio: 'ignore' });
50+
} catch (error) {
51+
console.log(
52+
chalk.red(
53+
'Error: You have uncommitted changes. Please commit or stash them before releasing.',
54+
),
55+
);
56+
process.exit(1);
57+
}
58+
59+
// Check for unpushed commits
60+
try {
61+
execSync('git log @{u}..', { stdio: 'ignore' });
62+
} catch (error) {
63+
console.log(
64+
chalk.red(
65+
'Error: You have unpushed commits. Please push them before releasing.',
66+
),
67+
);
68+
process.exit(1);
69+
}
70+
71+
// Build electron app for Linux, Windows and macOS
72+
try {
73+
execSync('npm run package');
74+
} catch (error) {
75+
console.log(chalk.red('`$ npm run package` failed!'));
76+
console.error(chalk.red('Error during build process:'), error);
77+
console.log(chalk.red('Release stopped.'));
78+
process.exit(1);
79+
}
80+
81+
// Push new releases to GitHub
82+
try {
83+
which.sync('gh');
84+
} catch (error) {
85+
console.log(
86+
chalk.red(
87+
'Error: GitHub CLI (gh) is not installed. Please install it before releasing.',
88+
),
89+
);
90+
process.exit(1);
91+
}
92+
93+
execSync(
94+
`gh release create "v${currVersion}" --target main --generate-notes`,
95+
);
96+
97+
console.log(
98+
chalk.green(
99+
'Make sure to update the Homebrew tap, and any other package managers with the new release.\nA GitHub Action will be triggered to update the .',
100+
),
101+
);
102+
}
103+
104+
// Run the release process
105+
release()
106+
.then(() => {
107+
console.log(chalk.green('Release completed successfully!'));
108+
process.exit(0);
109+
})
110+
.catch((err) => {
111+
console.error(err);
112+
process.exit(1);
113+
});

scripts/release.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)