-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (83 loc) · 2.96 KB
/
remove-stale-branches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Remove stale branches
on:
schedule:
- cron: "0 0 * * *"
# Allow workflow to be manually run from the GitHub UI
workflow_dispatch:
jobs:
remove_stale_branches:
runs-on: ubuntu-24.04
name: remove stale branches
steps:
- name: remove stale branches
uses: techdecember/github-action-inactive-branches@7aca3178001bdbff984c3eeb3eeb0f972bd75ae4 # 1.2.1
id: deleted_branches
with:
github_token: ${{ github.token }}
last_commit_age_days: 100
dry_run: yes
ignore_suffix: _keep_me
- name: Get output
run: "echo 'Stale branches: ${{ steps.deleted_branches.outputs.deleted_branches }}'"
- name: Format output for Slack
id: format_slack
run: |
{
echo 'formatted_branches<<EOF'
echo "${{ steps.deleted_branches.outputs.deleted_branches }}" | tr \' \" | jq -r .[] | awk '{printf("%s\\n", $0)}'
echo ""
echo EOF
} >> $GITHUB_ENV
- name: Send slack message with branches that can be deleted
if: steps.deleted_branches.outputs.deleted_branches != '[]'
uses: slackapi/slack-github-action@485a9d42d3a73031f12ec201c457e2162c45d02d # v2.0.0
with:
webhook-type: incoming-webhook
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
payload-templated: true
payload: |
"text": "Stale branches detected",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hi :wave:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "I have identified some branches on `${{ github.event.repository.name }}` that seem stale and could probably be removed:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```${{ env.formatted_branches }}```"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "I will only alert for an unprotected branch that has been abandonded for over a 100 days and without an open PR. If you want to keep a branch you might consider to add a `_keep_me` suffix to the branch name so I will ignore it."
}
]
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "Powered by GitHub Actions | <https://github.com/sbl/${{ github.event.repository.name }}|View Workflow>"
}
]
}
]