name: Release on: # This job runs when a new release is published release: types: [published] # Manual trigger with version input workflow_dispatch: inputs: version: description: "Version to release (e.g., 2.12.1)" required: true type: string permissions: contents: read id-token: write jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 12.16.3 - uses: actions/cache@v4 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} # Store the release version (from release tag or manual input) - name: Set release version run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV echo "Manual release triggered for version: ${{ github.event.inputs.version }}" else echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV echo "Release triggered from tag: ${GITHUB_REF#refs/*/}" fi - run: npm ci - run: npm version $RELEASE_VERSION --no-git-tag-version - run: npm run build - name: Upload build artifacts uses: actions/upload-artifact@v4 with: name: dist path: . publish: needs: build runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v4 with: name: dist - uses: actions/setup-node@v4 with: node-version: 20 registry-url: "https://registry.npmjs.org" - name: Update npm to latest (trusted publishing requires npm >= 11.5.1) run: npm install -g npm@latest - name: Publish to npm run: npm publish --provenance --access public