-
Notifications
You must be signed in to change notification settings - Fork 7
198 lines (192 loc) · 8.48 KB
/
monthly_maintenance.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Monthly Maintenence
on:
schedule:
- cron: '0 0 1 * *'
jobs:
create_issue:
name: create_issue
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: read
steps:
- name: Get current month and year
id: date
run: echo "::set-output name=date::$(date +'%B %Y')"
- name: Get previous month
id: prevdate
run: echo "::set-output name=prevdate::$(date -d 'last month' +'%Y-%m-%dT%H:%M:%SZ')"
- name: Get Open Dependabot Pull Requests
id: pull_requests
run: |
{
echo 'pull_requests<<EOF'
curl -X GET \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/revelrylabs/slax/pulls?state=open" \
| jq --raw-output 'map(select(.user.login == "dependabot[bot]")) | .[] | "[\(.title)](\(.html_url))"'
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Get open alerts
id: open_alerts
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.MONTHLY_AUTOMATION }}
with:
route: GET /repos/{owner}/{repo}/dependabot/alerts
owner: revelrylabs
repo: slax
state: "open"
sort: "updated"
per_page: 100
- name: Set open input
id: open_input
run: |
if [ steps.open_alerts.outputs.data.length > 0 ]; then
echo 'alerts<<EOF' >> $GITHUB_OUTPUT
echo '[${{ toJSON(fromJSON(steps.open_alerts.outputs.data).*.updated_at) }}, ${{ toJSON(fromJSON(steps.open_alerts.outputs.data).*.security_advisory.severity) }}, ${{ toJSON(fromJSON(steps.open_alerts.outputs.data).*.html_url) }}]' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo "alerts=[]" >> $GITHUB_OUTPUT
fi
- name: Build objects for open alerts
id: open_objects
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.open_input.outputs.alerts }}
script: '[.[0] as $times | .[1] as $severities | .[2] as $urls | foreach range(0; $times|length) as $i ( {}; . = { "time": $times[$i], "severity": $severities[$i], "url": $urls[$i] } )]'
- name: Get new open alerts
id: new_open_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.open_objects.outputs.output }}
script: 'map(select(.time >= "${{ steps.prevdate.outputs.prevdate }}"))'
- name: Get urls
id: urls
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_open_alerts.outputs.output }}
script: '.[].url'
raw-output: "true"
- name: Get number of new alerts
id: total_open_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_open_alerts.outputs.output }}
script: 'length'
- name: Get number of critical alerts
id: open_critical_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_open_alerts.outputs.output }}
script: 'map(select(.severity == "critical")) | length'
- name: Get number of high alerts
id: open_high_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_open_alerts.outputs.output }}
script: 'map(select(.severity == "high")) | length'
- name: Get number of moderate alerts
id: open_moderate_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_open_alerts.outputs.output }}
script: 'map(select(.severity == "medium")) | length'
- name: Get number of low alerts
id: open_low_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_open_alerts.outputs.output }}
script: 'map(select(.severity == "low")) | length'
- name: Get fixed alerts
id: fixed_alerts
uses: octokit/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.MONTHLY_AUTOMATION }}
with:
route: GET /repos/{owner}/{repo}/dependabot/alerts
owner: revelrylabs
repo: slax
state: "fixed"
sort: "updated"
per_page: 100
- name: Set fixed input
id: fixed_input
run: |
if [ steps.fixed_alerts.outputs.data.length > 0 ]; then
echo 'alerts<<EOF' >> $GITHUB_OUTPUT
echo '[${{ toJSON(fromJSON(steps.fixed_alerts.outputs.data).*.fixed_at) }}, ${{ toJSON(fromJSON(steps.fixed_alerts.outputs.data).*.security_advisory.severity) }}]' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo "alerts=[]" >> $GITHUB_OUTPUT
fi
- name: Build objects for fixed alerts
id: fixed_objects
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.fixed_input.outputs.alerts }}
script: '[.[0] as $times | .[1] as $severities | foreach range(0; $times|length) as $i ( {}; . = { "time": $times[$i], "severity": $severities[$i] } )]'
- name: Get new fixed alerts
id: new_fixed_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.fixed_objects.outputs.output }}
script: 'map(select(.time >= "${{ steps.prevdate.outputs.prevdate }}"))'
- name: Get number of new fixed alerts
id: total_fixed_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_fixed_alerts.outputs.output }}
script: 'length'
- name: Get number of critical alerts
id: fixed_critical_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_fixed_alerts.outputs.output }}
script: 'map(select(.severity == "critical")) | length'
- name: Get number of high alerts
id: fixed_high_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_fixed_alerts.outputs.output }}
script: 'map(select(.severity == "high")) | length'
- name: Get number of moderate alerts
id: fixed_moderate_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_fixed_alerts.outputs.output }}
script: 'map(select(.severity == "medium")) | length'
- name: Get number of low alerts
id: fixed_low_alerts
uses: edwardgeorge/jq-action@main
with:
input: ${{ steps.new_fixed_alerts.outputs.output }}
script: 'map(select(.severity == "low")) | length'
- name: Create monthly maintenence issue
uses: imjohnbo/issue-bot@v3
with:
labels: "dependencies, maintenance"
title: 'Slax - Maintenance - ${{ steps.date.outputs.date }}'
token: ${{ secrets.MONTHLY_AUTOMATION }}
body: |-
_requires [Slax dependabot alerts](https://github.com/revelrylabs/slax/security/dependabot)_ <!-- Link to project's dependabot alerts -->
## Background
Slax currently has ${{steps.total_open_alerts.outputs.output}} new security vulnerabilities (${{steps.open_critical_alerts.outputs.output}} critical, ${{steps.open_high_alerts.outputs.output}} high, ${{steps.open_moderate_alerts.outputs.output}} moderate, and ${{steps.open_low_alerts.outputs.output}} low). The purpose of this ticket is to address Slax's security vulnerabilities.
${{steps.urls.outputs.output}}
Closed last month: ${{steps.total_fixed_alerts.outputs.output}}
Critical: ${{steps.fixed_critical_alerts.outputs.output}}
High: ${{steps.fixed_high_alerts.outputs.output}}
Moderate: ${{steps.fixed_moderate_alerts.outputs.output}}
Low: ${{steps.fixed_low_alerts.outputs.output}}
Open Dependabot pull requests:
${{steps.pull_requests.outputs.pull_requests}}
### Scenario: Update security vulnerabilities
Given I am an Engineer
- [ ] When I manually address dependency conflicts listed [here](https://github.com/revelrylabs/slax/security/dependabot)<!-- Link to project's dependabot alerts -->
- [ ] Then I test by running locally
- [ ] And I merge to master and test in production
### QA / UAT Note
Remember to add a comment when passing this forward with links to:
- [ ] the review app
- [ ] the pull request itself