-
-
Notifications
You must be signed in to change notification settings - Fork 15
169 lines (161 loc) · 6.79 KB
/
clean-logs.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---
# Copied from: rasa/dotfiles/.github/workflows/clean-logs.yml
# EDIT THE ABOVE FILE, NOT THIS COPY, OR YOUR CHANGES WILL BE LOST!
# yamllint disable rule:line-length
# $schema https://json.schemastore.org/github-workflow.json
# checkov:skip=CKV_GHA_7:The build output cannot be affected by user parameters
# other than the build entry point and the top-level source location.
# GitHub Actions workflow_dispatch inputs MUST be empty.
name: clean-workflows
on: # yamllint disable-line rule:truthy
schedule:
# runs at 20:02 UTC (12:02 PST) every day.
- cron: "02 20 * * *"
# ┬ ┬ ┬ ┬ ┬ # * : run every 5 min/every 1 hour/every 1 day/every 1 mon
# │ │ │ │ └─ day of week (0-6 or SUN-SAT) # */X : run every X min/every X hour/every X day/every X mon
# │ │ │ └──── month (1-12 or JAN-DEC) # A,B : run when min/hour/day/mon = A or B
# │ │ └─────── day of month (1-31) # A-B : run every min/hour/day/mon between A and B
# │ └────────── hour (0-23) (UTC/GMT+0 time) # A-B/X: run every X min/hour/day/mon between A and B
# └───────────── minute (0-59) # Ex: '0 9-17/2 * * 1-5' : 9/11/1/3/5 on Mon/Tue/Wed/Thu/Fri
workflow_call: # Required so this workflow can be called from another workflow
inputs:
retain_days:
default: "30"
type: string
keep_minimum_runs:
default: "6"
type: string
delete_workflow_pattern:
type: string
delete_workflow_by_state_pattern:
default: ALL
type: string
delete_run_by_conclusion_pattern:
default: ALL
type: string
dry_run:
type: boolean
check_branch_existence:
default: "Keep"
type: string
check_pullrequest_exist:
default: "Keep"
type: string
repository:
type: string
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
inputs:
# checkov:skip=CKV_GHA_7
retain_days:
description: Days to keep
# Days-worth of runs to keep for each workflow
required: true
default: "30"
# checkov:skip=CKV_GHA_7
keep_minimum_runs:
description: Runs to keep
# Minimum runs to keep for each workflow
required: true
default: "6"
# checkov:skip=CKV_GHA_7
delete_workflow_pattern:
description: "Workflow name/filename (optional)"
# Name or filename of the workflow (if not set, all workflows are targeted)
# checkov:skip=CKV_GHA_7
delete_workflow_by_state_pattern:
description: State to clean
# "Filter workflows by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually"
required: true
default: ALL
type: choice
options:
- ALL
- active
- deleted
- disabled_inactivity
- disabled_manually
# checkov:skip=CKV_GHA_7
delete_run_by_conclusion_pattern:
description: Conclusion to clean
# "Remove runs based on conclusion: action_required, cancelled, failure, skipped, success"
required: true
default: ALL
type: choice
options:
- ALL
- "Unsuccessful: action_required,cancelled,failure,skipped"
- action_required
- cancelled
- failure
- skipped
- success
# checkov:skip=CKV_GHA_7
dry_run:
description: Dry run only
type: boolean
# checkov:skip=CKV_GHA_7
check_branch_existence:
description: Clean workflows of existing branches
# If the workflow was triggered by a branch, the branch must be deleted before the workflow run is deleted as well.
default: "Keep"
type: choice
options:
- "Keep"
- "Delete"
# checkov:skip=CKV_GHA_7
check_pullrequest_exist:
description: Clean workflows for active PRs
# If the run is linked to a pull request, the deletion is skipped.
default: "Keep"
type: choice
options:
- "Keep"
- "Delete"
# checkov:skip=CKV_GHA_7
repository:
description: Repository (user/repo) (optional)
# (default is current repository).
type: string
default: ""
concurrency:
# Group workflow jobs so new commits cancels in-progress execution triggered by previous commits.
# Source: https://mail.python.org/archives/list/[email protected]/thread/PCBCQMJF64JGRBOX7E2EE4YLKHT4DI55/
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
jobs:
clean-logs:
runs-on: ubuntu-latest
steps:
# Was crazy-max/[email protected]
# but it reports a deprecation error:
# Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/github-script@v6.
- name: rasa/ghaction-dump-context@master
uses: rasa/ghaction-dump-context@master
- name: Scheduled run (github.event_name == 'schedule')
if: github.event_name == 'schedule'
uses: rasa/delete-workflow-runs@main
with:
repository: ${{ github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}
retain_days: "30" # default: 30
keep_minimum_runs: "6" # default: 6
check_branch_existence: "Keep" # default: Keep
check_pullrequest_exist: "Keep" # default: Keep
- name: Non-scheduled run (github.event_name != 'schedule')
if: github.event_name != 'schedule'
uses: rasa/delete-workflow-runs@main
with:
repository: ${{ github.event.inputs.repository || github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}
retain_days: ${{ github.event.inputs.retain_days }}
keep_minimum_runs: ${{ github.event.inputs.keep_minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
delete_run_by_conclusion_pattern: ${{
startsWith(github.event.inputs.delete_run_by_conclusion_pattern, 'Unsuccessful:')
&& 'action_required,cancelled,failure,skipped'
|| github.event.inputs.delete_run_by_conclusion_pattern
}}
check_branch_existence: ${{ startsWith(github.event.inputs.check_branch_existence, 'Keep') && 'Y' || '' }}
check_pullrequest_exist: ${{ startsWith(github.event.inputs.check_pullrequest_exist, 'Keep') && 'Y' || '' }}
dry_run: ${{ (github.event.inputs.dry_run == true) && 'Y' || '' }}
# cSpell:ignore ghaction, Mattraks, pullrequest