Skip to content

Commit 99ecb6b

Browse files
authored
Release automation, take 3. (#102)
* Fix changeset version command, attempt 2. Since this isn't parsed by a shell, the quotes don't work. 🤦 * Add missing version-script.ts file. This was referenced from the prerelease job but didn't make it into the original PR.
1 parent 46180b9 commit 99ecb6b

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

.github/changeset-version.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/sh
2+
# This script is called by the changeset action in release.yml.
3+
4+
set -e
5+
6+
npx changeset version
7+
8+
# The standard step is only to run `changeset version` but this does not update the
9+
# package-lock.json file. So we also run `npm install`, which does this update.
10+
# This is a workaround until this is handled automatically by `changeset version`.
11+
# See https://github.com/changesets/changesets/issues/421.
12+
npm install

.github/version-script.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as fs from "node:fs";
2+
import { execSync } from "node:child_process";
3+
async function main() {
4+
try {
5+
console.log("Getting current git hash...");
6+
const stdout = execSync("git rev-parse --short HEAD").toString();
7+
console.log("Git hash:", stdout.trim());
8+
9+
const path = "./package.json";
10+
const packageJson = JSON.parse(fs.readFileSync(path, "utf-8"));
11+
packageJson.version = `0.0.0-${stdout.trim()}`;
12+
fs.writeFileSync(path, `${JSON.stringify(packageJson, null, 2)}\n`);
13+
} catch (error) {
14+
console.error(error);
15+
process.exit(1);
16+
}
17+
}
18+
19+
main().catch((err) => {
20+
// Build failures should fail
21+
console.error(err);
22+
process.exit(1);
23+
});

.github/workflows/release.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ jobs:
3434
- id: changesets
3535
uses: changesets/action@v1
3636
with:
37-
# The standard step is only to run `changeset version` but this does not update the
38-
# package-lock.json file. So we also run `npm install`, which does this update.
39-
# This is a workaround until this is handled automatically by `changeset version`.
40-
# See https://github.com/changesets/changesets/issues/421.
41-
version: bash -c 'npx changeset version && npm install'
37+
# Note that these commands are NOT interpreted by a shell, they are apparently only
38+
# split on whitespace and then passed directly to execvp(). Hence the need to indirect
39+
# through a shell script, ugh. :(
40+
version: ./github/changeset-version.sh
4241
publish: npx changeset publish
4342
env:
4443
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)