fix: use reusable func #7726
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This Source Code Form is subject to the terms of the Mozilla Public | |
| # License, v. 2.0. If a copy of the MPL was not distributed with this | |
| # file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
| # | |
| # OpenCRVS is also distributed under the terms of the Civil Registration | |
| # & Healthcare Disclaimer located at http://opencrvs.org/license. | |
| # | |
| # Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | |
| name: Publish toolkit to NPM registry | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch_name: | |
| description: Branch to publish from | |
| default: develop | |
| required: true | |
| push: | |
| branches: | |
| - '*' | |
| tags: | |
| - '*' | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: '.nvmrc' | |
| registry-url: 'https://registry.npmjs.org/' | |
| - name: Check if version exists on npm | |
| id: check-version | |
| run: | | |
| PACKAGE_VERSION=$(node -p "require('../../package.json').version") | |
| if [ "$GITHUB_REF_TYPE" = "tag" ]; then | |
| TAG_NAME="$GITHUB_REF_NAME" | |
| if [[ "$TAG_NAME" =~ ([0-9]+)\.([0-9]+)\.([0-9]+)([-+][A-Za-z0-9.-]+)?$ ]]; then | |
| TOOLKIT_VERSION="${BASH_REMATCH[0]}" | |
| echo "✅ Using semantic version: $TOOLKIT_VERSION" | |
| else | |
| echo "❌ Tag '$TAG_NAME' is not a valid semantic version (expected something like 1.2.3 or v1.2.3)" | |
| exit 1 | |
| fi | |
| else | |
| TOOLKIT_VERSION="$PACKAGE_VERSION-rc.$(git rev-parse --short=7 HEAD)" | |
| fi | |
| if npm view @opencrvs/toolkit@$TOOLKIT_VERSION > /dev/null 2>&1; then | |
| echo "Version $TOOLKIT_VERSION already exists on npm." | |
| echo "version-exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Version $TOOLKIT_VERSION does not exist on npm." | |
| echo "version-exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| echo "toolkit-version=$TOOLKIT_VERSION" >> $GITHUB_OUTPUT | |
| working-directory: packages/toolkit | |
| - name: Install dependencies | |
| if: steps.check-version.outputs.version-exists == 'false' | |
| run: yarn install | |
| working-directory: packages/toolkit | |
| - name: Build | |
| if: steps.check-version.outputs.version-exists == 'false' | |
| run: yarn build:all | |
| working-directory: packages/toolkit | |
| - name: Authenticate to npm | |
| if: steps.check-version.outputs.version-exists == 'false' | |
| run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| working-directory: packages/toolkit | |
| - name: Update package.json version | |
| if: steps.check-version.outputs.version-exists == 'false' | |
| run: | | |
| TOOLKIT_VERSION="${{ steps.check-version.outputs.toolkit-version }}" | |
| jq --arg version "$TOOLKIT_VERSION" '.version = $version' package.json > tmp.$$.json && mv tmp.$$.json package.json | |
| working-directory: packages/toolkit | |
| - name: Publish to npm | |
| if: steps.check-version.outputs.version-exists == 'false' | |
| run: npm publish --access public | |
| working-directory: packages/toolkit | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |