Skip to content

Commit f07584c

Browse files
committed
Update README
1 parent e43acbf commit f07584c

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# delete-abandoned-branches
2+
3+
Github action to delete abandoned branches.
4+
5+
## Warning
6+
7+
This action WILL delete branches from your repository, so you need to make your due diligence when choosing to use it and with which settings. I am not responsible for any mishaps that might occur.
8+
9+
## Abandoned branches
10+
11+
A branch must meet all the following criteria to be deemed abandoned and safe to delete:
12+
13+
* Must NOT be the default branch (eg `master` or `main`, depending on your repository settings)
14+
* Must NOT be a protected branch
15+
* Must NOT have any open pull requests
16+
* Must NOT be the base of an open pull request of another branch. The base of a pull request is the branch you told GitHub you want to merge your pull request into.
17+
* Must NOT be in an optional list of branches to ignore
18+
* Must be older than a given amount of days
19+
20+
## Inputs
21+
22+
| Name | Mandatory | Default value | Description | Example |
23+
| ------------- | ------------- | ------------- | ------------- | ------------- |
24+
| `ignore_branches` | ❌ | | Comma-separated list of branches to ignore and never delete. You don't need to add your protected branches here. | `foo,bar`
25+
| `last_commit_age_days` | ✅ | `60` | How old in days must be the last commit into the branch for the branch to be deleted. | 90
26+
| `dry_run` | ✅ | `yes` | Whether we're actually deleting branches at all. Possible values: `yes, no` (case sensitive) | `no`
27+
| `github_token` | ✅ | | The github token to use on requests to the github api. You can use the one github actions provide | `${{ github.token }}`
28+
29+
### Note: dry run
30+
31+
By default, the action will only perform a dry run. It will go in, gather all branches that qualify for deletion and give you the list on the actions' output, but without actually deleting anything. Make sure you configure your stuff correctly before setting `dry_run` to `yes`
32+
33+
## Example
34+
35+
The following workflow will run on a schedule (daily at 00:00) and will delete all abandoned branches older than 100 days:
36+
37+
```yaml
38+
name: Quick tests against our own repository
39+
40+
on:
41+
schedule:
42+
- cron: "0 * * * *"
43+
44+
workflow_dispatch:
45+
inputs:
46+
logLevel:
47+
description: 'Log level'
48+
required: true
49+
default: 'warning'
50+
tags:
51+
description: 'Test scenario tags'
52+
53+
jobs:
54+
check_dry_run_no_branches:
55+
runs-on: ubuntu-latest
56+
name: Runs the action with no ignore branches
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v2
60+
61+
- name: Delete those pesky dead branches
62+
uses: phpdocker-io/github-actions-delete-abandoned-branches
63+
id: delete_stuff
64+
with:
65+
github_token: ${{ github.token }}
66+
last_commit_age_days: 100
67+
dry_run: yes
68+
69+
- name: Get output
70+
run: "echo 'Deleted branches: ${{ steps.delete_stuff.outputs.deleted_branches }}'"
71+
72+
```

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ inputs:
1313
required: false
1414
default: ""
1515
last_commit_age_days:
16-
description: "Select for deletion branches with a last commit older than this parameter."
16+
description: "How old in days must be the last commit into the branch for the branch to be deleted."
1717
required: false
1818
default: "60"
1919
dry_run:

0 commit comments

Comments
 (0)