Skip to content

Commit a3beefa

Browse files
committed
ci: derive release version from tag
1 parent f199e9a commit a3beefa

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,48 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616

17+
- name: Validate and read release version
18+
id: version
19+
shell: bash
20+
run: |
21+
set -euo pipefail
22+
version="${GITHUB_REF_NAME#v}"
23+
[[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] \
24+
|| { echo "Tag '${GITHUB_REF_NAME}' must be a SemVer tag such as v1.2.3"; exit 1; }
25+
echo "version=${version}" >> "$GITHUB_OUTPUT"
26+
1727
- uses: oven-sh/setup-bun@v2
1828

1929
- run: bun install
2030

2131
- run: bun run build
32+
env:
33+
VERSION: ${{ steps.version.outputs.version }}
34+
35+
- name: Pack npm tarball
36+
id: npm-package
37+
env:
38+
VERSION: ${{ steps.version.outputs.version }}
39+
shell: bash
40+
run: |
41+
set -euo pipefail
42+
staging_dir="$(mktemp -d)"
43+
trap 'rm -rf "$staging_dir"' EXIT
44+
45+
cp package.json "$staging_dir/package.json"
46+
cp -R dist "$staging_dir/dist"
47+
node -e '
48+
const fs = require("fs");
49+
const path = process.argv[1];
50+
const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
51+
pkg.version = process.env.VERSION;
52+
fs.writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`);
53+
' "$staging_dir/package.json"
54+
55+
npm pack "$staging_dir" --pack-destination . --ignore-scripts
56+
tarball="mmx-cli-${VERSION}.tgz"
57+
test -f "$tarball"
58+
echo "path=${tarball}" >> "$GITHUB_OUTPUT"
2259
2360
- name: Create GitHub Release
2461
uses: softprops/action-gh-release@v2
@@ -33,6 +70,6 @@ jobs:
3370
registry-url: 'https://registry.npmjs.org'
3471

3572
- name: Publish to npm
36-
run: npm publish
73+
run: npm publish "${{ steps.npm-package.outputs.path }}" --ignore-scripts
3774
env:
3875
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mmx-cli",
3-
"version": "1.0.21",
3+
"version": "0.0.0-dev",
44
"description": "CLI for the MiniMax AI Platform",
55
"type": "module",
66
"repository": {

test/version.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import { spawnSync } from 'child_process';
44
import { CLI_VERSION } from '../src/version';
55

66
const packageVersion = (JSON.parse(readFileSync('package.json', 'utf-8')) as { version: string }).version;
7+
const DEVELOPMENT_VERSION = '0.0.0-dev';
78

89
describe('CLI version', () => {
9-
it('uses package.json as the source version when no build override is present', () => {
10-
expect(CLI_VERSION).toBe(packageVersion);
10+
it('uses the development package version when no build override is present', () => {
11+
expect(packageVersion).toBe(DEVELOPMENT_VERSION);
12+
expect(CLI_VERSION).toBe(DEVELOPMENT_VERSION);
1113
});
1214

13-
it('prints the package version in dev mode', () => {
15+
it('prints the development package version in dev mode', () => {
1416
const result = spawnSync(process.execPath, ['src/main.ts', '--version'], {
1517
cwd: process.cwd(),
1618
encoding: 'utf-8',
1719
});
1820

1921
expect(result.status).toBe(0);
20-
expect(result.stdout.trim()).toBe(`mmx ${packageVersion}`);
22+
expect(result.stdout.trim()).toBe(`mmx ${DEVELOPMENT_VERSION}`);
2123
});
2224
});

0 commit comments

Comments
 (0)