Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions .github/workflows/release.yml → .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
name: Release
name: Publish

on:
release:
types: [published]
push:
branches:
- main
paths:
- 'package.json'

permissions:
contents: read
id-token: write

jobs:
publish:
version-check:
runs-on: ubuntu-latest
environment: npm
outputs:
version_changed: ${{ steps.check.outputs.changed }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Validate version
- name: Detect package.json version bump
id: check
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
PKG_VERSION=$(node -p "require('./package.json').version")
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
echo "::error::Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)"
exit 1
fi
set -euo pipefail
NEW=$(node -p "require('./package.json').version")
echo "version=${NEW}" >> "$GITHUB_OUTPUT"
BEFORE="${{ github.event.before }}"
OLD=$(git show "${BEFORE}:package.json" 2>/dev/null | jq -r .version 2>/dev/null) || OLD=""
echo "changed=$([[ "$BEFORE" =~ ^0{40}$ || "$OLD" != "$NEW" ]] && echo true || echo false)" >> "$GITHUB_OUTPUT"

publish:
needs: version-check
if: needs.version-check.outputs.version_changed == 'true'
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v4

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

# Runs after npm publish; failures here do not affect the published package (re-run this job only if needed).
notify-vscode-motoko:
needs: publish
needs: [publish, version-check]
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App token
Expand All @@ -59,4 +75,4 @@ jobs:
token: ${{ steps.dispatch-token.outputs.token }}
repository: caffeinelabs/vscode-motoko
event-type: motoko-release
client-payload: '{"version":"${{ github.event.release.tag_name }}"}'
client-payload: '{"version":"v${{ needs.version-check.outputs.version }}"}'
10 changes: 4 additions & 6 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ with optional `moc_version` and `core_version` inputs. Leave them empty to auto-

## Publishing to npm

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

1. Go to [Releases](https://github.com/caffeinelabs/node-motoko/releases/new)
2. Create a new tag matching the `package.json` version (e.g. `v4.1.0`)
3. Click "Publish release"
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:

The [`release`](.github/workflows/release.yml) workflow will automatically:
- Validate the tag matches `package.json`
- Build and test
- Publish to npm via [OIDC trusted publishing](https://docs.npmjs.com/trusted-publishers) (no tokens needed)
- 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`)

Updating the version in `package.json` automatically publishes the package when merged into `main`.

## Local development (generate)

To regenerate files locally against a specific version:
Expand Down
Loading