Skip to content

Commit 10ac089

Browse files
authored
Merge pull request #377 from HarperFast/improve-publish
Bump versions on publish using release tag
2 parents c4c74da + f760933 commit 10ac089

File tree

3 files changed

+101
-64
lines changed

3 files changed

+101
-64
lines changed

.github/workflows/publish.yml

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
preflight:
1313
name: Preflight
1414
runs-on: ubuntu-latest
15+
outputs:
16+
version: ${{ steps.version.outputs.version }}
1517
steps:
1618
- name: Checkout repository
1719
uses: actions/checkout@v6
@@ -27,16 +29,27 @@ jobs:
2729
node-version: 24
2830
registry-url: 'https://registry.npmjs.org'
2931

32+
- name: Determine version from the release tag
33+
id: version
34+
shell: bash
35+
run: |
36+
set -e
37+
set -o pipefail
38+
echo "Tag: ${{ github.event.release.tag_name }}"
39+
VERSION=$(echo "${{ github.event.release.tag_name }}" | sed 's/^v//')
40+
echo "Version: $VERSION"
41+
if ! pnpm semver $VERSION; then
42+
echo "ERROR: Invalid version $VERSION"
43+
exit 1
44+
fi
45+
echo "version=$VERSION" >> $GITHUB_OUTPUT
46+
3047
- name: Install dependencies
3148
shell: bash
3249
env:
3350
GH_TOKEN: ${{ secrets.GH_TOKEN }}
3451
run: pnpm install --ignore-scripts --no-frozen-lockfile
3552

36-
- name: Check versions
37-
shell: bash
38-
run: node scripts/check-versions.mjs
39-
4053
- name: Build
4154
env:
4255
GH_TOKEN: ${{ secrets.GH_TOKEN }}
@@ -157,13 +170,34 @@ jobs:
157170
shell: bash
158171
run: find artifacts -ls
159172

173+
- name: Bump versions
174+
shell: bash
175+
run: node scripts/bump-versions.mjs ${{ needs.preflight.outputs.version }}
176+
177+
- name: Configure git
178+
shell: bash
179+
env:
180+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
181+
run: |
182+
git config user.name "github-actions[bot]"
183+
git config user.email "github-actions[bot]@users.noreply.github.com"
184+
git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git
185+
186+
- name: Commit package.json
187+
shell: bash
188+
run: |
189+
set -e
190+
set -o pipefail
191+
git add package.json
192+
git commit -m "v${{ needs.preflight.outputs.version }}"
193+
git push origin main
194+
160195
- name: Get package.json info
161196
id: get-package-info
162197
shell: bash
163198
run: |
164199
echo "name=$(node -p "require('./package.json').name")" >> $GITHUB_OUTPUT
165200
echo "homepage=$(node -p "require('./package.json').homepage")" >> $GITHUB_OUTPUT
166-
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
167201
168202
- name: Publish bindings to npm
169203
env:
@@ -178,6 +212,30 @@ jobs:
178212
shell: bash
179213
run: pnpm publish --access public --no-git-checks --tag ${{ github.event.release.prerelease && 'next' || 'latest' }}
180214

215+
- name: Wait for npm to publish
216+
shell: bash
217+
timeout-minutes: 5
218+
run: |
219+
sleep 10
220+
while ! pnpm view ${{ steps.get-package-info.outputs.name }}@${{ needs.preflight.outputs.version }} > /dev/null 2>&1; do
221+
echo "Waiting for npm to publish ${{ steps.get-package-info.outputs.name }}@${{ needs.preflight.outputs.version }}..."
222+
sleep 10
223+
done
224+
echo "npm has published ${{ steps.get-package-info.outputs.name }}@${{ needs.preflight.outputs.version }}"
225+
226+
- name: Update pnpm-lock.yaml
227+
env:
228+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
229+
shell: bash
230+
run: pnpm install
231+
232+
- name: Commit pnpm-lock.yaml
233+
shell: bash
234+
run: |
235+
git add pnpm-lock.yaml
236+
git commit -m "chore(package): update pnpm-lock.yaml after publishing ${{ needs.preflight.outputs.version }}"
237+
git push origin main
238+
181239
- name: Send Slack notification
182240
uses: slackapi/slack-github-action@v2.0.0
183241
with:
@@ -186,20 +244,20 @@ jobs:
186244
payload: |
187245
{
188246
"channel": "${{ secrets.SLACK_CHANNEL_ID }}",
189-
"text": "Published ${{ steps.get-package-info.outputs.name }}@${{ steps.get-package-info.outputs.version }}",
247+
"text": "Published ${{ steps.get-package-info.outputs.name }}@${{ needs.preflight.outputs.version }}",
190248
"blocks": [
191249
{
192250
"type": "header",
193251
"text": {
194252
"type": "plain_text",
195-
"text": "Published ${{ steps.get-package-info.outputs.name }}@${{ steps.get-package-info.outputs.version }}"
253+
"text": "Published ${{ steps.get-package-info.outputs.name }}@${{ needs.preflight.outputs.version }}"
196254
}
197255
},
198256
{
199257
"type": "section",
200258
"text": {
201259
"type": "mrkdwn",
202-
"text": "https://github.com/HarperFast/rocksdb-prebuilds/releases/tag/v${{ steps.get-package-info.outputs.version }}"
260+
"text": "https://github.com/HarperFast/rocksdb-prebuilds/releases/tag/v${{ needs.preflight.outputs.version }}"
203261
}
204262
}
205263
]

scripts/bump-versions.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { readFileSync, writeFileSync } from 'node:fs';
2+
import { dirname, resolve } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import semver from 'semver';
5+
6+
if (process.argv.length < 3) {
7+
console.error('Usage: node scripts/bump-versions.mjs <new-version>');
8+
process.exit(1);
9+
}
10+
11+
const __dirname = fileURLToPath(dirname(import.meta.url));
12+
const packageJson = JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json'), 'utf8'));
13+
const currentVersion = packageJson.version;
14+
const newVersion = process.argv[2];
15+
16+
if (!semver.valid(newVersion)) {
17+
console.error(`ERROR: Invalid version "${newVersion}"`);
18+
process.exit(1);
19+
}
20+
21+
if (semver.lte(newVersion, currentVersion)) {
22+
console.error(`ERROR: New version ${newVersion} is less than current version ${currentVersion}`);
23+
process.exit(1);
24+
}
25+
26+
packageJson.version = newVersion;
27+
for (const key of Object.keys(packageJson.optionalDependencies)) {
28+
if (key.startsWith(packageJson.name)) {
29+
packageJson.optionalDependencies[key] = newVersion;
30+
}
31+
}
32+
33+
writeFileSync(resolve(__dirname, '..', 'package.json'), JSON.stringify(packageJson, null, 2));
34+
35+
console.log(`🎉 Bumped version from ${currentVersion} to ${newVersion}`);

scripts/check-versions.mjs

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

0 commit comments

Comments
 (0)