From a7f79faebc491be728a8cc33e37a629af1bd72aa Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:01:14 +0100 Subject: [PATCH 1/6] ci(publish-npm): clarify that the `package` input is the `package_dir` - rename input `package` to `package_dir`, this is mostly a semantic change since it was already used as such - extract the package name from the `package.json` file (this have the additionnal advantage of retrieving the scope since it's included in the name) - use `working-directory: ${{ inputs.package_dir }}` instead of doing manual `cd` where applicable - fix console prints that were talking about `crates.io` which is incorrect since everything is done against `npmjs.com` in this workflow --- .../actions/publish-npm-package/action.yml | 58 ++++++++++--------- .github/workflows/ci.yml | 2 +- .github/workflows/manual-publish-npm.yml | 2 +- .github/workflows/pre-release.yml | 2 +- .github/workflows/release.yml | 2 +- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/.github/workflows/actions/publish-npm-package/action.yml b/.github/workflows/actions/publish-npm-package/action.yml index c4812e77105..81656d4b282 100644 --- a/.github/workflows/actions/publish-npm-package/action.yml +++ b/.github/workflows/actions/publish-npm-package/action.yml @@ -5,8 +5,8 @@ inputs: dry_run: description: Dry run will not publish to npm, just test it. required: true - package: - description: npm package name. + package_dir: + description: directory containing the package.json file. required: true scope: description: npm package scope (must not include '@' prefix). @@ -26,40 +26,46 @@ inputs: runs: using: "composite" steps: + - name: Prepare + id: prepare + shell: bash + run: | + echo "package_name=$(jq -r ".name" < "${{ inputs.package_dir }}"/package.json)" >> $GITHUB_OUTPUT + echo "package_local_version=$(jq -r ".version" < "${{ inputs.package_dir }}"/package.json)" >> $GITHUB_OUTPUT + - name: Check npm latest version id: check_version shell: bash run: | - echo "Check crate latest published version for '${{ inputs.package }}' package" + echo "Check npmjs.com latest published version for '${{ steps.prepare.outputs.package_name }}' package" if [ "${{ inputs.tag }}" != "latest" -a "${{ inputs.tag }}" != "next" ]; then echo "Tag '${{ inputs.tag }}' is not valid. It should be one of 'latest' or 'next'" exit 1 fi - LOCAL_VERSION=$(cat ${{ inputs.package }}/package.json | jq -r '.version') - NEXT_REMOTE_VERSION=$(npm view @${{ inputs.scope }}/${{ inputs.package }} dist-tags.next 2> /dev/null || true) - LATEST_REMOTE_VERSION=$(npm view @${{ inputs.scope }}/${{ inputs.package }} dist-tags.latest 2> /dev/null || true) + NEXT_REMOTE_VERSION=$(npm view ${{ steps.prepare.outputs.package_name }} dist-tags.next 2> /dev/null || true) + LATEST_REMOTE_VERSION=$(npm view ${{ steps.prepare.outputs.package_name }} dist-tags.latest 2> /dev/null || true) - echo "Latest crate.io version: '$LATEST_REMOTE_VERSION'" - echo "Next crate.io version: '$NEXT_REMOTE_VERSION'" - echo "Local version: '$LOCAL_VERSION'" + echo "Latest npmjs.com version: '$LATEST_REMOTE_VERSION'" + echo "Next npmjs.com version: '$NEXT_REMOTE_VERSION'" + echo "Local version: '${{ steps.prepare.outputs.package_local_version }}'" if [ "${{ inputs.tag }}" == "latest" ]; then - if [ "$LOCAL_VERSION" == "$LATEST_REMOTE_VERSION" ]; then + if [ "${{ steps.prepare.outputs.package_local_version }}" == "$LATEST_REMOTE_VERSION" ]; then echo "Local version and remote version are the same: no need to publish to npm registry" DEPLOY_MODE='none' - elif [ "$LOCAL_VERSION" == "$NEXT_REMOTE_VERSION" ]; then + elif [ "${{ steps.prepare.outputs.package_local_version }}" == "$NEXT_REMOTE_VERSION" ]; then DEPLOY_MODE='promote' else DEPLOY_MODE='publish' fi else # input.tag == 'next' - if [ "$LOCAL_VERSION" == "$LATEST_REMOTE_VERSION" ]; then + if [ "${{ steps.prepare.outputs.package_local_version }}" == "$LATEST_REMOTE_VERSION" ]; then # A latest already published: no need to tag with next echo "Local version and remote version are the same: no need to publish to npm registry" DEPLOY_MODE='none' - elif [ "$LOCAL_VERSION" == "$NEXT_REMOTE_VERSION" ]; then + elif [ "${{ steps.prepare.outputs.package_local_version }}" == "$NEXT_REMOTE_VERSION" ]; then echo "Local version and remote version are the same: no need to publish to npm registry" DEPLOY_MODE='none' else @@ -70,43 +76,43 @@ runs: echo "Deploy mode: '$DEPLOY_MODE'" echo "Dry run: '${{ inputs.dry_run }}'" echo "deploy_mode=$DEPLOY_MODE" >> $GITHUB_OUTPUT - echo "package_version=$LOCAL_VERSION" >> $GITHUB_OUTPUT - name: Build package shell: bash - working-directory: ${{ inputs.package }} + working-directory: ${{ inputs.package_dir }} env: WASM_PACK_ARGS: --release --scope ${{ inputs.scope }} run: | - echo "Build '@${{ inputs.scope }}/${{ inputs.package }}' package" + echo "Build '${{ steps.prepare.outputs.package_name }}' package" make build - name: Prepare publish shell: bash run: | - cp ./LICENSE ${{ inputs.package }} - cp -f ${{ inputs.package }}/npm/README.md ${{ inputs.package }}/ + cp ./LICENSE ${{ inputs.package_dir }} + cp -f ${{ inputs.package_dir }}/npm/README.md ${{ inputs.package_dir }}/ - name: List package shell: bash run: | - echo "List '@${{ inputs.scope }}/${{ inputs.package }}' package" - ls -al -R ${{ inputs.package }}/dist + echo "List '${{ steps.prepare.outputs.package_name }}' package" + ls -al -R ${{ inputs.package_dir }}/dist - name: Publish package new version if: steps.check_version.outputs.deploy_mode == 'publish' shell: bash + working-directory: ${{ inputs.package_dir }} env: NPM_TOKEN: ${{ inputs.api_token }} run: | - echo "Publish '@${{ inputs.scope }}/${{ inputs.package }}' package" + echo "Publish '${{ steps.prepare.outputs.package_name }}' package" npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" if [ -z "${NPM_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then echo "Warning: An NPM access token is required for authentication and has not been provided." else npm whoami fi - cd ${{ inputs.package }}/ + if [ "${{ inputs.dry_run }}" == "false" ]; then dry_run_option="" else @@ -117,12 +123,12 @@ runs: - name: Promote package distribution tag to 'latest' if: inputs.dry_run == 'false' && steps.check_version.outputs.deploy_mode == 'promote' shell: bash + working-directory: ${{ inputs.package_dir }} env: NPM_TOKEN: ${{ inputs.api_token }} run: | - echo "Publish '@${{ inputs.scope }}/${{ inputs.package }}' package" + echo "Promote '${{ steps.prepare.outputs.package_name }}' package version '${{ steps.prepare.outputs.package_local_version }}' from 'next' to 'latest'" npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" npm whoami - cd ${{ inputs.package }}/ - npm dist-tag add @${{ inputs.scope }}/${{ inputs.package }}@${{ steps.check_version.outputs.package_version }} latest - npm dist-tag rm @${{ inputs.scope }}/${{ inputs.package }}@${{ steps.check_version.outputs.package_version }} next + npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest + npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bbe3010a74..48b77921a59 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -617,7 +617,7 @@ jobs: uses: ./.github/workflows/actions/publish-npm-package with: dry_run: "true" - package: ${{ matrix.package }} + package_dir: ${{ matrix.package }} scope: ${{ matrix.scope }} access: ${{ matrix.access }} api_token: ${{ secrets[matrix.api_token_secret_name] }} diff --git a/.github/workflows/manual-publish-npm.yml b/.github/workflows/manual-publish-npm.yml index bcd22ba932d..33077e3a5de 100644 --- a/.github/workflows/manual-publish-npm.yml +++ b/.github/workflows/manual-publish-npm.yml @@ -65,7 +65,7 @@ jobs: uses: ./.github/workflows/actions/publish-npm-package with: dry_run: ${{ inputs.dry_run }} - package: ${{ matrix.package }} + package_dir: ${{ matrix.package }} scope: ${{ matrix.scope }} tag: ${{ matrix.tag }} access: ${{ matrix.access }} diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 8316e32b52c..1c5172ef9ad 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -345,7 +345,7 @@ jobs: uses: ./.github/workflows/actions/publish-npm-package with: dry_run: "false" - package: ${{ matrix.package }} + package_dir: ${{ matrix.package }} scope: ${{ matrix.scope }} tag: next access: ${{ matrix.access }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e3f3e3c5550..fa1d3b8eefa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -277,7 +277,7 @@ jobs: uses: ./.github/workflows/actions/publish-npm-package with: dry_run: "false" - package: ${{ matrix.package }} + package_dir: ${{ matrix.package }} scope: ${{ matrix.scope }} tag: latest access: ${{ matrix.access }} From 814a4ce00f1cc34137b116155739782a890bdddc Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:11:24 +0100 Subject: [PATCH 2/6] ci: clarify wasm test-publish/publish/promote steps name --- .github/workflows/ci.yml | 2 +- .github/workflows/pre-release.yml | 2 +- .github/workflows/release.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48b77921a59..c0da2549ba5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -613,7 +613,7 @@ jobs: cargo-tools: wasm-pack github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Publish package to npm + - name: Publish package to npm (dry-run) uses: ./.github/workflows/actions/publish-npm-package with: dry_run: "true" diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 1c5172ef9ad..817b8f53871 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -316,7 +316,7 @@ jobs: dry_run: "true" package: ${{ matrix.package }} - publish-wasm-test: + publish-next-wasm-package: strategy: fail-fast: false max-parallel: 1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fa1d3b8eefa..adcb3fbf4b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -248,7 +248,7 @@ jobs: package: ${{ matrix.package }} api_token: ${{ secrets[matrix.api_token_secret_name] }} - publish-wasm: + promote-wasm-package-to-latest: strategy: fail-fast: false max-parallel: 1 @@ -273,7 +273,7 @@ jobs: cargo-tools: wasm-pack github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Publish package to npm + - name: Promote npm package uses: ./.github/workflows/actions/publish-npm-package with: dry_run: "false" From 6af6550089654d571becd181b5767bf775c44c1e Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:14:43 +0100 Subject: [PATCH 3/6] ci: make `scope` in npm publications transparents Since it's already in the package.json name, we do not need to re-specify it so it can be removed from the ci workflows. --- .github/workflows/actions/publish-npm-package/action.yml | 5 +---- .github/workflows/ci.yml | 4 +--- .github/workflows/manual-publish-npm.yml | 2 -- .github/workflows/pre-release.yml | 2 -- .github/workflows/release.yml | 2 -- mithril-client-wasm/package.json | 6 +++--- 6 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.github/workflows/actions/publish-npm-package/action.yml b/.github/workflows/actions/publish-npm-package/action.yml index 81656d4b282..ba6e1f9dc32 100644 --- a/.github/workflows/actions/publish-npm-package/action.yml +++ b/.github/workflows/actions/publish-npm-package/action.yml @@ -8,9 +8,6 @@ inputs: package_dir: description: directory containing the package.json file. required: true - scope: - description: npm package scope (must not include '@' prefix). - required: true tag: description: npm package tag. required: false @@ -81,7 +78,7 @@ runs: shell: bash working-directory: ${{ inputs.package_dir }} env: - WASM_PACK_ARGS: --release --scope ${{ inputs.scope }} + WASM_PACK_ARGS: --release run: | echo "Build '${{ steps.prepare.outputs.package_name }}' package" make build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0da2549ba5..25da5b2924e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -136,7 +136,7 @@ jobs: shell: bash working-directory: mithril-client-wasm env: - WASM_PACK_ARGS: --release --scope mithril-dev + WASM_PACK_ARGS: --release run: make build - name: Prepare 'mithril-client-wasm' package @@ -594,7 +594,6 @@ jobs: package: [mithril-client-wasm] include: - package: mithril-client-wasm - scope: mithril-dev tag: latest access: public api_token_secret_name: NPM_API_TOKEN_MITHRIL_CLIENT_WASM @@ -618,7 +617,6 @@ jobs: with: dry_run: "true" package_dir: ${{ matrix.package }} - scope: ${{ matrix.scope }} access: ${{ matrix.access }} api_token: ${{ secrets[matrix.api_token_secret_name] }} diff --git a/.github/workflows/manual-publish-npm.yml b/.github/workflows/manual-publish-npm.yml index 33077e3a5de..122fbf803bc 100644 --- a/.github/workflows/manual-publish-npm.yml +++ b/.github/workflows/manual-publish-npm.yml @@ -39,7 +39,6 @@ jobs: package: [mithril-client-wasm] include: - package: mithril-client-wasm - scope: mithril-dev tag: latest access: public api_token_secret_name: NPM_API_TOKEN_MITHRIL_CLIENT_WASM @@ -66,7 +65,6 @@ jobs: with: dry_run: ${{ inputs.dry_run }} package_dir: ${{ matrix.package }} - scope: ${{ matrix.scope }} tag: ${{ matrix.tag }} access: ${{ matrix.access }} api_token: ${{ secrets[matrix.api_token_secret_name] }} diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index 817b8f53871..a21a0c49f12 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -324,7 +324,6 @@ jobs: package: [mithril-client-wasm] include: - package: mithril-client-wasm - scope: mithril-dev tag: next access: public api_token_secret_name: NPM_API_TOKEN_MITHRIL_CLIENT_WASM @@ -346,7 +345,6 @@ jobs: with: dry_run: "false" package_dir: ${{ matrix.package }} - scope: ${{ matrix.scope }} tag: next access: ${{ matrix.access }} api_token: ${{ secrets[matrix.api_token_secret_name] }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index adcb3fbf4b8..24b2ee8937b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -256,7 +256,6 @@ jobs: package: [mithril-client-wasm] include: - package: mithril-client-wasm - scope: mithril-dev tag: latest access: public api_token_secret_name: NPM_API_TOKEN_MITHRIL_CLIENT_WASM @@ -278,7 +277,6 @@ jobs: with: dry_run: "false" package_dir: ${{ matrix.package }} - scope: ${{ matrix.scope }} tag: latest access: ${{ matrix.access }} api_token: ${{ secrets[matrix.api_token_secret_name] }} diff --git a/mithril-client-wasm/package.json b/mithril-client-wasm/package.json index abbb43c9c01..a6ff644580a 100644 --- a/mithril-client-wasm/package.json +++ b/mithril-client-wasm/package.json @@ -25,11 +25,11 @@ "types": "dist/node/mithril_client_wasm.d.ts", "scripts": { "build": "npm run build:node && npm run build:web && npm run build:bundler", - "build:bundler": "wasm-pack build --target bundler --out-dir dist/bundler $WASM_PACK_ARGS", + "build:bundler": "wasm-pack build --target bundler --out-dir dist/bundler --scope mithril-dev $WASM_PACK_ARGS", "postbuild:bundler": "rm dist/bundler/.gitignore", - "build:node": "wasm-pack build --target nodejs --out-dir dist/node $WASM_PACK_ARGS", + "build:node": "wasm-pack build --target nodejs --out-dir dist/node --scope mithril-dev $WASM_PACK_ARGS", "postbuild:node": "rm dist/node/.gitignore", - "build:web": "wasm-pack build --target web --out-dir dist/web $WASM_PACK_ARGS", + "build:web": "wasm-pack build --target web --out-dir dist/web --scope mithril-dev $WASM_PACK_ARGS", "postbuild:web": "rm dist/web/.gitignore" } } From 2e3ba375015e89667f6798c6048b493f8d647b97 Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:27:55 +0100 Subject: [PATCH 4/6] ci(npm-publish): rework auth using `actions/setup-node` --- .../actions/publish-npm-package/action.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/actions/publish-npm-package/action.yml b/.github/workflows/actions/publish-npm-package/action.yml index ba6e1f9dc32..44e21ace9fe 100644 --- a/.github/workflows/actions/publish-npm-package/action.yml +++ b/.github/workflows/actions/publish-npm-package/action.yml @@ -23,6 +23,13 @@ inputs: runs: using: "composite" steps: + - uses: actions/setup-node@v6 + with: + node-version: "lts/*" + package-manager-cache: "false" + # Note: setting up the registry allows auth to be passed via env.NODE_AUTH_TOKEN + registry-url: https://registry.npmjs.org + - name: Prepare id: prepare shell: bash @@ -100,16 +107,15 @@ runs: shell: bash working-directory: ${{ inputs.package_dir }} env: - NPM_TOKEN: ${{ inputs.api_token }} + NODE_AUTH_TOKEN: ${{ inputs.api_token }} run: | echo "Publish '${{ steps.prepare.outputs.package_name }}' package" - npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" - if [ -z "${NPM_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then + if [ -z "${NODE_AUTH_TOKEN}" -a "${{ inputs.dry_run }}" == "true" ]; then echo "Warning: An NPM access token is required for authentication and has not been provided." else npm whoami fi - + if [ "${{ inputs.dry_run }}" == "false" ]; then dry_run_option="" else @@ -122,10 +128,9 @@ runs: shell: bash working-directory: ${{ inputs.package_dir }} env: - NPM_TOKEN: ${{ inputs.api_token }} + NODE_AUTH_TOKEN: ${{ inputs.api_token }} run: | echo "Promote '${{ steps.prepare.outputs.package_name }}' package version '${{ steps.prepare.outputs.package_local_version }}' from 'next' to 'latest'" - npm set "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" npm whoami npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next From 008bdcd90a4ec1bfd23e49fbbbb396e9f0be4df7 Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Mon, 27 Oct 2025 15:09:46 +0100 Subject: [PATCH 5/6] ci(publish-npm): wrap build step in a group --- .github/workflows/actions/publish-npm-package/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/actions/publish-npm-package/action.yml b/.github/workflows/actions/publish-npm-package/action.yml index 44e21ace9fe..f4edc15ab6a 100644 --- a/.github/workflows/actions/publish-npm-package/action.yml +++ b/.github/workflows/actions/publish-npm-package/action.yml @@ -87,8 +87,9 @@ runs: env: WASM_PACK_ARGS: --release run: | - echo "Build '${{ steps.prepare.outputs.package_name }}' package" + echo "::group::Build '${{ steps.prepare.outputs.package_name }}' package" make build + echo "::endgroup::" - name: Prepare publish shell: bash From 110e8967bbf0b397ef1ff45abab4e8c0ba2e256c Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Mon, 27 Oct 2025 15:18:47 +0100 Subject: [PATCH 6/6] ci(publish-npm): add a 'dry-run' version of the promote step This induce repeating code but will at least ensure that something is written to the console in all cases. --- .../actions/publish-npm-package/action.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/actions/publish-npm-package/action.yml b/.github/workflows/actions/publish-npm-package/action.yml index f4edc15ab6a..c850cb7a642 100644 --- a/.github/workflows/actions/publish-npm-package/action.yml +++ b/.github/workflows/actions/publish-npm-package/action.yml @@ -125,13 +125,18 @@ runs: npm publish --tag ${{ inputs.tag }} --access ${{ inputs.access }} $dry_run_option - name: Promote package distribution tag to 'latest' - if: inputs.dry_run == 'false' && steps.check_version.outputs.deploy_mode == 'promote' + if: steps.check_version.outputs.deploy_mode == 'promote' shell: bash working-directory: ${{ inputs.package_dir }} env: NODE_AUTH_TOKEN: ${{ inputs.api_token }} run: | echo "Promote '${{ steps.prepare.outputs.package_name }}' package version '${{ steps.prepare.outputs.package_local_version }}' from 'next' to 'latest'" - npm whoami - npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest - npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next + if [ "${{ inputs.dry_run }}" == "false" ]; then + npm whoami + npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest + npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next + else + echo "Dry run: npm dist-tag add ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} latest + echo "Dry run: npm dist-tag rm ${{ steps.prepare.outputs.package_name }}"@${{ steps.prepare.outputs.package_local_version }} next + fi