From b10c1eff80d092b69a4bb773a8cf07977d4fbcad Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Tue, 11 Jun 2024 17:09:03 +0200 Subject: [PATCH] [BLD] JS client release to GH packages + dev releases (#2173) ## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - Added support for releasing js client to GH packages - Fixed the tag matching patterns to prevent unexpected tags to trigger the WF, thus resulting in failure (existing error handling is still in place) - Added support for dev releases to GH packages only (we want to prevent poluting npmjs with too many releases, as it is the primary distribution channel for the js package) - Implemented dev package naming convention to include sha of the merge commit + GH action run it for provenance tracing ## Test plan *How are these changes tested?* ## Documentation Changes N/A --- .../release-dev-javascript-client.yml | 59 +++++++++++++++++++ .../workflows/release-javascript-client.yml | 11 ++-- clients/js/package.json | 3 +- 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release-dev-javascript-client.yml diff --git a/.github/workflows/release-dev-javascript-client.yml b/.github/workflows/release-dev-javascript-client.yml new file mode 100644 index 00000000000..b7f59468271 --- /dev/null +++ b/.github/workflows/release-dev-javascript-client.yml @@ -0,0 +1,59 @@ +name: 📦 Development Release JavaScript client + +on: + push: + branches: + - main + +jobs: + release-dev: + strategy: + matrix: + registry: [ "https://npm.pkg.github.com" ] + runs-on: ubuntu-latest + if: ${{ github.ref == 'refs/heads/main' }} + permissions: write-all + steps: + - name: Check if tag matches the pattern + id: check-tag + run: | + # we don't necessarily need this + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "Push to main branch, releasing dev version to GH packages" + echo "NPM_SCRIPT=release_dev" >> "$GITHUB_ENV" + else + echo "The ref does not point to main, exiting workflow" # we alredy make the check above but this is a good practice + exit 1 + fi + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: "16.x" + registry-url: ${{ matrix.registry }} + - name: Install dependencies + run: npm install + working-directory: ./clients/js/ + - name: Dev Version + id: dev-version + run: | + set -e + # Get current version + CURRENT_VERSION=$(node -p "require('./package.json').version") + # Generate a beta tag using commit short sha and run id + COMMIT_SHA=$(git rev-parse --short HEAD) + DEV_TAG="dev.${COMMIT_SHA}-${GITHUB_RUN_ID}" + # Create full version with beta tag + BASE_VERSION=$(echo $CURRENT_VERSION | cut -f1,2 -d.) + PATCH_VERSION=$(echo $CURRENT_VERSION | cut -f3 -d.) + # bump patch version + NEW_PATCH_VERSION=$((PATCH_VERSION + 1)) + NEW_VERSION="${BASE_VERSION}.${NEW_PATCH_VERSION}-${DEV_TAG}" + echo "NEW_VERSION=${NEW_VERSION}" >> "$GITHUB_ENV" + - name: Test & publish + run: npm run db:run && PORT=8001 npm run $NPM_SCRIPT + working-directory: ./clients/js/ + env: + NODE_AUTH_TOKEN: ${{ matrix.registry == 'https://registry.npmjs.org' && secrets.NPM_TOKEN || secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-javascript-client.yml b/.github/workflows/release-javascript-client.yml index 939cfbb45eb..886105fea40 100644 --- a/.github/workflows/release-javascript-client.yml +++ b/.github/workflows/release-javascript-client.yml @@ -3,11 +3,14 @@ name: 📦 Release JavaScript client on: push: tags: - - 'js_release_*.*.*' # Match tags in the form js_release_X.Y.Z - - 'js_release_alpha_*.*.*' # Match tags in the form js_release_alpha_X.Y.Z + - 'js_release_[0-9]+\.[0-9]+\.[0-9]+' # Match tags in the form js_release_X.Y.Z + - 'js_release_alpha_[0-9]+\.[0-9]+\.[0-9]+' # Match tags in the form js_release_alpha_X.Y.Z jobs: release: + strategy: + matrix: + registry: [ "https://registry.npmjs.org", "https://npm.pkg.github.com" ] runs-on: ubuntu-latest permissions: write-all steps: @@ -30,7 +33,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: "16.x" - registry-url: "https://registry.npmjs.org" + registry-url: ${{ matrix.registry }} - name: Install dependencies run: npm install working-directory: ./clients/js/ @@ -38,4 +41,4 @@ jobs: run: npm run db:run && PORT=8001 npm run $NPM_SCRIPT working-directory: ./clients/js/ env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_AUTH_TOKEN: ${{ matrix.registry == 'https://registry.npmjs.org' && secrets.NPM_TOKEN || secrets.GITHUB_TOKEN }} diff --git a/clients/js/package.json b/clients/js/package.json index 1e59f61a73a..c937d7e67ca 100644 --- a/clients/js/package.json +++ b/clients/js/package.json @@ -67,7 +67,8 @@ "genapi": "./genapi.sh", "prettier": "prettier --write .", "release": "run-s build test:run && npm publish", - "release_alpha": "run-s build test:run && npm publish --tag alpha" + "release_alpha": "run-s build test:run && npm publish --tag alpha", + "release_dev": "run-s build test:run && npm version ${NEW_VERSION} --no-git-tag-version && npm publish" }, "engines": { "node": ">=14.17.0"