chore: version packages (#10) #2
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 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Enable Corepack | |
| run: corepack enable | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run tests and linting | |
| run: | | |
| pnpm test | |
| pnpm lint | |
| - name: Create Release PR or Tag | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| version: pnpm run version | |
| publish: pnpm run release | |
| commit: "chore: version packages" | |
| title: "chore: version packages" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create GitHub Release | |
| if: steps.changesets.outputs.published == 'true' | |
| run: | | |
| # Get the version from package.json using jq | |
| VERSION=$(jq -r '.version' package.json) | |
| TAG="v${VERSION}" | |
| # Wait for tag to be available (changesets creates it asynchronously) | |
| # Total wait time: 20 seconds (10 attempts × 2 seconds) | |
| MAX_ATTEMPTS=10 | |
| SLEEP_SECONDS=2 | |
| echo "Waiting for tag $TAG to be available..." | |
| for i in $(seq 1 $MAX_ATTEMPTS); do | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "Tag $TAG found" | |
| break | |
| fi | |
| if [ $i -eq $MAX_ATTEMPTS ]; then | |
| echo "Error: Tag $TAG not found after waiting ${MAX_ATTEMPTS} attempts ($(($MAX_ATTEMPTS * $SLEEP_SECONDS)) seconds total)" | |
| exit 1 | |
| fi | |
| echo "Attempt $i/$MAX_ATTEMPTS: Tag not yet available, waiting..." | |
| sleep $SLEEP_SECONDS | |
| done | |
| # Create GitHub release using gh CLI | |
| gh release create "$TAG" \ | |
| --title "$TAG" \ | |
| --notes "See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details." | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |