-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
455 lines (405 loc) · 20 KB
/
action.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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
name: 'Srg auto collect changelog'
description: 'Auto collect changelog'
inputs:
enforce_jira_policy:
description: 'Enforce Jira policy'
required: fasle
default: 'true'
enforce_commit_policy:
description: 'Enforce commit policy'
required: fasle
default: 'true'
jira_domain:
description: 'The company Jira domain'
required: true
default: 'srgxxxx.atlassian.net'
gh_token:
description: 'A Github token with read permission for repos'
required: true
pattern_commit_convention:
required: false
default: "feat|fix|ci|chore|docs|new_api|break_api|deprecate_api"
description: 'The commit message convention pattern'
pattern_jira_tickets:
required: false
default: "([a-z]+[0-9]*-[0-9]+)"
ignored_jira_tickets:
required: false
default: "^(patch|feature|bugfix)-[0-9]+"
# default: "([a-z]{2,}-)([0-9]+)"
description: 'Regex for extract jira ticket'
google_sheet_token:
required: true
description: 'Google sheet token'
google_sheet_id:
required: true
description: 'Google sheet id'
google_sheet_client_email:
required: true
description: 'Google sheet client email'
google_sheet_work_sheet_title:
required: true
default: "changelog_from_pr"
description: 'Google sheet work sheet tittle'
google_sheet_closed_pr_sheet_title:
required: false
default: "log_from_closed_pr"
description: 'Google sheet work sheet tittle'
outputs:
jira_ticket_list:
description: "The jira tickets list form pull request and commit message"
value: ${{ steps.export_outputs_step.outputs.jira_ticket_list }}
srg_changelog_file:
description: "The file that contains changelog of current pull request"
value: ${{ steps.export_outputs_step.outputs.srg_changelog_file }}
runs:
using: "composite"
steps:
- run: echo Hello ${{ inputs.jira_domain }}.
shell: bash
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
# - run: echo "${{ toJSON(github) }}"
# shell: bash
- run: pwd
shell: bash
- run: |
echo name: "AAA -> Figure out env --> 0: Pr event type"
echo ""
echo "github event action: ${{github.event.action}}"
if [[ "${{ github.event_name }}" == 'pull_request' && "${{github.event.pull_request.merged}}" == 'true' && "${{github.event.action}}" == 'closed' ]]; then
echo "----------------------------> PR merged and closed. <----------------------------"
elif [[ "${{ github.event_name }}" == 'pull_request' && "${{github.event.pull_request.merged}}" == 'false' && "${{github.event.action}}" == 'closed' ]]; then
echo "----------------------------> PR closed without merging, do nothing. <----------------------------"
else
echo "----------------------------> PR event action:${{github.event_name}} <----------------------------"
fi
shell: bash
- run: |
echo name: "AAA -> Figure out env --> 0: Test srcipt"
echo ""
goodbye.sh
shell: bash
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true }}
- run: |
echo "AAA -> Init env --> 1: Init file name into GITHUB_ENV"
echo ""
echo "SRG_PR_CONTENT_TXT=srg_temp_pr_and_branch_info.txt" >> $GITHUB_ENV
echo "SRG_TEMP_FILE=srg_temp.txt" >> $GITHUB_ENV
echo "SRG_TEMP_COMMITS_FILE=srg_temp_commits.txt" >> $GITHUB_ENV
echo "SRG_OUTPUT_TICKETS_FILE=srg_output_tickets.txt" >> $GITHUB_ENV
echo "SRG_OUTPUT_COMMITS_FILE=srg_output_commits.txt" >> $GITHUB_ENV
shell: bash
- run: |
echo "AAA -> init env --> 2: Get repo company name"
echo ""
repo_org_name=$(get_repo_company_name.sh "SrgGactionChangelogApp")
echo "repo_org_name --> $repo_org_name"
if [ -f "${{ env.SRG_OUTPUT_TICKETS_FILE }}" ]; then
rm -f "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
fi
if [ -f "${{ env.SRG_OUTPUT_COMMITS_FILE }}" ]; then
rm -f "${{ env.SRG_OUTPUT_COMMITS_FILE }}"
fi
shell: bash
- run: |
echo "CCC -> Get commits --> 0: save commit message to text"
echo ""
PR_NUMBER="${{ github.event.pull_request.number }}"
REPO_NAME="${{ github.repository }}"
API_URL="https://api.github.com/repos/$REPO_NAME/pulls/$PR_NUMBER/commits"
echo "PR_NUMBER: $PR_NUMBER --> REPO_NAME: $REPO_NAME"
curl -s -H "Authorization: token ${{ inputs.gh_token }}" -H "Accept: application/vnd.github+json" $API_URL > "${{ env.SRG_TEMP_FILE}}"
jq_installed=$(command -v jq)
echo "jq_installed: $jq_installed"
if [ -z "$jq_installed" ]; then
echo "jq is not installed on the machine, exit..."
exit 1
else
echo "jq has installed on the machine"
fi
echo "---------------------------------------------"
#
cat "./${{ env.SRG_TEMP_FILE}}" | jq -r '.[] | "\(.commit.message)"' > "./${{ env.SRG_TEMP_COMMITS_FILE }}"
echo "" >> "./${{ env.SRG_TEMP_COMMITS_FILE }}"
cat "./${{ env.SRG_TEMP_COMMITS_FILE }}"
if: ${{ github.event_name == 'pull_request' }}
shell: bash
- if: ${{ github.event_name == 'pull_request' }}
uses: DamianReeves/write-file-action@master
with:
path: "./${{ env.SRG_PR_CONTENT_TXT }}"
contents: |
${{ github.head_ref }}
${{ github.event.pull_request.title }}
${{ github.event.pull_request.body }}
write-mode: overwrite
- if: ${{ github.event_name == 'pull_request' }}
run: |
echo "WWW -> Print original content"
# add a end line for SRG_PR_CONTENT_TXT
echo "" >> "${{ env.SRG_PR_CONTENT_TXT }}"
echo ""
echo "------------------ cat ${{ env.SRG_TEMP_COMMITS_FILE }} --------------------"
cat "${{ env.SRG_TEMP_COMMITS_FILE }}"
echo "----------------------------------------------------------------------------"
echo ""
echo "------------------ cat ${{ env.SRG_PR_CONTENT_TXT }} --------------------"
cat "${{ env.SRG_PR_CONTENT_TXT }}"
echo "----------------------------------------------------------------------------"
echo "jira_ticket_list=${mock_artifact_download_link}" >> $GITHUB_OUTPUT
echo "srg_changelog_file=${mock_artifact_download_link}" >> $GITHUB_OUTPUT
shell: bash
- run: |
echo "WWW -> Extract Jira tickets"
temp_merge="temp_merge.txt"
if [ -f "${{ env.SRG_OUTPUT_TICKETS_FILE }}" ]; then
rm -f "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
fi
touch "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
cat "${{ env.SRG_PR_CONTENT_TXT }}" "${{ env.SRG_TEMP_COMMITS_FILE }}" > "${temp_merge}"
echo " ---> : ${temp_merge}"
cat "${temp_merge}"
if cat "${temp_merge}" | tr '[:upper:]' '[:lower:]' | grep -Eo "${{ inputs.pattern_jira_tickets }}" | grep -v -E "${{ inputs.ignored_jira_tickets }}" | sort -u | sort -n >/dev/null 2>&1; then
echo "Extract Jira tickets succeed"
cat "${temp_merge}" | tr '[:upper:]' '[:lower:]' | grep -Eo "${{ inputs.pattern_jira_tickets }}" | grep -v -E "${{ inputs.ignored_jira_tickets }}" | sort -u | sort -n > "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
else
# echo "" > "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
echo "Extract Jira tickets failed"
fi
echo "cat: ${{ env.SRG_OUTPUT_TICKETS_FILE }}"
cat "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
shell: bash
if: ${{ github.event_name == 'pull_request' }}
- name: 'TTT -> Enforce Jira policy'
run: |
echo "TTT -> Enforce Jira policy."
if [ -s "./${{ env.SRG_OUTPUT_TICKETS_FILE }}" ]; then
echo "Jira ticket list is not empty."
cat "./${{ env.SRG_OUTPUT_TICKETS_FILE }}"
else
echo "## ❌ Please make sure your pull request contains at least one Jira ticket id in any those places:" >>$GITHUB_STEP_SUMMARY
echo "- commit message" >>$GITHUB_STEP_SUMMARY
echo "- pull request title, or pull reuqest body" >>$GITHUB_STEP_SUMMARY
echo "- branch name." >>$GITHUB_STEP_SUMMARY
echo "## ❌ 请确保当前 pull request 关联(至少)一个 Jira ticket id, 以下任何地方都可以:" >>$GITHUB_STEP_SUMMARY
echo "- 提交信息 (commit message)" >>$GITHUB_STEP_SUMMARY
echo "- pull request 标题栏, 或者 pull reuqest 内题栏" >>$GITHUB_STEP_SUMMARY
echo "- 分支名称,(branch name)" >>$GITHUB_STEP_SUMMARY
echo "::error::❌ Please make sure your pull request or commit messages contains at least one Jira ticket id"
echo "::error::❌ 请确保当前 pull request 或者 commit message 关联(至少)一个 Jira ticket id"
exit 1
fi
cat "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
shell: bash
if: ${{ inputs.enforce_jira_policy == 'true' }}
- name: 'TTT -> Reminder Jira policy'
run: |
echo "TTT -> Enforce Jira policy."
if [ -s "./${{ env.SRG_OUTPUT_TICKETS_FILE }}" ]; then
echo "Jira ticket list is not empty."
cat "./${{ env.SRG_OUTPUT_TICKETS_FILE }}"
else
echo "## ⚠️ Warning, please make sure your pull request contains at least one Jira ticket id in any those places:" >>$GITHUB_STEP_SUMMARY
echo "- commit message" >>$GITHUB_STEP_SUMMARY
echo "- pull request title, or pull reuqest body" >>$GITHUB_STEP_SUMMARY
echo "- branch name." >>$GITHUB_STEP_SUMMARY
echo "## ⚠️ 警告,请确保当前 pull request 关联(至少)一个 Jira ticket id, 以下任何地方都可以:" >>$GITHUB_STEP_SUMMARY
echo "- 提交信息 (commit message)" >>$GITHUB_STEP_SUMMARY
echo "- pull request 标题栏, 或者 pull reuqest 内题栏" >>$GITHUB_STEP_SUMMARY
echo "- 分支名称,(branch name)" >>$GITHUB_STEP_SUMMARY
echo "::warning::⚠️ Please make sure your pull request or commit messages contains at least one Jira ticket id"
echo "::warning::⚠️ 请确保当前 pull request 或者 commit message 关联(至少)一个 Jira ticket id"
fi
cat "${{ env.SRG_OUTPUT_TICKETS_FILE }}"
shell: bash
if: ${{ inputs.enforce_jira_policy != 'true' }}
- run: |
echo "WWW -> Extract commit messages"
if cat "${{ env.SRG_PR_CONTENT_TXT }}" "${{ env.SRG_TEMP_COMMITS_FILE }}" | tr '[:upper:]' '[:lower:]'| grep -i -E "(${{ inputs.pattern_commit_convention }}):" >/dev/null 2>&1; then
echo "Extract commit messages succeed"
cat "${{ env.SRG_PR_CONTENT_TXT }}" "${{ env.SRG_TEMP_COMMITS_FILE }}" | tr '[:upper:]' '[:lower:]'| grep -i -E "(${{ inputs.pattern_commit_convention }}):" | sed -e 's/([^()]*)//g' | sed 's/;/,/g'| sort -u | sort -n > "${{ env.SRG_OUTPUT_COMMITS_FILE }}"
else
echo "Extract commit messages failed"
touch "${{ env.SRG_OUTPUT_COMMITS_FILE }}"
fi
shell: bash
if: ${{ github.event_name == 'pull_request' }}
- name: 'TTT -> Enforce commit policy'
run: |
echo "TTT -> Enforce commit policy"
if [ -s "./${{ env.SRG_OUTPUT_COMMITS_FILE }}" ]; then
echo "commits message list is not empty."
cat "./${{ env.SRG_OUTPUT_COMMITS_FILE }}"
else
echo "## ❌ Please make sure your pull request follows up the commit convention" >> $GITHUB_STEP_SUMMARY
echo "## ❌ 请遵守 git commit messge 规范" >> $GITHUB_STEP_SUMMARY
echo "[git commit convention](https://github.com/SweetRainGarden/SrgGactionChangelogApp/blob/develop/docs/git_commits_convention_en.md)" >> $GITHUB_STEP_SUMMARY
echo "[git commit messge 规范](https://github.com/SweetRainGarden/SrgGactionChangelogApp/blob/develop/docs/git_commits_convention_ch.md)" >> $GITHUB_STEP_SUMMARY
echo "::warning::❌ Please make sure your pull request follows up the commit convention"
echo "::warning::❌ 请遵守 git commit messge 规范"
exit 1
fi
cat "${{ env.SRG_OUTPUT_COMMITS_FILE }}"
shell: bash
if: ${{ inputs.enforce_commit_policy == 'true' }}
- name: 'TTT -> Reminder commit policy'
run: |
echo "TTT -> Reminder commit policy"
if [ -s "./${{ env.SRG_OUTPUT_COMMITS_FILE }}" ]; then
echo "commits message list is not empty."
cat "./${{ env.SRG_OUTPUT_COMMITS_FILE }}"
else
echo "## ⚠️ Please make sure your pull request follows up the commit convention" >> $GITHUB_STEP_SUMMARY
echo "## ⚠️ 请遵守 git commit messge 规范" >> $GITHUB_STEP_SUMMARY
echo "[git commit convention](https://github.com/SweetRainGarden/SrgGactionChangelogApp/blob/develop/docs/git_commits_convention_en.md)" >> $GITHUB_STEP_SUMMARY
echo "[git commit messge 规范](https://github.com/SweetRainGarden/SrgGactionChangelogApp/blob/develop/docs/git_commits_convention_ch.md)" >> $GITHUB_STEP_SUMMARY
echo "::error::⚠️ Please make sure your pull request follows up the commit convention"
echo "::error::⚠️ 请遵守 git commit messge 规范"
fi
cat "${{ env.SRG_OUTPUT_COMMITS_FILE }}"
shell: bash
if: ${{ inputs.enforce_commit_policy != 'true' }}
- run: |
echo "XXX -> Print --> 0: cat files"
echo ""
pwd="$(pwd)"
echo "-----------------------------------------------------"
echo "cat: ${pwd}/${{ env.SRG_OUTPUT_TICKETS_FILE }}"
cat "${pwd}/${{ env.SRG_OUTPUT_TICKETS_FILE }}"
echo "-----------------------------------------------------"
echo "cat: ${pwd}/${{ env.SRG_OUTPUT_COMMITS_FILE }}"
cat "${pwd}/${{ env.SRG_OUTPUT_COMMITS_FILE }}"
echo "-----------------------------------------------------"
shell: bash
if: ${{ github.event_name == 'pull_request' }}
- name: 'TTT -> Get action trigger time'
run: |
# Get the current date and time in Seattle time zone
seattle_time=$(TZ='America/Los_Angeles' date '+%m/%d/%Y %T')
echo "SRG_ACTION_TRIGGER_TIME_SEATTLE=${seattle_time}" >> $GITHUB_ENV
beijing_time=$(TZ='Asia/Shanghai' date '+%m/%d/%Y %T')
echo "SRG_ACTION_TRIGGER_TIME_BEIJING=${beijing_time}" >> $GITHUB_ENV
echo "Seattle time: $seattle_time"
echo "Beijing time: $beijing_time"
pwd=$(pwd)
ticket_list=$(txt_to_one_line_format_string.sh "${pwd}/${{ env.SRG_OUTPUT_TICKETS_FILE }}" ",")
echo "SRG_ACTION_TICKET_LIST=${ticket_list}" >> $GITHUB_ENV
commits_list=$(txt_to_one_line_format_string.sh "${pwd}/${{ env.SRG_OUTPUT_COMMITS_FILE }}" "\n")
echo "SRG_ACTION_COMMIT_LIST=${commits_list}" >> $GITHUB_ENV
echo "## ✅ Valid changelog: " >> $GITHUB_STEP_SUMMARY
echo "### jira tickets " >> $GITHUB_STEP_SUMMARY
cat "${pwd}/${{ env.SRG_OUTPUT_TICKETS_FILE }}" >> $GITHUB_STEP_SUMMARY
echo "### git commits: " >> $GITHUB_STEP_SUMMARY
cat "${pwd}/${{ env.SRG_OUTPUT_COMMITS_FILE }}" >> $GITHUB_STEP_SUMMARY
shell: bash
if: ${{ github.event_name == 'pull_request' }}
- if: ${{ github.event_name == 'pull_request' }}
id: export_outputs_step
run: |
echo "WWW -> Print export_outputs_step content"
echo "jira_ticket_list=${{ env.SRG_ACTION_TICKET_LIST }}" >> $GITHUB_OUTPUT
echo "srg_changelog_file=${{ env.SRG_ACTION_COMMIT_LIST }}" >> $GITHUB_OUTPUT
shell: bash
- name: "TTT -> Update Google Sheet --> 1: append merged pr data"
continue-on-error: true
id: append_data_google_sheet
if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' || github.event.pull_request.merged != false }}
uses: jroehl/gsheet.action@v2.1.1
with:
spreadsheetId: "${{inputs.google_sheet_id}}"
commands: | # list of commands, specified as a valid JSON string
[
{
"command": "appendData",
"args":
{
"worksheetTitle": "${{ inputs.google_sheet_work_sheet_title }}",
"data":
[
[
"${{ github.event.repository.name }}",
"=HYPERLINK(${{ env.DOUBLE_QUOTE }}${{ github.event.pull_request.html_url }}${{ env.DOUBLE_QUOTE }},${{ env.DOUBLE_QUOTE }}${{ github.event.number }}${{ env.DOUBLE_QUOTE }})",
"${{ github.base_ref }}",
"${{ github.head_ref }}",
"${{ github.event.pull_request.merged }}",
"${{ github.event.action }}",
"${{ github.actor }}",
"${{ env.SRG_ACTION_TRIGGER_TIME_SEATTLE }}",
"${{ env.SRG_ACTION_TRIGGER_TIME_BEIJING }}",
"${{ env.SRG_ACTION_TICKET_LIST }}",
"${{ env.SRG_ACTION_COMMIT_LIST }}"
]
],
"minCol": 1,
"valueInputOption":"USER_ENTERED"
}
}
]
env:
DOUBLE_QUOTE: '\"'
GSHEET_CLIENT_EMAIL: ${{ inputs.google_sheet_client_email }}
GSHEET_PRIVATE_KEY: ${{ inputs.google_sheet_token }}
- name: "TTT -> Update Google Sheet --> 2: append closed pr data"
continue-on-error: true
id: append_closed_pr_data_google_sheet
uses: jroehl/gsheet.action@v2.1.1
if: ${{ github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == false }}
with:
spreadsheetId: "${{inputs.google_sheet_id}}"
commands: | # list of commands, specified as a valid JSON string
[
{
"command": "appendData",
"args":
{
"worksheetTitle": "${{ inputs.google_sheet_closed_pr_sheet_title }}",
"data":
[
[
"${{ github.event.repository.name }}",
"=HYPERLINK(${{ env.DOUBLE_QUOTE }}${{ github.event.pull_request.html_url }}${{ env.DOUBLE_QUOTE }},${{ env.DOUBLE_QUOTE }}${{ github.event.number }}${{ env.DOUBLE_QUOTE }})",
"${{ github.base_ref }}",
"${{ github.head_ref }}",
"${{ github.event.pull_request.merged }}",
"${{ github.event.action }}",
"${{ github.actor }}",
"${{ env.SRG_ACTION_TRIGGER_TIME_SEATTLE }}",
"${{ env.SRG_ACTION_TRIGGER_TIME_BEIJING }}",
"${{ env.SRG_ACTION_TICKET_LIST }}",
"${{ env.SRG_ACTION_COMMIT_LIST }}"
]
],
"minCol": 1,
"valueInputOption":"USER_ENTERED"
}
}
]
env:
DOUBLE_QUOTE: '\"'
GSHEET_CLIENT_EMAIL: ${{ inputs.google_sheet_client_email }}
GSHEET_PRIVATE_KEY: ${{ inputs.google_sheet_token }}
- name: "TTT -> Update Google Sheet --> 2: echo success result"
env:
RESULTS: ${{ steps.append_data_google_sheet.outputs.results }}
run: |
echo "append_data_google_sheet step result:"
echo "$RESULTS"
shell: bash
if: steps.append_data_google_sheet.outcome == 'success'
- run: |
echo "ZZZ -> Clean up --> 0: txt files"
echo ""
echo "------------- pull_request closed and merged ------------"
if [ -f "${{ env.SRG_PR_CONTENT_TXT }}" ]; then
rm -f "${{ env.SRG_PR_CONTENT_TXT }}"
fi
if [ -f "${{ env.SRG_TEMP_FILE }}" ]; then
rm -f "${{ env.SRG_TEMP_FILE }}"
fi
if [ -f "${{ env.SRG_TEMP_COMMITS_FILE }}" ]; then
rm -f "${{ env.SRG_TEMP_COMMITS_FILE }}"
fi
shell: bash
continue-on-error: true
if: ${{ github.event_name == 'pull_request' }}