name: Release on: push: tags: - "*-[0-9]+.[0-9]+.[0-9]+*" workflow_dispatch: inputs: package: description: "Package to release" required: true type: choice options: - client - proxy version: description: "Version to release (e.g., 1.2.0, 1.3.0-alpha.0)" required: true type: string dry_run: description: "Dry run (will not publish to npm)" required: false type: boolean default: true jobs: build-and-publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "20" registry-url: "https://registry.npmjs.org" - name: Install dependencies run: npm ci - name: Extract package info id: tag-info run: | if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then # Manual trigger PACKAGE_NAME="${{ inputs.package }}" VERSION="${{ inputs.version }}" else # Tag trigger TAG_NAME=${{ github.ref_name }} PACKAGE_NAME=$(echo $TAG_NAME | cut -d'-' -f1) VERSION=$(echo $TAG_NAME | cut -d'-' -f2-) fi # Extract npm tag based on version qualifier if [[ $VERSION =~ .*-([a-zA-Z]+)\.[0-9]+$ ]]; then NPM_TAG="${BASH_REMATCH[1]}" else NPM_TAG="latest" fi echo "package=$PACKAGE_NAME" >> $GITHUB_OUTPUT echo "version=$VERSION" >> $GITHUB_OUTPUT echo "npm_tag=$NPM_TAG" >> $GITHUB_OUTPUT - name: Build package run: npx nx build ${{ steps.tag-info.outputs.package }} --prod - name: Verify package version run: | PACKAGE_JSON_VERSION=$(node -p "require('./dist/libs/${{ steps.tag-info.outputs.package }}/package.json').version") if [ "$PACKAGE_JSON_VERSION" != "${{ steps.tag-info.outputs.version }}" ]; then echo "Package version ($PACKAGE_JSON_VERSION) does not match tag version (${{ steps.tag-info.outputs.version }})" exit 1 fi - name: Publish package run: | echo "Publishing ${{ steps.tag-info.outputs.package }}@${{ steps.tag-info.outputs.version }} with tag ${{ steps.tag-info.outputs.npm_tag }}" cd dist/libs/${{ steps.tag-info.outputs.package }} npm publish --access public --tag ${{ steps.tag-info.outputs.npm_tag }} ${{ inputs.dry_run && '--dry-run' || '' }} env: NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}