-
Notifications
You must be signed in to change notification settings - Fork 294
162 lines (143 loc) · 5.53 KB
/
process_har.yaml
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
name: HAR_Process
on:
workflow_dispatch: {}
issues:
types: [edited, labeled]
env:
TZ: Asia/Shanghai
REPO_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
jobs:
extract-issue-body:
runs-on: ubuntu-latest
# Only run if the issue is not a PR and is labeled by har
if: github.event.issue.pull_request == null && contains(github.event.issue.labels.*.name, 'har')
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/process_har.yaml
- name: Echo issue body
run: |
cat ${HOME}/issue-parser-result.json
- name: Obtain HARNAME
env:
ISSUE_JSON: ${{ steps.issue-parser.outputs.jsonString }}
id: harname
run: |
harname=$(python3 -c """
import json
import os
issue_json:dict = json.loads(os.getenv('ISSUE_JSON','{}'))
if len(issue_json) > 0 and 'name' in issue_json:
print(issue_json['name'])
else:
print('')
""")
echo "harname=${harname}" >> $GITHUB_OUTPUT
- name: Judge HAR is update
env:
ISSUE_JSON: ${{ steps.issue-parser.outputs.jsonString }}
id: isupdate
run: |
isupdate=$(python3 -c """
import json
import os
with open('tpls_history.json', 'r', encoding='utf8') as f:
hfile = json.loads(f.read())
issue_json:dict = json.loads(os.getenv('ISSUE_JSON','{}'))
if len(issue_json) > 0 and 'name' in issue_json:
if (issue_json['name'] in hfile['har']):
print('Update')
else:
print('Add')
else:
print('Add')
""")
echo "isupdate=${isupdate}" >> $GITHUB_OUTPUT
- name: Extract issue to json
env:
ISSUE_JSON: ${{ steps.issue-parser.outputs.jsonString }}
ISSUE_URL: ${{ github.event.issue.html_url }}
REPO_FULL_NAME: ${{ github.repository }}
run: |
python .github/src/extract_issue_body.py
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "${{ steps.isupdate.outputs.isupdate }} HAR: ${{ steps.harname.outputs.harname }}"
title: "${{ steps.isupdate.outputs.isupdate }} HAR: ${{ steps.harname.outputs.harname }}"
body: "Auto create pull request by HAR_Process action.\n\nIssue: ${{ github.event.issue.html_url }}\n\nAuthor: @${{ github.event.issue.user.login }}"
branch: process-har-${{ github.event.issue.number }}
delete-branch: true
base: ${{ env.REPO_DEFAULT_BRANCH }}
delete-invalid-har:
runs-on: ubuntu-latest
# Only run if the issue is not a PR and is labeled by har
if: github.event.issue.pull_request == null && contains(github.event.issue.labels.*.name, 'invalid')
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/process_har.yaml
- name: Echo issue body
run: |
cat ${HOME}/issue-parser-result.json
- name: Obtain HARNAME
env:
ISSUE_JSON: ${{ steps.issue-parser.outputs.jsonString }}
id: harname
run: |
harname=$(python3 -c """
import json
import os
issue_json:dict = json.loads(os.getenv('ISSUE_JSON','{}'))
if len(issue_json) > 0 and 'name' in issue_json:
print(issue_json['name'])
else:
print('')
""")
echo "harname=${harname}" >> $GITHUB_OUTPUT
- name: Delete HAR by harname
env:
ISSUE_JSON: ${{ steps.issue-parser.outputs.jsonString }}
run: |
existed=$(python3 .github/src/delete_har.py)
if [ "${existed}" == "True" ]; then
echo "Delete HAR: ${{ steps.harname.outputs.harname }}"
else
echo "HAR: ${{ steps.harname.outputs.harname }} not existed"
fi
- name: Creat Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Delete HAR: ${{ steps.harname.outputs.harname }}"
title: "Delete HAR: ${{ steps.harname.outputs.harname }}"
body: "Auto create pull request by HAR_Process action.\n\nIssue: ${{ github.event.issue.html_url }}\n\nAuthor: @${{ github.event.issue.user.login }}"
branch: process-har-${{ github.event.issue.number }}
delete-branch: true
base: ${{ env.REPO_DEFAULT_BRANCH }}
- name: Close issue
uses: peter-evans/close-issue@v3
with:
issue-number: ${{ github.event.issue.number }}
comment: "HAR: ${{ steps.harname.outputs.harname }} is invalid, close it."