File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Clean Old Branches
2
+
3
+ on :
4
+ workflow_dispatch :
5
+ schedule :
6
+ - cron : ' 5 18 * * *'
7
+
8
+ jobs :
9
+ clean-old-branches :
10
+ runs-on : ubuntu-latest
11
+
12
+ steps :
13
+ - name : Checkout repo
14
+ uses : actions/checkout@v4
15
+ with :
16
+ fetch-depth : 0
17
+
18
+ - name : Clean old branches
19
+ shell : pwsh
20
+ env :
21
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22
+ run : |
23
+ $cutoffDate = (Get-Date).AddDays(-30)
24
+ $repo = gh repo view --json nameWithOwner --jq ".nameWithOwner"
25
+
26
+ Write-Host "Checking repo: $repo"
27
+ $branches = gh api "repos/$repo/branches" --paginate | ConvertFrom-Json
28
+ Write-Host "Total branches: $($branches.Count)"
29
+
30
+ foreach ($branch in $branches) {
31
+ $name = $branch.name
32
+ if ($name -match "^Daily/Release_(\d{14})$") {
33
+ $timestamp = $matches[1]
34
+ try {
35
+ $branchDate = [datetime]::ParseExact($timestamp, "yyyyMMddHHmmss", [System.Globalization.CultureInfo]::InvariantCulture)
36
+ } catch {
37
+ Write-Warning "Failed to parse timestamp for $name"
38
+ continue
39
+ }
40
+
41
+ if ($branchDate -lt $cutoffDate) {
42
+ Write-Host "Deleting old branch: $name (created $branchDate)"
43
+ gh api -X DELETE "repos/$repo/git/refs/heads/$name"
44
+ }
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments