-
-
Notifications
You must be signed in to change notification settings - Fork 7
242 lines (231 loc) · 8.79 KB
/
update_bug_report.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: 🚀 Update Bug Report
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads
on:
# used for testing this action
# you shouldn't use this trigger in production
push:
branches:
- main
# used for testing this action
# you shouldn't use this trigger in production
pull_request:
branches: [main]
# specific to this workflow
create:
delete:
label:
types: [created, edited, deleted]
# use in production
workflow_dispatch:
# use in production
# needs ref setup
release:
branches:
- main
types: [published]
# use in production
schedule:
# runs daily at midnight
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule
- cron: '0 0 * * *'
jobs:
pre:
name: Prepare context for other jobs
runs-on: ubuntu-latest
outputs:
# needed in order to reference the local action
branch: ${{ env.job_ref }}
branches: ${{ steps.branches.outputs.result }}
labels: ${{ steps.labels.outputs.result }}
long: ${{ steps.long.outputs.result }}
long2: ${{ steps.long2.outputs.result }}
dates: ${{ steps.dates.outputs.result }}
year_end: ${{ steps.year_end.outputs.result }}
timestamp: ${{ steps.timestamp.outputs.value }}
steps:
- name: Setting branch for committing
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
run: |
BRANCH=""
if [ ${{ github.event_name == 'release' }} == true ]; then
BRANCH=${{ github.event.release.target_commitish }}
elif [ ${{ github.event_name == 'create' }} == true ]; then
BRANCH=${{ github.event.repository.default_branch }}
elif [ ${{ github.event_name == 'pull_request' }} == true ]; then
BRANCH=${{ github.head_ref }}
else
BRANCH=${{ github.ref }}
fi
echo "job_ref=$BRANCH" >> $GITHUB_ENV
echo "Branch: $BRANCH"
- name: Get branches
id: branches
# https://github.com/actions/github-script
uses: actions/github-script@v6
with:
result-encoding: string
# https://octokit.github.io/rest.js
# https://docs.github.com/en/rest/branches/branches#list-branches
script: |
return github
.rest.repos.listBranches(context.repo)
.then((res) => res.data.map((b) => b.name));
- name: Get labels
id: labels
uses: actions/github-script@v6
with:
result-encoding: string
# https://octokit.github.io/rest.js
# https://docs.github.com/en/rest/issues/labels#list-labels-for-a-repository
script: |
return github
.rest.issues.listLabelsForRepo(context.repo)
.then((res) => res.data.map((l) => l.name));
- name: Generate a long array
id: long
uses: actions/github-script@v6
with:
result-encoding: string
script: |
return new Array(500).fill(0).map((_, i) => `#${i + 1}`);
- name: Generate another long array
id: long2
uses: actions/github-script@v6
with:
result-encoding: string
script: |
return new Array(500).fill(0).map((_, i) => `#${i + 1}`).reverse();
- name: Get next week
id: dates
uses: actions/github-script@v6
with:
# unfortunately I didn't manage to import moment
# https://github.com/actions/github-script/issues/275
script: |
const dayMs = 24 * 60 * 60 * 1000;
function format(dayDiff) {
const date = new Date(Date.now() + dayDiff * dayMs);
return `${date.getFullYear()}-${date.getMonth() + 1}-${
date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
}`;
}
return new Array(7).fill(0).map((_, i) => format(i + 7));
- name: Get dates until end of year
id: year_end
uses: actions/github-script@v6
with:
script: |
const dayMs = 24 * 60 * 60 * 1000;
function format(dayDiff) {
const date = new Date(Date.now() + dayDiff * dayMs);
return `${date.getFullYear()}-${date.getMonth() + 1}-${
date.getDate() < 10 ? `0${date.getDate()}` : date.getDate()
}`;
}
const jan1 = new Date(new Date().getFullYear() + 1, 0, 1)
return new Array(Math.floor((jan1 - new Date()) / dayMs)).fill(0).map((_, i) => format(i + 1));
- name: Timestamp
id: timestamp
run: echo "::set-output name=value::$(date +'%Y-%m-%d %H:%M:%S') "
update-bug-report:
name: Update bug report on branch `${{ needs.pre.outputs.branch }}`
runs-on: ubuntu-latest
needs: pre
if: contains(github.actor, 'github-actions') == false
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.pre.outputs.branch }}
- name: Update branches
id: branches
uses: ./
with:
form: .github/ISSUE_TEMPLATE/bug_report.yml
dropdown: _branches
options: ${{ needs.pre.outputs.branches }}
dry_run: no-push
- name: Bug report modified? ${{ steps.branches.outputs.modified }}
run: |
- name: Update labels
id: labels
uses: ./
with:
form: .github/ISSUE_TEMPLATE/bug_report.yml
dropdown: _labels
options: ${{ needs.pre.outputs.labels }}
dry_run: no-push
- name: Bug report modified? ${{ steps.labels.outputs.modified }}
run: |
- name: Update dates
id: dates
uses: ./
with:
form: .github/ISSUE_TEMPLATE/bug_report.yml
dropdown: _dates
options: ${{ needs.pre.outputs.dates }}
dry_run: no-push
- name: Pushed? ${{ steps.branches.outputs.modified || steps.labels.outputs.modified || steps.dates.outputs.modified }}
if: steps.branches.outputs.modified || steps.labels.outputs.modified || steps.dates.outputs.modified
run: git push
update-long-report:
name: Update long report on branch `${{ needs.pre.outputs.branch }}`
runs-on: ubuntu-latest
needs: pre
if: contains(github.actor, 'github-actions') == false
steps:
- uses: actions/checkout@v3
with:
ref: ${{ needs.pre.outputs.branch }}
- name: Update long dropdown
uses: ./
with:
template: .github/template_report.yml
form: .github/ISSUE_TEMPLATE/long_report.yml
dropdown: long
options: ${{ needs.pre.outputs.long }}
commit_message: 'chore(): update long report / long dropdown'
- name: Update long2 dropdown
uses: ./
with:
# passing template again for testing
template: .github/template_report.yml
form: .github/ISSUE_TEMPLATE/long_report.yml
dropdown: long2
options: ${{ needs.pre.outputs.long2 }}
commit_message: 'chore(): update long report / long2 dropdown'
- name: Update year end dropdown
uses: ./
with:
# passing template again for testing
template: .github/template_report.yml
form: .github/ISSUE_TEMPLATE/long_report.yml
dropdown: year_end
options: ${{ needs.pre.outputs.year_end }}
commit_message: 'chore(): update long report / year_end dropdown'
dry_run: no-push
- name: Dynamic Substitution
uses: ./
with:
# passing template again for testing
template: .github/template_report.yml
form: .github/ISSUE_TEMPLATE/long_report.yml
dropdown: _subs
options: '{{...}},${{ needs.pre.outputs.timestamp }}'
description: '{...}\nUpdated ${{ needs.pre.outputs.timestamp }}'
dry_run: no-push
- name: Commit & PR
uses: peter-evans/[email protected]
with:
commit-message: 'chore(): update long report / year_end dropdown'
add-paths: .github/ISSUE_TEMPLATE/long_report.yml
branch: ci-update-long-report
base: ${{ needs.pre.outputs.branch }}
delete-branch: true
labels: ci, bot
title: 'ci(`Automated`): Update year end dropdown'
body: |
Automated update to `.github/ISSUE_TEMPLATE/long_report.yml`
Last sha ${{ github.sha }}
Created with
[![create-pull-request](https://img.shields.io/github/v/release/peter-evans/create-pull-request?label=peter-evans%2Fcreate-pull-request&sort=semver)](https://github.com/marketplace/actions/create-pull-request)