From ea508c6764462aa3b05495f3842f5542dd2e0cfc Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 31 Mar 2026 09:12:48 -0400 Subject: [PATCH 1/2] Publish on update package.json version --- .github/workflows/release.yml | 62 ----------------------------------- RELEASING.md | 12 +++---- 2 files changed, 6 insertions(+), 68 deletions(-) delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index d67aa0e..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Release - -on: - release: - types: [published] - -permissions: - contents: read - id-token: write - -jobs: - publish: - runs-on: ubuntu-latest - environment: npm - steps: - - uses: actions/checkout@v4 - - - name: Validate version - 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 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '24' - cache: 'npm' - registry-url: 'https://registry.npmjs.org' - - - run: npm ci - - run: npm run build - - run: npm test - - - name: Publish to npm - run: npm publish --provenance - - # Runs after npm publish; failures here do not affect the published package (re-run this job only if needed). - notify-vscode-motoko: - needs: publish - runs-on: ubuntu-latest - steps: - - name: Generate GitHub App token - id: dispatch-token - uses: actions/create-github-app-token@v1 - with: - app-id: ${{ vars.GENERIC_CI_RW_APP_ID }} - private-key: ${{ secrets.GENERIC_CI_RW_APP_PRIVATE_KEY }} - owner: caffeinelabs - repositories: | - vscode-motoko - - - name: Trigger vscode-motoko (bump motoko npm in extension) - uses: peter-evans/repository-dispatch@v3 - with: - token: ${{ steps.dispatch-token.outputs.token }} - repository: caffeinelabs/vscode-motoko - event-type: motoko-release - client-payload: '{"version":"${{ github.event.release.tag_name }}"}' diff --git a/RELEASING.md b/RELEASING.md index 5b68951..51066f3 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -21,18 +21,18 @@ 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`) +Edits to `package.json` that do not change `version` (for example dependency bumps only) do not trigger a publish. + +You can still tag releases on GitHub for changelog visibility; publishing is driven by the version bump on `main`, not by the GitHub Release event. + ## Local development (generate) To regenerate files locally against a specific version: From 9970edbbc991e8095cfb1397d633001289bda526 Mon Sep 17 00:00:00 2001 From: rvanasa Date: Tue, 31 Mar 2026 09:15:31 -0400 Subject: [PATCH 2/2] Update release instructions --- .github/workflows/publish.yml | 78 +++++++++++++++++++++++++++++++++++ RELEASING.md | 4 +- 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..2039ae2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,78 @@ +name: Publish + +on: + push: + branches: + - main + paths: + - 'package.json' + +permissions: + contents: read + id-token: write + +jobs: + version-check: + runs-on: ubuntu-latest + outputs: + version_changed: ${{ steps.check.outputs.changed }} + version: ${{ steps.check.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Detect package.json version bump + id: check + run: | + 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 + with: + node-version: '24' + cache: 'npm' + registry-url: 'https://registry.npmjs.org' + + - run: npm ci + - run: npm run build + - run: npm test + + - name: Publish to npm + run: npm publish --provenance + + # Runs after npm publish; failures here do not affect the published package (re-run this job only if needed). + notify-vscode-motoko: + needs: [publish, version-check] + runs-on: ubuntu-latest + steps: + - name: Generate GitHub App token + id: dispatch-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ vars.GENERIC_CI_RW_APP_ID }} + private-key: ${{ secrets.GENERIC_CI_RW_APP_PRIVATE_KEY }} + owner: caffeinelabs + repositories: | + vscode-motoko + + - name: Trigger vscode-motoko (bump motoko npm in extension) + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ steps.dispatch-token.outputs.token }} + repository: caffeinelabs/vscode-motoko + event-type: motoko-release + client-payload: '{"version":"v${{ needs.version-check.outputs.version }}"}' diff --git a/RELEASING.md b/RELEASING.md index 51066f3..cb87c5e 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -29,9 +29,7 @@ The [`release`](.github/workflows/release.yml) workflow runs when `package.json` - 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`) -Edits to `package.json` that do not change `version` (for example dependency bumps only) do not trigger a publish. - -You can still tag releases on GitHub for changelog visibility; publishing is driven by the version bump on `main`, not by the GitHub Release event. +Updating the version in `package.json` automatically publishes the package when merged into `main`. ## Local development (generate)