You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The GitHub action to delete workflow runs in a repository. This action (written in JavaScript) wraps two Workflow Runs API:
3
-
*[**List repository workflows**](https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-repository-workflows) -- Lists the workflows in a repository.
1
+
# Delete Workflow Runs v2.1.0
4
2
5
-
*[**List workflow runs**](https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#list-workflow-runs) -- List all workflow runs for a workflow.
3
+
A GitHub Action to delete workflow runs in a repository. This Action uses JavaScript and interacts with the GitHub API to manage workflow runs efficiently.
6
4
7
-
*[**Delete a workflow run**](https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#delete-a-workflow-run) -- Delete a specific workflow run.
5
+
## Features
8
6
9
-
The action will calculate the number of days that each workflow run has been retained so far, then use this number to compare with the number you specify for the input parameter "[**`retain_days`**](#3-retain_days)". If the retention days of the workflow run has reached (equal to or greater than) the specified number, the workflow run will be deleted.
10
-
11
-
## What's new?
12
-
* Added ability to match multiple values with "[**`delete_workflow_by_state_pattern`**](#6-delete_workflow_by_state_pattern)" & "[**`delete_run_by_conclusion_pattern`**](#7-delete_run_by_conclusion_pattern)" by using a comma-separated list
13
-
* Removed 'all' option from "[**`delete_workflow_pattern`**](#5-delete_workflow_pattern)", simply don't provide it a value for all workflows to be targeted
14
-
* Added the input parameter "[**`delete_run_by_conclusion_pattern`**](#7-delete_run_by_conclusion_pattern)" - filters runs by conclusion (useful for `skipped`!)
15
-
* Added the input parameter "[**`delete_workflow_by_state_pattern`**](#6-delete_workflow_by_state_pattern)" - filters workflows by state
16
-
* Added the input parameter "[**`dry_run`**](#8-dry_run)" - only logs targeted workflows & runs, no deletions are performed
17
-
* Added ability to filter workflows by workflow filename (in addition to the name)
18
-
##
7
+
- Deletes workflow runs based on retention period and minimum runs to keep.
8
+
- Supports filtering by workflow name, filename, state, or run conclusion.
9
+
- Includes a dry-run mode to simulate deletions without making changes.
10
+
- Skips runs linked to active branches or pull requests (optional).
11
+
- Optimized to avoid uploading `node_modules` by bundling code with `@vercel/ncc`.
19
12
20
13
## Inputs
14
+
21
15
### 1. `token`
22
-
#### Required: YES
23
-
#### Default: `${{ github.token }}`
24
-
The token used to authenticate.
25
-
* If the workflow runs are in the current repository where the action is running, using **`github.token`** is OK, but you must specify additional permissions within your build job (or at a higher level) to allow the default token access to read the repository contents and to write (delete) action-related data, see the examples below. More details, see the [**`GITHUB_TOKEN`**](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow).
26
-
* If the workflow runs are in another repository, you need to use a personal access token (PAT) that must have the **`repo`** scope. More details, see "[Creating a personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)".
16
+
17
+
-**Required**: Yes
18
+
-**Default**: `${{ github.token }}`
19
+
- The GitHub token for authentication. Use `github.token` for the current repository (requires `actions: write` and `contents: read` permissions) or a Personal Access Token (PAT) with `repo` scope for other repositories.
27
20
28
21
### 2. `repository`
29
-
#### Required: YES
30
-
#### Default: `${{ github.repository }}`
31
-
Name of the repository where the workflow runs are located
22
+
23
+
-**Required**: Yes
24
+
-**Default**: `${{ github.repository }}`
25
+
- The repository name in `{owner}/{repo}` format.
32
26
33
27
### 3. `retain_days`
34
-
#### Required: YES
35
-
#### Default: 30
36
-
Amount of days used to compare with the retention days of each workflow
28
+
29
+
-**Required**: Yes
30
+
-**Default**: `30`
31
+
- Number of days to retain workflow runs before deletion.
37
32
38
33
### 4. `keep_minimum_runs`
39
-
#### Required: YES
40
-
#### Default: 6
41
-
Minimum runs to keep for each workflow
34
+
35
+
-**Required**: Yes
36
+
-**Default**: `6`
37
+
- Minimum number of runs to keep per workflow.
42
38
43
39
### 5. `delete_workflow_pattern`
44
-
#### Required: NO
45
-
Name or filename of the workflow (if not set, all workflows are targeted)
40
+
41
+
-**Required**: No
42
+
- Target workflows by name or filename. Omit to target all workflows.
46
43
47
44
### 6. `delete_workflow_by_state_pattern`
48
-
#### Required: NO
49
-
#### Default: 'ALL'
50
-
Filter workflows by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually
51
-
_Multiple state values permitted as a comma-separated list_
45
+
46
+
-**Required**: No
47
+
- Filter workflows by state (comma-separated): `active`, `deleted`, `disabled_fork`, `disabled_inactivity`, `disabled_manually`.
52
48
53
49
### 7. `delete_run_by_conclusion_pattern`
54
-
#### Required: NO
55
-
#### Default: 'ALL'
56
-
Remove runs based on conclusion: action_required, cancelled, failure, skipped, success
57
-
_Multiple conclusion values permitted as a comma-separated list_
Logs simulated changes, no deletions are performed
62
-
##
55
+
56
+
-**Required**: No
57
+
-**Default**: `false`
58
+
- Simulate deletions and log actions without performing them.
63
59
64
60
### 9. `check_branch_existence`
65
-
#### Required: NO
66
-
If true, the removage of a workflow is skipped, when a run is attached to a existing branch. Set to true avoids that check runs are deleted and the checks are not more present. (excludes main)
67
-
##
61
+
62
+
-**Required**: No
63
+
-**Default**: `false`
64
+
- Skip deletion if the run is linked to an existing branch (excludes `main`).
68
65
69
66
### 10. `check_pullrequest_exist`
70
-
#### Required: NO
71
-
If true, the Runs will be checked for linkage to a PR.
72
-
##
73
67
68
+
-**Required**: No
69
+
-**Default**: `false`
70
+
- Skip deletion if the run is linked to a pull request.
71
+
72
+
## Setup
73
+
74
+
1. Ensure the repository has a `package.json` with dependencies and a build script using `@vercel/ncc`.
75
+
2. Run `npm install` and `npm run build` to generate `dist/index.js`.
76
+
3. Commit the `dist/` folder, but exclude `node_modules/` using `.gitignore`.
77
+
4. Use the Action in your workflow as shown below.
74
78
75
79
## Examples
76
-
### In scheduled workflow, see [schedule event](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#schedule).
77
-
> **Tip:** Using scheduled workflow is the recommended way that can periodically, automatically delete old workflow runs.
80
+
81
+
### Scheduled Workflow
82
+
83
+
Run monthly to delete old workflow runs:
84
+
78
85
```yaml
79
86
name: Delete old workflow runs
80
87
on:
81
88
schedule:
82
-
- cron: '0 0 1 * *'
83
-
# Run monthly, at 00:00 on the 1st day of month.
84
-
89
+
- cron: "0 0 1 * *"# Monthly at 00:00 on the 1st
85
90
jobs:
86
-
del_runs:
91
+
delete-runs:
87
92
runs-on: ubuntu-latest
88
93
permissions:
89
94
actions: write
@@ -98,28 +103,29 @@ jobs:
98
103
keep_minimum_runs: 6
99
104
```
100
105
101
-
### In manual triggered workflow, see [workflow_dispatch event](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#workflow_dispatch).
102
-
> In this way, you can manually trigger the workflow at any time to delete old workflow runs. <br/>
103
-

106
+
### Manual Workflow
107
+
108
+
Trigger manually with customizable inputs:
109
+
104
110
```yaml
105
111
name: Delete old workflow runs
106
112
on:
107
113
workflow_dispatch:
108
114
inputs:
109
115
days:
110
-
description: 'Days-worth of runs to keep for each workflow'
116
+
description: "Daysto retain runs"
111
117
required: true
112
-
default: '30'
118
+
default: "30"
113
119
minimum_runs:
114
-
description: 'Minimum runs to keep for each workflow'
120
+
description: "Minimum runs to keep"
115
121
required: true
116
-
default: '6'
122
+
default: "6"
117
123
delete_workflow_pattern:
118
-
description: 'Name or filename of the workflow (if not set, all workflows are targeted)'
124
+
description: "Workflow name or filename (omit for all)"
119
125
required: false
120
126
delete_workflow_by_state_pattern:
121
-
description: 'Filter workflows by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
If you're using this action in a GHE environment, the value you provide for `baseUrl` needs to be the precise and full URL.
176
-
Consult the [documentation](https://docs.github.com/en/enterprise-server@3.14/rest/quickstart?apiVersion=2022-11-28) for your GHE instance to determine the correct URL to use.
183
+
### GitHub Enterprise
177
184
178
-
For this example, let's say that you're running a modern version of GHE and it is accessible at `https://github.mycompany.com`.
179
-
The API endpoint for your GHE instance will (probably) be `https://github.mycompany.com/api/v3`.
180
-
So the resulting configuration would look like this:
185
+
For GitHub Enterprise, specify the API base URL:
181
186
182
187
```yaml
183
188
jobs:
184
-
clean_up:
185
-
# <...>
186
-
steps:
187
-
- name: Delete workflow runs
188
-
uses: Mattraks/delete-workflow-runs@v2
189
-
with:
190
-
# <...>
191
-
baseUrl: https://github.mycompany.com/api/v3
189
+
delete-runs:
190
+
runs-on: ubuntu-latest
191
+
permissions:
192
+
actions: write
193
+
contents: read
194
+
steps:
195
+
- name: Delete old workflow runs
196
+
uses: Mattraks/delete-workflow-runs@v2
197
+
with:
198
+
token: ${{ secrets.PAT_TOKEN }}
199
+
baseUrl: https://github.mycompany.com/api/v3
200
+
repository: mycompany/myrepo
201
+
retain_days: 30
202
+
keep_minimum_runs: 6
192
203
```
193
204
194
-
##
205
+
## Development
206
+
207
+
To build the Action:
208
+
209
+
1. Install dependencies: `npm install`
210
+
2. Build the Action: `npm run build`
211
+
3. Commit the `dist/` folder to the repository.
212
+
213
+
The `node_modules` folder is excluded via `.gitignore` to reduce repository size.
195
214
196
215
## License
197
-
The scripts and documentation in this project are released under the [MIT License](LICENSE).
198
-
##
216
+
217
+
This project is licensed under the [MIT License](LICENSE).
0 commit comments