chore(release): version packages (#94) #83
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: ${{ github.workflow }}-${{ github.ref }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Create Release Pull Request or Publish | |
| id: changesets | |
| uses: changesets/action@v1 | |
| with: | |
| version: pnpm run version | |
| publish: echo "Publishing disabled - handled by release workflow" | |
| title: 'chore(release): version packages' | |
| commit: 'chore(release): version packages' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
| - name: Update Release PR Description | |
| if: steps.changesets.outputs.pullRequestNumber | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.PAT_TOKEN }} | |
| script: | | |
| const prNumber = ${{ steps.changesets.outputs.pullRequestNumber }}; | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber | |
| }); | |
| // Extract the package versions and changelog section | |
| const body = pr.body || ''; | |
| // Keep everything after the misleading intro text | |
| // The useful content starts with package names like "think-app@" | |
| const contentMatch = body.match(/(think-[\w-]+@[\s\S]*)/); | |
| let releases = contentMatch ? contentMatch[1] : body; | |
| // Format releases content: | |
| // - Convert package names to H2 headings | |
| // - Normalize bullet points to dashes | |
| releases = releases | |
| .replace(/^(think-[\w-]+@[\d.]+)/gm, '## $1') | |
| .replace(/^\* /gm, '- ') | |
| .replace(/^ \* /gm, ' - '); | |
| const newBody = `## Release Summary | |
| This PR updates version numbers and changelogs. When merged, it will trigger a new release build. | |
| **When merged:** | |
| - Package versions are updated | |
| - CHANGELOG.md files are updated | |
| - A git tag is created (e.g., \`v0.6.0\`) | |
| - GitHub Actions builds macOS app, Windows app, and Chrome extension | |
| --- | |
| ${releases}`.replace(/^ +/gm, ''); | |
| await github.rest.pulls.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| body: newBody | |
| }); | |
| - name: Create Release Tag | |
| if: steps.changesets.outputs.hasChangesets == 'false' | |
| run: | | |
| VERSION=$(node -p "require('./app/package.json').version") | |
| if ! git rev-parse "v$VERSION" >/dev/null 2>&1; then | |
| git tag "v$VERSION" | |
| git push origin "v$VERSION" | |
| echo "Created and pushed tag v$VERSION" | |
| else | |
| echo "Tag v$VERSION already exists" | |
| fi |