Skip to content

Remove stale branches #78

Remove stale branches

Remove stale branches #78

#
# SPDX-FileCopyrightText: 2024 Lifely
# SPDX-License-Identifier: EUPL-1.2+
#
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-latest
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 the ZAC repository 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/infonl/dimpact-provisioning|View Workflow>"
}
]
}
]