refactor: extract shared utilities for duplicated code patterns #120
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 | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| paths: | |
| - ".github/workflows/**" | |
| - "src/**" | |
| - "scripts/**" | |
| - "tests/**" | |
| - "assets/**" | |
| - "package.json" | |
| - "bun.lock" | |
| - "tsconfig.json" | |
| - "tsconfig.build.json" | |
| - "biome.json" | |
| - "knip.ts" | |
| - "sgconfig.yml" | |
| - "ast-grep/**" | |
| pull_request: | |
| branches: [main] | |
| paths: | |
| - ".github/workflows/**" | |
| - "src/**" | |
| - "scripts/**" | |
| - "tests/**" | |
| - "assets/**" | |
| - "package.json" | |
| - "bun.lock" | |
| - "tsconfig.json" | |
| - "tsconfig.build.json" | |
| - "biome.json" | |
| - "knip.ts" | |
| - "sgconfig.yml" | |
| - "ast-grep/**" | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| full-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| env: | |
| BUN_INSTALL_ALLOW_SCRIPTS: "@ast-grep/cli" | |
| - name: Run full checks | |
| run: bun run check:ci | |
| - name: Upload coverage reports to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: [full-check] | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install --frozen-lockfile | |
| env: | |
| BUN_INSTALL_ALLOW_SCRIPTS: "@ast-grep/cli" | |
| - name: Build | |
| run: bun run build | |
| - name: Verify build output | |
| run: | | |
| test -f dist/index.js || (echo "ERROR: dist/index.js not found!" && exit 1) | |
| test -f dist/index.d.ts || (echo "ERROR: dist/index.d.ts not found!" && exit 1) | |
| test -f dist/bin/cc-safety-net.js || (echo "ERROR: dist/bin/cc-safety-net.js not found!" && exit 1) | |
| - name: Auto-commit schema changes | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: | | |
| if git diff --quiet assets/cc-safety-net.schema.json; then | |
| echo "No schema changes to commit" | |
| else | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add assets/cc-safety-net.schema.json | |
| git commit -m "chore: auto-update schema.json" | |
| git push | |
| fi | |
| draft-release: | |
| runs-on: ubuntu-latest | |
| needs: [build] | |
| if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - run: git fetch --force --tags | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - name: Generate release notes | |
| id: notes | |
| run: | | |
| NOTES=$(bun run scripts/generate-changelog.ts) | |
| { | |
| echo "notes<<EOF" | |
| echo "$NOTES" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create or update draft release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| EXISTING_DRAFT=$(gh release list --json tagName,isDraft --jq '.[] | select(.isDraft == true and .tagName == "next") | .tagName') | |
| if [ -n "$EXISTING_DRAFT" ]; then | |
| echo "Updating existing draft release..." | |
| gh release edit next \ | |
| --title "Upcoming Changes 🛡️" \ | |
| --notes-file - \ | |
| --draft <<'EOF' | |
| ${{ steps.notes.outputs.notes }} | |
| EOF | |
| else | |
| echo "Creating new draft release..." | |
| gh release create next \ | |
| --title "Upcoming Changes 🛡️" \ | |
| --notes-file - \ | |
| --draft \ | |
| --target ${{ github.sha }} <<'EOF' | |
| ${{ steps.notes.outputs.notes }} | |
| EOF | |
| fi |