Skip to content

Commit 4caec8a

Browse files
authored
chore: 오래된 브랜치 제거하는 workflow 추가
This workflow automatically deletes branches that haven't had any commits in the last 7 days, excluding 'main' and 'dev'. It runs on a schedule every Friday and can also be triggered manually.
1 parent 16b6715 commit 4caec8a

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
on:
2+
schedule:
3+
- cron: "0 0 * * 5"
4+
workflow_dispatch:
5+
6+
jobs:
7+
cleanup:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Delete old branches
11+
uses: actions/github-script@v7
12+
with:
13+
script: |
14+
const owner = context.repo.owner;
15+
const repo = context.repo.repo;
16+
const days = 7;
17+
const cutoff = new Date(Date.now() - days*24*60*60*1000);
18+
19+
const branches = await github.paginate(github.reset.repose.listBranches, { owner, repo });
20+
21+
for (const branch of branches){
22+
if(branch.name === 'main' || branch.name ==='dev') continue;
23+
24+
const commits = await github.rest.repos.listCommits({
25+
owner,
26+
repo,
27+
sha: branch.name,
28+
per_page: 1
29+
})
30+
31+
const lastCommitDate = new Date(commits.data[0].commit.committer.date);
32+
33+
if(lastCommitDate < cutoff ) {
34+
console.log(`Deleting ${branch.name}`);
35+
await github.rest.git.deleteRef({
36+
owner,
37+
repo,
38+
ref: `heads/${branch.name}`
39+
})
40+
}
41+
}

0 commit comments

Comments
 (0)