Publish @nmfs-radfish/react-radfish to NPM #5
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 @nmfs-radfish/react-radfish to NPM | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: 'Version bump type' | |
| required: true | |
| type: choice | |
| options: | |
| - patch # 1.1.2 → 1.1.3 | |
| - minor # 1.1.2 → 1.2.0 | |
| - major # 1.1.2 → 2.0.0 | |
| - prerelease # 1.1.2-rc.1 → 1.1.2-rc.2 | |
| - prepatch # 1.1.2 → 1.1.3-rc.1 | |
| - preminor # 1.1.2 → 1.2.0-rc.1 | |
| - premajor # 1.1.2 → 2.0.0-rc.1 | |
| permissions: | |
| contents: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check admin permissions | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: { permission } } = await github.rest.repos.getCollaboratorPermissionLevel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| username: context.actor | |
| }); | |
| if (permission !== 'admin') { | |
| core.setFailed(`User ${context.actor} does not have admin permissions. Current permission: ${permission}`); | |
| } | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.ref }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: npm install --legacy-peer-deps | |
| - name: Run tests | |
| run: | | |
| set -e | |
| npm test -- --run | |
| working-directory: packages/react-radfish | |
| - name: Bump version (no git operations) | |
| id: bump-version | |
| run: | | |
| set -e | |
| # Bump version (ignore output) | |
| npm version ${{ inputs.version_type }} --preid=rc --no-git-tag-version --legacy-peer-deps | |
| # Query the updated package.json for clean version | |
| NEW_VERSION=$(jq -r '.version' package.json) | |
| echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
| working-directory: packages/react-radfish | |
| - name: Build package | |
| run: | | |
| set -e | |
| npm run build | |
| working-directory: packages/react-radfish | |
| - name: Publish to NPM | |
| id: npm-publish | |
| run: | | |
| set -e | |
| if [[ "${{ steps.bump-version.outputs.new_version }}" == *"-rc."* ]]; then | |
| npm publish --tag beta | |
| else | |
| npm publish | |
| fi | |
| working-directory: packages/react-radfish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Commit version bump | |
| if: success() | |
| run: | | |
| set -e | |
| git add packages/react-radfish/package.json | |
| git commit -m "chore(release): bump @nmfs-radfish/react-radfish to ${{ steps.bump-version.outputs.new_version }}" | |
| - name: Create and push tags | |
| if: success() | |
| run: | | |
| set -e | |
| git tag "react-radfish@${{ steps.bump-version.outputs.new_version }}" | |
| git push origin HEAD | |
| if [[ "${{ steps.bump-version.outputs.new_version }}" == *"-rc."* ]]; then | |
| # For prereleases, only tag and push beta | |
| git tag -f "react-radfish@beta" | |
| git push origin "react-radfish@${{ steps.bump-version.outputs.new_version }}" "react-radfish@beta" --force | |
| else | |
| # For regular releases, only tag and push latest | |
| git tag -f "react-radfish@latest" | |
| git push origin "react-radfish@${{ steps.bump-version.outputs.new_version }}" "react-radfish@latest" --force | |
| fi | |
| - name: Create GitHub Release | |
| if: success() | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: "react-radfish@${{ steps.bump-version.outputs.new_version }}" | |
| release_name: "react-radfish@${{ steps.bump-version.outputs.new_version }}" | |
| body: | | |
| Release of @nmfs-radfish/react-radfish version ${{ steps.bump-version.outputs.new_version }} | |
| ## Changes | |
| See [commit history](https://github.com/${{ github.repository }}/commits/react-radfish@${{ steps.bump-version.outputs.new_version }}) for detailed changes. | |
| draft: false | |
| prerelease: ${{ contains(steps.bump-version.outputs.new_version, '-rc.') }} | |
| - name: Rollback version on failure | |
| if: failure() && steps.bump-version.conclusion == 'success' | |
| run: | | |
| set -e | |
| git checkout -- packages/react-radfish/package.json | |
| echo "Version bump rolled back due to publish failure" | |
| working-directory: . |