name: Release to NPM on: workflow_dispatch: # No input required release: types: [published] push: branches: [main] jobs: build: uses: ./.github/workflows/build.yml deploy_release: name: Publish npm package needs: [build] runs-on: [ubuntu-latest] permissions: contents: write id-token: write steps: - uses: actions/checkout@v4 with: submodules: true fetch-depth: 100 fetch-tags: true - uses: actions/setup-node@v6.4.0 with: node-version-file: 'package.json' package-manager-cache: false registry-url: 'https://registry.npmjs.org' - name: Determine version and tag id: version run: | if [[ "${{ github.event_name }}" == "release" ]] || [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then VERSION=$(node -p "require('./package.json').version") echo "tag=latest" >> $GITHUB_OUTPUT echo "publish_type=stable" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT else ALPHA_VERSION=$(node -e "console.log(require('./version').getAlphaVersion());") echo "tag=next" >> $GITHUB_OUTPUT echo "publish_type=alpha" >> $GITHUB_OUTPUT echo "alpha_version=$ALPHA_VERSION" >> $GITHUB_OUTPUT echo "verson=$ALPHA_VERSION" >> $GITHUB_OUTPUT # Set the alpha version npm --no-git-tag-version version $ALPHA_VERSION fi - run: npm install -g npm@11.16.0 - run: npm ci - name: Build Alpha if: steps.version.outputs.publish_type == 'alpha' run: npm run build - name: Publish to NPM (Alpha) if: steps.version.outputs.publish_type == 'alpha' run: npm stage publish --tag next --provenance - name: Tag alpha publish id: tag if: steps.version.outputs.publish_type == 'alpha' env: ALPHA_VERSION: ${{ steps.version.outputs.alpha_version }} run: | set -euo pipefail TAG="v$(printf '%s' "$ALPHA_VERSION" | sed 's/+.*//')" if git rev-parse "refs/tags/$TAG" >/dev/null 2>&1; then echo "Tag $TAG already exists, skipping" echo "tag=$TAG" >> $GITHUB_OUTPUT exit 0 fi git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git tag -a "$TAG" -m "Alpha release $TAG" git push origin "$TAG" echo "tag=$TAG" >> $GITHUB_OUTPUT - name: Build Release if: steps.version.outputs.publish_type == 'stable' run: npm run build env: release: true - name: Publish Release if: steps.version.outputs.publish_type == 'stable' run: npm stage publish --provenance - name: Output Published Version run: | echo "Published version ${{ steps.version.outputs.version }} with tag ${{ steps.version.outputs.tag }}"