chore: version packages (#9) #10
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: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - 'feature-*' | |
| concurrency: ${{ github.workflow }}-${{ github.ref }} | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| if: github.repository == 'kanyun-inc/octo-cli' && github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.x' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Typecheck | |
| run: pnpm typecheck | |
| - name: Lint | |
| run: pnpm lint | |
| - name: Test | |
| run: pnpm test | |
| - name: Create Release Pull Request or Publish | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| version: pnpm changeset version | |
| publish: pnpm release | |
| title: 'chore: version packages' | |
| commit: 'chore: version packages' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: true | |
| beta-release: | |
| name: Beta Release | |
| runs-on: ubuntu-latest | |
| if: github.repository == 'kanyun-inc/octo-cli' && startsWith(github.ref, 'refs/heads/feature-') | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.x' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Check pre-release mode | |
| id: check-pre | |
| run: | | |
| if [ -f ".changeset/pre.json" ]; then | |
| TAG=$(jq -r '.tag' .changeset/pre.json) | |
| if [ "$TAG" = "beta" ]; then | |
| echo "is_pre=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "::warning::pre.json exists but tag is '$TAG', expected 'beta'. Skipping." | |
| echo "is_pre=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "is_pre=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Skip notice | |
| if: steps.check-pre.outputs.is_pre != 'true' | |
| run: echo "::notice::Not in beta pre-release mode. Skipping beta publish." | |
| - name: Version packages (beta) | |
| if: steps.check-pre.outputs.is_pre == 'true' | |
| run: pnpm changeset version | |
| - name: Check for version changes | |
| if: steps.check-pre.outputs.is_pre == 'true' | |
| id: check-version | |
| run: | | |
| if git diff --quiet package.json; then | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| echo "::notice::No version changes detected. Package may already be at this version." | |
| else | |
| NEW_VERSION=$(node -e "console.log(require('./package.json').version)") | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "::notice::Version bumped to $NEW_VERSION" | |
| fi | |
| - name: Typecheck | |
| if: steps.check-pre.outputs.is_pre == 'true' && steps.check-version.outputs.has_changes == 'true' | |
| run: pnpm typecheck | |
| - name: Test | |
| if: steps.check-pre.outputs.is_pre == 'true' && steps.check-version.outputs.has_changes == 'true' | |
| run: pnpm test | |
| - name: Build | |
| if: steps.check-pre.outputs.is_pre == 'true' && steps.check-version.outputs.has_changes == 'true' | |
| run: pnpm build | |
| - name: Publish beta to npm | |
| if: steps.check-pre.outputs.is_pre == 'true' && steps.check-version.outputs.has_changes == 'true' | |
| run: pnpm changeset publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| NPM_CONFIG_PROVENANCE: true | |
| - name: Commit version bump back to branch | |
| if: steps.check-pre.outputs.is_pre == 'true' && steps.check-version.outputs.has_changes == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add package.json pnpm-lock.yaml CHANGELOG.md .changeset/pre.json | |
| git commit -m "chore: release beta ${{ steps.check-version.outputs.new_version }} [skip ci]" | |
| git push origin HEAD:${{ github.ref_name }} |