Files
self/.github/workflows/npm-publish.yml
Javier Cortejoso 988c5c2c1a chore: enhance npm publish workflow to include version tagging
- Updated the npm publish workflow to dynamically determine the package version and apply a beta tag for pre-release versions.
- This change ensures that the correct versioning is maintained during the publishing process, improving clarity for users regarding package stability.
- Retained existing dry run functionality for testing without actual publishing.
2026-02-11 18:28:06 +01:00

304 lines
12 KiB
YAML

name: NPM Publish
on:
push:
branches:
- dev
paths:
- "sdk/core/package.json"
- "sdk/qrcode/package.json"
- "common/package.json"
- "packages/mobile-sdk-alpha/package.json"
- "sdk/qrcode-angular/package.json"
- "contracts/package.json"
workflow_dispatch:
inputs:
dry_run:
description: "Run publish with --dry-run (validates auth/Trusted Publishers without uploading)"
required: false
type: boolean
default: false
permissions:
id-token: write # Required for OIDC
contents: read
jobs:
detect-changes:
runs-on: ubuntu-slim
outputs:
core_changed: ${{ steps.check-version.outputs.core_changed }}
qrcode_changed: ${{ steps.check-version.outputs.qrcode_changed }}
common_changed: ${{ steps.check-version.outputs.common_changed }}
contracts_changed: ${{ steps.check-version.outputs.contracts_changed }}
qrcode_angular_changed: ${{ steps.check-version.outputs.qrcode_angular_changed }}
msdk_changed: ${{ steps.check-version.outputs.msdk_changed }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Check for version changes
id: check-version
run: |
git diff HEAD^ HEAD --name-only | grep -q "sdk/core/package.json" && echo "core_changed=true" >> $GITHUB_OUTPUT || echo "core_changed=false" >> $GITHUB_OUTPUT
git diff HEAD^ HEAD --name-only | grep -q "sdk/qrcode/package.json" && echo "qrcode_changed=true" >> $GITHUB_OUTPUT || echo "qrcode_changed=false" >> $GITHUB_OUTPUT
git diff HEAD^ HEAD --name-only | grep -q "common/package.json" && echo "common_changed=true" >> $GITHUB_OUTPUT || echo "common_changed=false" >> $GITHUB_OUTPUT
git diff HEAD^ HEAD --name-only | grep -q "contracts/package.json" && echo "contracts_changed=true" >> $GITHUB_OUTPUT || echo "contracts_changed=false" >> $GITHUB_OUTPUT
git diff HEAD^ HEAD --name-only | grep -q "sdk/qrcode-angular/package.json" && echo "qrcode_angular_changed=true" >> $GITHUB_OUTPUT || echo "qrcode_angular_changed=false" >> $GITHUB_OUTPUT
git diff HEAD^ HEAD --name-only | grep -q "packages/mobile-sdk-alpha/package.json" && echo "msdk_changed=true" >> $GITHUB_OUTPUT || echo "msdk_changed=false" >> $GITHUB_OUTPUT
# check if it was dispatched manually as well
if git diff HEAD^ HEAD -- sdk/core/package.json | grep -q '"version":' || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "core_changed=true" >> $GITHUB_OUTPUT
fi
if git diff HEAD^ HEAD -- sdk/qrcode/package.json | grep -q '"version":' || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "qrcode_changed=true" >> $GITHUB_OUTPUT
fi
if git diff HEAD^ HEAD -- common/package.json | grep -q '"version":' || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "common_changed=true" >> $GITHUB_OUTPUT
fi
if git diff HEAD^ HEAD -- contracts/package.json | grep -q '"version":' || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "contracts_changed=true" >> $GITHUB_OUTPUT
fi
if git diff HEAD^ HEAD -- sdk/qrcode-angular/package.json | grep -q '"version":' || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "qrcode_angular_changed=true" >> $GITHUB_OUTPUT
fi
if git diff HEAD^ HEAD -- packages/mobile-sdk-alpha/package.json | grep -q '"version":' || [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "msdk_changed=true" >> $GITHUB_OUTPUT
fi
publish-core:
needs: detect-changes
if: needs.detect-changes.outputs.core_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Build package
run: |
yarn workspace @selfxyz/core build:deps
# OIDC trusted publishing requires the npm CLI (not yarn npm publish)
- name: Publish to npm
working-directory: sdk/core
id: publish
run: |
DRY_RUN="${{ github.event.inputs.dry_run == 'true' && '--dry-run' || '' }}"
VERSION=$(node -p "require('./package.json').version")
TAG=$([[ "$VERSION" == *-* ]] && echo "--tag beta" || echo "")
npx npm@latest publish --access public $TAG $DRY_RUN
- name: Publish result
if: always()
run: |
if [ "${{ steps.publish.outcome }}" != "success" ]; then
echo "::warning::NPM publish failed. For @selfxyz/core we use Trusted Publishers (OIDC); check workflow and npm package settings."
elif [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "✅ Dry run completed (no package uploaded)"
else
echo "✅ Package published successfully"
fi
publish-qrcode:
needs: detect-changes
if: needs.detect-changes.outputs.qrcode_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Build package
run: |
yarn workspace @selfxyz/qrcode build:deps
- name: Publish to npm
working-directory: sdk/qrcode
id: publish
run: |
DRY_RUN="${{ github.event.inputs.dry_run == 'true' && '--dry-run' || '' }}"
VERSION=$(node -p "require('./package.json').version")
TAG=$([[ "$VERSION" == *-* ]] && echo "--tag beta" || echo "")
npx npm@latest publish --access public $TAG $DRY_RUN
- name: Publish result
if: always()
run: |
if [ "${{ steps.publish.outcome }}" != "success" ]; then
echo "::warning::NPM publish failed. For @selfxyz/qrcode we use Trusted Publishers (OIDC); check workflow and npm package settings."
elif [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "✅ Dry run completed (no package uploaded)"
else
echo "✅ Package published successfully"
fi
publish-common:
needs: detect-changes
if: needs.detect-changes.outputs.common_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Build package
run: |
yarn workspace @selfxyz/common build
- name: Publish to npm
working-directory: common
id: publish
run: |
DRY_RUN="${{ github.event.inputs.dry_run == 'true' && '--dry-run' || '' }}"
VERSION=$(node -p "require('./package.json').version")
TAG=$([[ "$VERSION" == *-* ]] && echo "--tag beta" || echo "")
npx npm@latest publish --access public $TAG $DRY_RUN
- name: Publish result
if: always()
run: |
if [ "${{ steps.publish.outcome }}" != "success" ]; then
echo "::warning::NPM publish failed. For @selfxyz/common we use Trusted Publishers (OIDC); check workflow and npm package settings."
elif [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "✅ Dry run completed (no package uploaded)"
else
echo "✅ Package published successfully"
fi
publish-contracts:
needs: detect-changes
if: needs.detect-changes.outputs.contracts_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Build package
run: |
yarn workspace @selfxyz/contracts build
- name: Publish to npm
working-directory: contracts
id: publish
run: |
DRY_RUN="${{ github.event.inputs.dry_run == 'true' && '--dry-run' || '' }}"
VERSION=$(node -p "require('./package.json').version")
TAG=$([[ "$VERSION" == *-* ]] && echo "--tag beta" || echo "")
npx npm@latest publish --access public $TAG $DRY_RUN
- name: Publish result
if: always()
run: |
if [ "${{ steps.publish.outcome }}" != "success" ]; then
echo "::warning::NPM publish failed. For @selfxyz/contracts we use Trusted Publishers (OIDC); check workflow and npm package settings."
elif [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "✅ Dry run completed (no package uploaded)"
else
echo "✅ Package published successfully"
fi
publish-qrcode-angular:
needs: detect-changes
if: needs.detect-changes.outputs.qrcode_angular_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Build package
run: |
yarn workspace @selfxyz/qrcode-angular build:deps
- name: Publish to npm
working-directory: sdk/qrcode-angular
id: publish
run: |
DRY_RUN="${{ github.event.inputs.dry_run == 'true' && '--dry-run' || '' }}"
VERSION=$(node -p "require('./package.json').version")
TAG=$([[ "$VERSION" == *-* ]] && echo "--tag beta" || echo "")
npx npm@latest publish --access public $TAG $DRY_RUN
- name: Publish result
if: always()
run: |
if [ "${{ steps.publish.outcome }}" != "success" ]; then
echo "::warning::NPM publish failed. For @selfxyz/qrcode-angular we use Trusted Publishers (OIDC); check workflow and npm package settings."
elif [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "✅ Dry run completed (no package uploaded)"
else
echo "✅ Package published successfully"
fi
publish-msdk:
needs: detect-changes
if: needs.detect-changes.outputs.msdk_changed == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies
uses: ./.github/actions/yarn-install
- name: Build package dependencies
run: |
yarn workspace @selfxyz/common build
yarn workspace @selfxyz/mobile-sdk-alpha build
- name: Publish to npm
working-directory: packages/mobile-sdk-alpha
id: publish
run: |
DRY_RUN="${{ github.event.inputs.dry_run == 'true' && '--dry-run' || '' }}"
npx npm@latest publish --access restricted --tag alpha $DRY_RUN
- name: Publish result
if: always()
run: |
if [ "${{ steps.publish.outcome }}" != "success" ]; then
echo "::warning::NPM publish failed. For @selfxyz/mobile-sdk-alpha we use Trusted Publishers (OIDC); check workflow and npm package settings."
elif [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "✅ Dry run completed (no package uploaded)"
else
echo "✅ Package published successfully"
fi