chore: integrate auto-release into ci workflow with dynamic Anthropic… #79
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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| release: | |
| types: [published] | |
| jobs: | |
| build-and-test: | |
| name: Build and Test | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| node-version: [20.x] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Run format check | |
| run: npm run format:check | |
| - name: Run lint | |
| run: npm run lint | |
| - name: Compile TypeScript | |
| run: npm run compile | |
| # Note: Integration tests are not run in CI because VS Code debug sessions | |
| # don't reliably initialize in headless CI environments. Tests run automatically | |
| # via git pre-commit hooks for all local commits. See README for details. | |
| auto-release: | |
| name: Auto Release | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, '[skip ci]') | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Determine next version | |
| id: version | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const latestRelease = await github.rest.repos.getLatestRelease({ owner: context.repo.owner, repo: context.repo.repo }).catch(()=>null); | |
| let nextVersion; | |
| if (latestRelease) { | |
| const prevTagRaw = latestRelease.data.tag_name || ''; | |
| const prev = prevTagRaw.replace(/^v/, ''); | |
| const parts = prev.split('.'); | |
| if (parts.length !== 3 || parts.some(p => isNaN(Number(p)))) { | |
| core.setFailed(`Latest release tag '${prevTagRaw}' is not semver x.y.z`); | |
| return; | |
| } | |
| parts[2] = String(Number(parts[2]) + 1); | |
| nextVersion = parts.join('.'); | |
| } else { | |
| nextVersion = '0.0.1'; | |
| } | |
| core.info(`Computed next version: ${nextVersion}`); | |
| core.setOutput('version', nextVersion); | |
| - name: Update package.json version | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); pkg.version=process.env.VERSION; pkg._versionComment='Version is auto-generated by the CI auto-release workflow. Manual edits are overwritten.'; fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2)+ '\n');" | |
| git config user.name "github-actions" | |
| git config user.email "[email protected]" | |
| git add package.json | |
| git commit -m "chore: release ${VERSION} [skip ci]" || echo "No changes to commit" | |
| - name: Create and push tag | |
| env: | |
| VERSION: ${{ steps.version.outputs.version }} | |
| run: | | |
| if git rev-parse ${VERSION} >/dev/null 2>&1; then echo "Tag ${VERSION} already exists"; else git tag ${VERSION}; git push origin ${VERSION}; fi | |
| git push origin HEAD:main | |
| - name: Generate release notes & create release | |
| uses: ./.github/actions/anthropic-release-notes | |
| with: | |
| anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }} | |
| language: en | |
| model: claude-3-5-sonnet-latest | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| version: ${{ steps.version.outputs.version }} | |
| - name: Output release notes | |
| if: steps.version.outputs.version | |
| run: echo "Release notes generated for version ${{ steps.version.outputs.version }}" | |
| package: | |
| name: Package Extension | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Install vsce | |
| run: npm install -g @vscode/vsce | |
| - name: Package extension | |
| run: vsce package | |
| - name: Upload VSIX artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: vsix-package | |
| path: '*.vsix' | |
| retention-days: 30 | |
| publish: | |
| name: Publish to VS Code Marketplace | |
| runs-on: ubuntu-latest | |
| needs: package | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.x | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Install vsce | |
| run: npm install -g @vscode/vsce | |
| - name: Publish to VS Code Marketplace | |
| env: | |
| VSCE_PAT: ${{ secrets.VSCE_PAT }} | |
| run: vsce publish -p $VSCE_PAT | |
| - name: Download VSIX artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: vsix-package | |
| - name: Upload VSIX to GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: '*.vsix' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |