Skip to content

Commit 43d08ab

Browse files
authored
Publish on update package.json version (#171)
Changes the release process from pushing a tag to automatically publishing when updating the version in `package.json`.
1 parent 1eea62a commit 43d08ab

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
1-
name: Release
1+
name: Publish
22

33
on:
4-
release:
5-
types: [published]
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'package.json'
69

710
permissions:
811
contents: read
912
id-token: write
1013

1114
jobs:
12-
publish:
15+
version-check:
1316
runs-on: ubuntu-latest
14-
environment: npm
17+
outputs:
18+
version_changed: ${{ steps.check.outputs.changed }}
19+
version: ${{ steps.check.outputs.version }}
1520
steps:
1621
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
1724

18-
- name: Validate version
25+
- name: Detect package.json version bump
26+
id: check
1927
run: |
20-
TAG_VERSION="${GITHUB_REF_NAME#v}"
21-
PKG_VERSION=$(node -p "require('./package.json').version")
22-
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
23-
echo "::error::Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)"
24-
exit 1
25-
fi
28+
set -euo pipefail
29+
NEW=$(node -p "require('./package.json').version")
30+
echo "version=${NEW}" >> "$GITHUB_OUTPUT"
31+
BEFORE="${{ github.event.before }}"
32+
OLD=$(git show "${BEFORE}:package.json" 2>/dev/null | jq -r .version 2>/dev/null) || OLD=""
33+
echo "changed=$([[ "$BEFORE" =~ ^0{40}$ || "$OLD" != "$NEW" ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"
34+
35+
publish:
36+
needs: version-check
37+
if: needs.version-check.outputs.version_changed == 'true'
38+
runs-on: ubuntu-latest
39+
environment: npm
40+
steps:
41+
- uses: actions/checkout@v4
2642

2743
- name: Setup Node.js
2844
uses: actions/setup-node@v4
@@ -40,7 +56,7 @@ jobs:
4056

4157
# Runs after npm publish; failures here do not affect the published package (re-run this job only if needed).
4258
notify-vscode-motoko:
43-
needs: publish
59+
needs: [publish, version-check]
4460
runs-on: ubuntu-latest
4561
steps:
4662
- name: Generate GitHub App token
@@ -59,4 +75,4 @@ jobs:
5975
token: ${{ steps.dispatch-token.outputs.token }}
6076
repository: caffeinelabs/vscode-motoko
6177
event-type: motoko-release
62-
client-payload: '{"version":"${{ github.event.release.tag_name }}"}'
78+
client-payload: '{"version":"v${{ needs.version-check.outputs.version }}"}'

RELEASING.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ with optional `moc_version` and `core_version` inputs. Leave them empty to auto-
2121

2222
## Publishing to npm
2323

24-
After merging a moc update (or any version bump), create a **GitHub Release**:
24+
After merging a moc update (or any version bump), bump the **`version`** field in `package.json` and merge to `main`.
2525

26-
1. Go to [Releases](https://github.com/caffeinelabs/node-motoko/releases/new)
27-
2. Create a new tag matching the `package.json` version (e.g. `v4.1.0`)
28-
3. Click "Publish release"
26+
The [`release`](.github/workflows/release.yml) workflow runs when `package.json` changes on `main`. If the **version** field changed compared to the previous commit on `main`, it will:
2927

30-
The [`release`](.github/workflows/release.yml) workflow will automatically:
31-
- Validate the tag matches `package.json`
3228
- Build and test
3329
- Publish to npm via [OIDC trusted publishing](https://docs.npmjs.com/trusted-publishers) (no tokens needed)
3430
- Notify [vscode-motoko](https://github.com/caffeinelabs/vscode-motoko) to open a PR bumping the `motoko` dependency (GitHub App must include the `vscode-motoko` repo; same app as `update-moc`)
3531

32+
Updating the version in `package.json` automatically publishes the package when merged into `main`.
33+
3634
## Local development (generate)
3735

3836
To regenerate files locally against a specific version:

0 commit comments

Comments
 (0)