chore: release v0.36.67 #315
Workflow file for this run
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: Cleanup stale branches | |
| on: | |
| # Run weekly on Monday at 06:00 UTC. | |
| schedule: | |
| - cron: "0 6 * * 1" | |
| # Allow manual trigger. | |
| workflow_dispatch: | |
| # Delete head branch right after PR merge. | |
| pull_request: | |
| types: [closed] | |
| permissions: | |
| contents: write | |
| jobs: | |
| # Delete the PR head branch immediately after merge. | |
| delete-pr-branch: | |
| if: github.event_name == 'pull_request' && github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Delete merged branch | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request; | |
| const branch = pr.head.ref; | |
| const protectedNames = new Set(['main', 'master', 'develop', 'release']); | |
| const protectedPrefixes = ['release/', 'hotfix/', 'dependabot/']; | |
| if (pr.head.repo.full_name !== context.repo.owner + '/' + context.repo.repo) { | |
| console.log(`Skipping branch from fork: ${pr.head.repo.full_name}:${branch}`); | |
| return; | |
| } | |
| if (protectedNames.has(branch) || protectedPrefixes.some(prefix => branch.startsWith(prefix))) { | |
| console.log(`Skipping protected branch: ${branch}`); | |
| return; | |
| } | |
| try { | |
| await github.rest.git.deleteRef({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| ref: `heads/${branch}`, | |
| }); | |
| console.log(`Deleted branch: ${branch}`); | |
| } catch (e) { | |
| console.log(`Could not delete ${branch}: ${e.message}`); | |
| } | |
| # Weekly cleanup of old release-plz and claude/* branches. | |
| sweep-stale: | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const protectedBranches = ['main', 'master', 'develop', 'release']; | |
| const protectedPrefixes = ['release/', 'hotfix/', 'dependabot/']; | |
| // Patterns for branches that should be auto-cleaned. | |
| const stalePatterns = [/^release-plz-/, /^claude\//]; | |
| const { data: branches } = await github.rest.repos.listBranches({ | |
| owner, repo, per_page: 100, | |
| }); | |
| let deleted = 0; | |
| for (const branch of branches) { | |
| if (protectedBranches.includes(branch.name)) continue; | |
| if (protectedPrefixes.some(prefix => branch.name.startsWith(prefix))) continue; | |
| if (!stalePatterns.some(p => p.test(branch.name))) continue; | |
| // Only delete if fully merged into main. | |
| try { | |
| const { data: comparison } = await github.rest.repos.compareCommits({ | |
| owner, repo, | |
| base: 'main', | |
| head: branch.name, | |
| }); | |
| // ahead_by == 0 means all commits are in main. | |
| if (comparison.ahead_by !== 0) continue; | |
| } catch { | |
| continue; | |
| } | |
| try { | |
| await github.rest.git.deleteRef({ | |
| owner, repo, | |
| ref: `heads/${branch.name}`, | |
| }); | |
| console.log(`Deleted: ${branch.name}`); | |
| deleted++; | |
| } catch (e) { | |
| console.log(`Failed to delete ${branch.name}: ${e.message}`); | |
| } | |
| } | |
| console.log(`Cleaned up ${deleted} stale branches.`); |