File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Prune stale branches
2
+ on :
3
+ workflow_dispatch :
4
+ schedule :
5
+ - cron : ' 30 1 * * *' # run every day at 01:30 UTC
6
+
7
+ jobs :
8
+ stale-branches :
9
+ runs-on : ubuntu-latest
10
+ env :
11
+ ORG : nginx
12
+ REPO : documentation
13
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
14
+ permissions :
15
+ contents : write
16
+ steps :
17
+ - name : Prune all stale branches
18
+ run : |
19
+ HAS_MORE="true"
20
+
21
+ while [ "$HAS_MORE" == "true" ]; do
22
+ RESPONSE=$(curl -L -s \
23
+ -X GET \
24
+ -H "Accept: application/json" \
25
+ -s "https://github.com/${{env.ORG}}/${{env.REPO}}/branches/stale")
26
+
27
+ HAS_MORE=$(echo "$RESPONSE" | jq -r '.payload.has_more')
28
+ BRANCHES=$(echo "$RESPONSE" | jq -r '.payload.branches[].name')
29
+
30
+ for BRANCH in $BRANCHES; do
31
+ echo "Deleting branch $BRANCH..."
32
+ DELETE_RESPONSE=$(curl -L -s \
33
+ -X DELETE \
34
+ -H "Accept: application/vnd.github+json" \
35
+ -H "Authorization: Bearer ${{env.GITHUB_TOKEN}}" \
36
+ -H "X-GitHub-Api-Version: 2022-11-28" \
37
+ https://api.github.com/repos/${{env.ORG}}/${{env.REPO}}/git/refs/heads/$BRANCH)
38
+ echo "Delete response for branch $BRANCH: $DELETE_RESPONSE"
39
+ done
40
+ done
41
+
You can’t perform that action at this time.
0 commit comments