From 606816341903ae348669edff6270a707b7796ba3 Mon Sep 17 00:00:00 2001 From: Daniel Rochetti Date: Thu, 21 Nov 2024 11:04:02 -0800 Subject: [PATCH] chore(build): automated release process (#108) * chore(build): automated release process * fix: update secret name to match current setup --- .github/workflows/release.yml | 83 +++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2907c87..cbcd66c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,28 +2,85 @@ name: Release on: push: - branches: - - x_main # CI release temporarily disabled + 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: - release: - name: Release + build-and-publish: runs-on: ubuntu-latest + steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: "16.x" + node-version: "20" registry-url: "https://registry.npmjs.org" - scope: "@fal" + - name: Install dependencies run: npm ci - - name: Publish to NPM + + - 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: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} - run: npx nx release client + NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}