release: bump versions #576
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 workflow is the single npm Trusted Publisher entrypoint. | |
| # It handles both stable releases and snapshot releases. | |
| name: Publish npm Package | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - v2 | |
| workflow_dispatch: | |
| inputs: | |
| release_mode: | |
| description: Release mode | |
| required: true | |
| default: snapshot | |
| type: choice | |
| options: | |
| - snapshot | |
| - stable | |
| commit_sha: | |
| description: Commit SHA for snapshot publishing (optional) | |
| required: false | |
| type: string | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| id-token: write | |
| jobs: | |
| handle_snapshot_command: | |
| if: github.event_name == 'workflow_dispatch' || (github.event_name == 'issue_comment' && github.event.issue.pull_request) | |
| runs-on: ubuntu-latest | |
| outputs: | |
| command_found: ${{ steps.check_command.outputs.command_found || 'false' }} | |
| status_comment_id: ${{ steps.comment_deployment.outputs.comment_id || '' }} | |
| pr_sha: ${{ steps.pr_details.outputs.sha || '' }} | |
| steps: | |
| - name: Check for snapshot-release command | |
| if: github.event_name == 'issue_comment' | |
| id: check_command | |
| run: | | |
| comment="${{ github.event.comment.body }}" | |
| comment=$(echo "$comment" | xargs) | |
| if [[ "$comment" =~ ^/snapshot-release ]]; then | |
| echo "command_found=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "command_found=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: React to comment | |
| if: github.event_name == 'issue_comment' && steps.check_command.outputs.command_found == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.reactions.createForIssueComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: ${{ github.event.comment.id }}, | |
| content: 'rocket' | |
| }); | |
| - name: Get PR details | |
| if: github.event_name == 'issue_comment' && steps.check_command.outputs.command_found == 'true' | |
| id: pr_details | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: ${{ github.event.issue.number }} | |
| }); | |
| core.setOutput('sha', pr.head.sha); | |
| - name: Comment deployment started | |
| if: github.event_name == 'issue_comment' && steps.check_command.outputs.command_found == 'true' | |
| id: comment_deployment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { data: comment } = await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: ${{ github.event.issue.number }}, | |
| body: '🚀 Starting snapshot release... This may take a few minutes.' | |
| }); | |
| core.setOutput('comment_id', comment.id); | |
| release: | |
| if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'stable') | |
| runs-on: ubuntu-latest | |
| # Must match npm Trusted Publisher environment configuration. | |
| environment: PUBLISH_NPM_REGISTRY_TOKEN | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| # npm Trusted Publishing requires modern Node/npm versions. | |
| node-version: '24' | |
| cache: 'pnpm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: pnpm -r install | |
| - name: Type Check UIKit | |
| run: pnpm --filter @tidbcloud/uikit type-check | |
| - name: Build Package | |
| run: pnpm -r build | |
| - name: Create Release Pull Request or Publish to npm | |
| uses: changesets/action@v1 | |
| with: | |
| commit: 'release: bump versions' | |
| title: 'release: bump versions' | |
| publish: pnpm release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: true | |
| snapshot_release: | |
| needs: handle_snapshot_command | |
| if: | | |
| (github.event_name == 'issue_comment' && needs.handle_snapshot_command.outputs.command_found == 'true') || | |
| (github.event_name == 'workflow_dispatch' && github.event.inputs.release_mode == 'snapshot') | |
| runs-on: ubuntu-latest | |
| # Must match npm Trusted Publisher environment configuration. | |
| environment: PUBLISH_NPM_REGISTRY_TOKEN | |
| concurrency: ${{ github.workflow }}-${{ github.ref }}-snapshot | |
| outputs: | |
| version: ${{ steps.get_version.outputs.version }} | |
| steps: | |
| - name: Checkout Repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event_name == 'issue_comment' && needs.handle_snapshot_command.outputs.pr_sha || github.event.inputs.commit_sha || github.sha }} | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| cache: 'pnpm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Type Check UIKit | |
| run: pnpm --filter @tidbcloud/uikit type-check | |
| - name: Build Packages | |
| run: pnpm build | |
| - name: Configure Git User | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Create Snapshot Changeset File | |
| run: | | |
| echo "---" > .changeset/snapshot-${{ github.run_id }}.md | |
| echo "'@tidbcloud/uikit': patch" >> .changeset/snapshot-${{ github.run_id }}.md | |
| echo "---" >> .changeset/snapshot-${{ github.run_id }}.md | |
| echo "" >> .changeset/snapshot-${{ github.run_id }}.md | |
| echo "chore: snapshot release" >> .changeset/snapshot-${{ github.run_id }}.md | |
| - name: Bump Version for Snapshot | |
| run: pnpm exec changeset version --snapshot | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish Snapshot to npm under experimental tag | |
| run: pnpm exec changeset publish --tag experimental | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: true | |
| - name: Get Published Version | |
| id: get_version | |
| run: echo "version=$(node -p "require('./packages/uikit/package.json').version")" >> $GITHUB_OUTPUT | |
| notify_snapshot_result: | |
| needs: [handle_snapshot_command, snapshot_release] | |
| if: github.event_name == 'issue_comment' && always() && needs.handle_snapshot_command.outputs.command_found == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Update comment with success | |
| if: needs.snapshot_release.result == 'success' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: ${{ needs.handle_snapshot_command.outputs.status_comment_id }}, | |
| body: `✅ Snapshot release published successfully! | |
| 📦 **Version**: \`${{ needs.snapshot_release.outputs.version }}\` | |
| 🏷️ **Tag**: \`experimental\` | |
| 🔗 **npm**: https://www.npmjs.com/package/@tidbcloud/uikit/v/${{ needs.snapshot_release.outputs.version }}?activeTab=readme | |
| 📥 **Install**: | |
| \`\`\` | |
| pnpm install @tidbcloud/uikit@${{ needs.snapshot_release.outputs.version }} | |
| \`\`\` | |
| You can test this version in your project now.` | |
| }); | |
| - name: Update comment with failure | |
| if: needs.snapshot_release.result == 'failure' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| await github.rest.issues.updateComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: ${{ needs.handle_snapshot_command.outputs.status_comment_id }}, | |
| body: '❌ Snapshot release failed. Please check the [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details.' | |
| }); |