Skip to content

Commit d8a3dc8

Browse files
committed
chore: fix release script
Fix bad exec statements causing tags to be added before release commit is created(!). Switch to asyn/await to wait for child processes to complete.
1 parent 48d98ee commit d8a3dc8

File tree

3 files changed

+54
-42
lines changed

3 files changed

+54
-42
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v1
11+
- uses: actions/checkout@v2
1212
- uses: actions/setup-node@v1
1313
with:
1414
node-version: 12

prepare-release.js

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
const fs = require('fs');
44
const path = require('path');
55
const semver = require('semver');
6-
const { exec } = require('child_process');
6+
const util = require('util');
7+
const exec = util.promisify(require('child_process').exec);
78
const yesno = require('yesno');
89

910
if (process.argv.length < 3) {
@@ -19,26 +20,26 @@ if (semver.valid(version) == null) {
1920

2021
process.chdir(__dirname);
2122

22-
// Update package.json
23-
console.log('Updating package.json...');
24-
const pkg = JSON.parse(fs.readFileSync('./package.json').toString());
25-
if (!semver.gt(version, pkg.version)) {
26-
console.error(`New version ${version} is not greater than current version ${pkg.version}`);
27-
process.exit(1);
28-
}
29-
pkg.version = version;
30-
fs.writeFileSync('./package.json', `${JSON.stringify(pkg, null, ' ')}\n`);
23+
async function update() {
24+
// Update package.json
25+
console.log('Updating package.json...');
26+
const pkg = JSON.parse(fs.readFileSync('./package.json').toString());
27+
if (!semver.gt(version, pkg.version)) {
28+
console.error(`New version ${version} is not greater than current version ${pkg.version}`);
29+
process.exit(1);
30+
}
31+
pkg.version = version;
32+
fs.writeFileSync('./package.json', `${JSON.stringify(pkg, null, ' ')}\n`);
3133

32-
// Run standard-changelog
33-
console.log('Running standard-changelog...');
34-
exec('./node_modules/.bin/standard-changelog', err => {
35-
if (err) {
34+
// Run standard-changelog
35+
console.log('Running standard-changelog...');
36+
try {
37+
await exec('./node_modules/.bin/standard-changelog');
38+
} catch (err) {
3639
console.error(err);
3740
process.exit(1);
3841
}
39-
});
4042

41-
async function commitAndPush() {
4243
// Commit to git after prompting user
4344
let ok = await yesno({
4445
question: 'Commit changes to git and add tag (y/N)?',
@@ -50,18 +51,19 @@ async function commitAndPush() {
5051
process.exit(0);
5152
}
5253

53-
exec(`git commit -a -m "release: v${version}"`, err => {
54-
if (err) {
55-
console.error(err);
56-
process.exit(1);
57-
}
58-
});
59-
exec(`git tag "v${version}"`, err => {
60-
if (err) {
61-
console.error(err);
62-
process.exit(1);
63-
}
64-
});
54+
try {
55+
await exec(`git commit -a -m "release: v${version}"`);
56+
} catch (err) {
57+
console.error(err);
58+
process.exit(1);
59+
}
60+
61+
try {
62+
await exec(`git tag "v${version}"`);
63+
} catch (err) {
64+
console.error(err);
65+
process.exit(1);
66+
}
6567

6668
// Prompt to push to origin
6769
ok = await yesno({
@@ -74,19 +76,20 @@ async function commitAndPush() {
7476
process.exit(0);
7577
}
7678

77-
exec(`git push origin`, err => {
78-
if (err) {
79-
console.error(err);
80-
process.exit(1);
81-
}
82-
});
83-
exec(`git push origin --tags`, err => {
84-
if (err) {
85-
console.error(err);
86-
process.exit(1);
87-
}
88-
});
79+
try {
80+
await exec(`git push origin`);
81+
} catch (err) {
82+
console.error(err);
83+
process.exit(1);
84+
}
85+
86+
try {
87+
await exec(`git push origin --tags`);
88+
} catch (err) {
89+
console.error(err);
90+
process.exit(1);
91+
}
8992

9093
process.exit(0);
9194
}
92-
commitAndPush();
95+
update();

process/RELEASE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Publishing a new release
44

5+
### Step 1: Run `prepare-release.js`
6+
57
In the root directory run
68

79
```sh
@@ -16,5 +18,12 @@ This will
1618
- Prompt you to create a release commit and tag it with the version number
1719
- Prompt you to push the commit and tag to origin
1820

21+
### Steps 2: Create a release in Github
22+
23+
- Click on `Releases` tab and click on Tags (or go to https://github.com/vikerman/rollup-plugin-hoist-import-deps/tags)
24+
- Click on the newly created tag version name and click on `Edit release`
25+
- Set the version name to same as tag name
26+
- Click on `Publish release` to create a release.
27+
1928
This should in turn kick off the release Github Action at
2029
`.github/workflows/publish.yml`, which should publish the build to NPM.

0 commit comments

Comments
 (0)