Skip to content

Commit 476f8d8

Browse files
authored
chore: fix releasing package with next tag (#93)
1 parent 3f7d06c commit 476f8d8

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ jobs:
133133
uses: actions/download-artifact@v4
134134
with:
135135
path: release-artifacts
136+
- name: Prepare next release
137+
if: github.ref_type == 'branch'
138+
run: ./.scripts/prepare-next-release.ts ${{ github.run_number }} ${{ github.sha }}
136139
- name: Create npm dirs
137140
run: yarn napi create-npm-dir -t .
138141
- name: Move artifacts
@@ -150,26 +153,28 @@ jobs:
150153
omit-heading: true
151154
- run: 'cat ${{ steps.extract-changelog.outputs.output-file }}'
152155
- name: Release
156+
id: gh-release
153157
uses: softprops/action-gh-release@v2
154-
if: startsWith(github.ref, 'refs/tags/')
158+
if: github.ref_type == 'tag'
155159
with:
156160
body_path: ${{ steps.extract-changelog.outputs.output-file }}
157161
repository: toss/es-git
158162
generate_release_notes: false
159163
token: ${{ github.token }}
160164
- name: Publish
161-
if: |
162-
github.event_name == 'push' &&
163-
(github.ref_type == 'tag' || github.ref == 'refs/heads/main')
164165
run: |
165166
set -ex
166167
npm config set provenance true
167168
npm config set //registry.npmjs.org/:_authToken "$NPM_AUTH_TOKEN"
168169
npm whoami
169170
if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
171+
yarn napi prepublish -t npm --gh-release-id ${{ steps.gh-release.outputs.id }}
170172
npm publish --access public
171-
else
173+
elif [[ "$GITHUB_REF_TYPE" = "branch" ]]; then
174+
yarn napi prepublish -t npm --skip-gh-release
172175
npm publish --access public --tag next
176+
else
177+
echo "Skip publish"
173178
fi
174179
env:
175180
GITHUB_TOKEN: ${{ github.token }}

.scripts/prepare-next-release.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env -S node --no-warnings=ExperimentalWarning --experimental-strip-types
2+
import fs from 'node:fs/promises';
3+
import { EOL } from 'node:os';
4+
import path from 'node:path';
5+
import { fileURLToPath } from 'node:url';
6+
7+
const dirname = path.dirname(fileURLToPath(import.meta.url));
8+
const rootdir = path.join(dirname, '..');
9+
10+
const [, , build, commit] = process.argv;
11+
if (build == null || commit == null) {
12+
throw new Error('Invalid build/commit info');
13+
}
14+
15+
const pkgFilepath = path.join(rootdir, 'package.json');
16+
const pkg = JSON.parse(await fs.readFile(pkgFilepath, 'utf8'));
17+
pkg.version = `${pkg.version}-next.${build}+${commit.slice(0, 7)}`;
18+
19+
await fs.writeFile(pkgFilepath, `${JSON.stringify(pkg, null, 2)}${EOL}`, 'utf8');

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"benchmarks"
4141
],
4242
"scripts": {
43-
"prepublishOnly": "napi prepublish -t npm",
4443
"build": "napi build --platform --release --no-const-enum --pipe=\"yarn transform:dts\"",
4544
"build:debug": "DEBUG=\"napi:*\" napi build --platform --no-const-enum --pipe=\"yarn transform:dts\"",
4645
"transform:dts": "jscodeshift -t transforms/dts.mjs index.d.ts",

0 commit comments

Comments
 (0)