Repository navigation
Publish package to NPM #36
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
| name: Publish package to NPM | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: 'Branch to publish from' | |
| required: true | |
| default: 'main' | |
| type: choice | |
| options: | |
| - main | |
| - release-1.10 | |
| - release-1.9 | |
| - release-1.8 | |
| jobs: | |
| version: | |
| name: Version Packages | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v7 | |
| with: | |
| ref: ${{ inputs.branch }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version-file: '.nvmrc' | |
| - name: Install Dependencies | |
| run: yarn install --immutable | |
| - name: Build | |
| run: yarn build | |
| - name: Update npm | |
| run: npm install -g npm@11 | |
| - name: Detect latest GA branch | |
| id: detect-ga | |
| run: | | |
| # Auto-detect the latest GA release branch: | |
| # 1. git ls-remote lists all remote release-* branches without cloning history | |
| # 2. sed strips everything up to "release-", leaving just the version (e.g., "1.10") | |
| # 3. sort -t. splits on "." and sorts each field numerically (-n), so | |
| # 1.9 < 1.10 < 1.11 < 2.1 (lexicographic sort would wrongly put 1.10 before 1.9) | |
| # 4. tail -1 picks the highest version | |
| LATEST_GA=$(git ls-remote --heads origin 'refs/heads/release-*' \ | |
| | sed 's|.*refs/heads/release-||' \ | |
| | sort -t. -k1,1n -k2,2n \ | |
| | tail -1) | |
| echo "branch=release-${LATEST_GA}" >> "$GITHUB_OUTPUT" | |
| - name: Publish | |
| run: | | |
| if [ "${{ inputs.branch }}" = "main" ]; then | |
| npm publish --access public --tag next | |
| elif [ "${{ inputs.branch }}" = "${{ steps.detect-ga.outputs.branch }}" ]; then | |
| npm publish --access public --tag latest | |
| npm dist-tag add "$(node -p "require('./package.json').name")@$(node -p "require('./package.json').version")" "${{ inputs.branch }}" | |
| else | |
| npm publish --access public --tag ${{ inputs.branch }} | |
| fi |