Skip to content

Commit c280519

Browse files
committed
Merge branch 'pr/n4_main'
2 parents 2342eb6 + d30d37d commit c280519

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The GitHub action to delete workflow runs in a repository. This action (written
99
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.
1010

1111
## What's new?
12-
* Keep minimum runs feature update.
12+
* Add the input parameter "[**`delete_workflow_pattern`**](#5-delete_workflow_pattern)". Fill in the specified workflow name, this workflow will be processed, if no workflow is specified, all workflows in the repository will be processed.
1313
##
1414

1515
## Inputs
@@ -34,6 +34,10 @@ The number of days that is used to compare with the retention days of each workf
3434
#### Required: YES
3535
#### Default: 6
3636
The minimum runs to keep for each workflow.
37+
38+
### 5. `delete_workflow_pattern`
39+
#### Required: NO
40+
The name of the workflow. if not set then it will target all workflows.
3741
##
3842

3943
## Examples
@@ -75,6 +79,9 @@ on:
7579
description: 'The minimum runs to keep for each workflow.'
7680
required: true
7781
default: 6
82+
delete_workflow_pattern:
83+
description: 'The name of the workflow. if not set then it will target all workflows.'
84+
required: false
7885

7986
jobs:
8087
del_runs:
@@ -87,6 +94,7 @@ jobs:
8794
repository: ${{ github.repository }}
8895
retain_days: ${{ github.event.inputs.days }}
8996
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
97+
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
9098
```
9199
##
92100

action.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
required: true
2424
default: 6
2525

26+
delete_workflow_pattern:
27+
description: 'The name of the workflow. if not set then it will target all workflows.'
28+
required: false
29+
2630
runs:
2731
using: 'node12'
2832
main: 'dist/index.js'

dist/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ async function run() {
66
const repository = core.getInput('repository');
77
const retain_days = Number(core.getInput('retain_days'));
88
const keep_minimum_runs = Number(core.getInput('keep_minimum_runs'));
9+
const delete_workflow_pattern = core.getInput('delete_workflow_pattern');
910
// Split the input 'repository' (format {owner}/{repo}) to be {owner} and {repo}
1011
const splitRepository = repository.split('/');
1112
if (splitRepository.length !== 2 || !splitRepository[0] || !splitRepository[1]) {
@@ -15,11 +16,18 @@ async function run() {
1516
const repo_name = splitRepository[1];
1617
const { Octokit } = require("@octokit/rest");
1718
const octokit = new Octokit({ auth: token });
18-
const workflows = await octokit
19+
let workflows = await octokit
1920
.paginate("GET /repos/:owner/:repo/actions/workflows", {
2021
owner: repo_owner,
2122
repo: repo_name,
2223
});
24+
if (delete_workflow_pattern) {
25+
console.log(`💬 workflows containing '${delete_workflow_pattern}' will be targeted`);
26+
workflows = workflows.filter(
27+
({ name }) => name.indexOf(delete_workflow_pattern) !== -1
28+
);
29+
}
30+
console.log(`💬 found total of ${workflows.length} workflow(s)`);
2331
for (const workflow of workflows) {
2432
core.debug(`Workflow: ${workflow.name} ${workflow.id} ${workflow.state}`);
2533
let del_runs = new Array();

img/example.PNG

-1.35 KB
Loading

0 commit comments

Comments
 (0)