-
-
Notifications
You must be signed in to change notification settings - Fork 171
420 lines (384 loc) · 17.1 KB
/
comment_on_issues.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
name: Auto comment Issues
on:
issues:
types: [opened, reopened]
issue_comment:
types: [created, edited, deleted]
jobs:
build:
if: github.event_name == 'issues'
name: Build WSA and Check comment
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create Issues comment
id: comment
uses: actions-cool/issues-helper@v3
with:
actions: 'create-comment'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
We are checking your Issues body and head ...
> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
----
emoji: heart
- name: Setup Python
uses: actions/setup-python@v5
with:
check-latest: true
python-version: '3.10'
cache: 'pip'
cache-dependency-path: scripts/
- name: Update Package
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
sudo apt-get update
python3 -m pip install --upgrade setuptools
- name: Get Issues Info
id: get-issues
uses: actions/github-script@v7
with:
script: |
var fs = require('fs');
var issuenumber = ${{ toJSON(github.event.issue.number) }};
var issueauth = ${{ toJSON(github.event.issue.user.login) }};
var issuetitle = ${{ toJSON(github.event.issue.title) }};
var issuebody = ${{ toJSON(github.event.issue.body) }};
if (issuetitle != null) {
issuetitle = issuetitle.replace(/\u000A|\u000D/g, ""); //Replace newline letter
}
if (issuebody != null) {
issuebody = issuebody.replace(/\u0008|\u0009|\u000A|\u000B|\u000C|\u000D|\u00A0|\u2028|\u2029|\uFEFF/g, "");
issuebody = issuebody.replace(/—/g, "-");
}
core.setOutput("issuenumber", JSON.stringify(issuenumber));
core.setOutput("issueauth", JSON.stringify(issueauth));
core.setOutput("issuetitle", JSON.stringify(issuetitle));
core.setOutput("issuebody", JSON.stringify(issuebody));
- name: Set Issues Info
if: success()
run: |
echo "issuenumber="${{ steps.get-issues.outputs.issuenumber }}"" >> $GITHUB_ENV
echo "issueauth="${{ steps.get-issues.outputs.issueauth }}"" >> $GITHUB_ENV
echo "issuetitle="${{ steps.get-issues.outputs.issuetitle }}"" >> $GITHUB_ENV
echo "issuebody="${{ steps.get-issues.outputs.issuebody }}"" >> $GITHUB_ENV
- name: Get Build Info
shell: python
run: |
import os, re, json, shutil, string, subprocess
def set_output(name, value):
subprocess.call(["echo '{}={}' >> $GITHUB_ENV".format(name, value)], shell=True)
if __name__ == '__main__':
issues = 'false'
ismagisk = 'false'
iscustom = 'true'
errinfo = body = ''
try:
if '${{ env.issuetitle }}'.lower().startswith('custom wsa build'):
issues = 'true'
body = '${{ env.issuebody }}'
else:
iscustom = 'false'
if re.match(".*arch.*64.*release-type.*root-sol.*magisk-branch.*magisk-ver.*compress-format.*", body):
iscustom = 'true'
else:
iscustom = 'false'
errinfo = 'Argument is invaild, please update the body of the Issues'
if re.match(".*arch.*64.*release-type.*root-sol\smagisk.*magisk-branch.*magisk-ver.*compress-format.*", body):
ismagisk = 'true'
except Exception as e:
iscustom = 'false'
errinfo = 'Issues Body error, {}.'.format(e)
set_output('issues', issues)
set_output('iscustom', iscustom)
set_output('ismagisk', ismagisk)
set_output('errinfo', errinfo)
set_output('body', body)
- name: Add Issues labels
if: env.issues == 'true' && env.iscustom == 'true'
uses: actions-cool/issues-helper@v3
with:
actions: 'add-labels'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ env.issuenumber }}
labels: 'custom'
- name: Update Comment Begin
if: env.issues == 'true' && env.iscustom == 'true'
uses: actions-cool/issues-helper@v3
with:
actions: 'update-comment'
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ steps.comment.outputs.comment-id }}
update-mode: replace
body: |
Hello ${{ env.issueauth }} .
Your custom WSA build has started building. Please go to the URL below for more details.
> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
----
emoji: heart
- name: Update Comment Error
if: env.issues == 'true' && env.iscustom == 'false'
uses: actions-cool/issues-helper@v3
with:
actions: 'update-comment'
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ steps.comment.outputs.comment-id }}
update-mode: replace
body: |
Hello ${{ env.issueauth }}.
Look like we have a problem with the workflow. We will take a look soon.
`Error Info:`
`${{ env.errinfo }}`
> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
----
emoji: eyes
- name: Update Comment Invalid
if: env.issues == 'false'
uses: actions-cool/issues-helper@v3
with:
actions: 'update-comment'
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ steps.comment.outputs.comment-id }}
update-mode: replace
body: |
Hello ${{ env.issueauth }}.
Thanks for sending an issues. Now our admin is inactive, just waiting and he will reply you soon.
Hope you have a nice day.
> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
----
emoji: eyes
- name: Install Ubuntu Dependencies
if: env.iscustom == 'true' && success()
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: e2fsprogs attr unzip qemu-utils python3-venv
version: 1.0
- name: Setup Python3 Virtual Enviroment
if: env.iscustom == 'true' && success()
working-directory: scripts
run: |
PYTHON_VENV_DIR="$(dirname "$PWD")/python3-env"
python3 -m venv "$PYTHON_VENV_DIR" || abort "Failed to create python3 virtual env"
# shellcheck disable=SC1091
source "$PYTHON_VENV_DIR/bin/activate" || abort "Failed to activate python3 virtual env"
python3 -c "import pkg_resources; pkg_resources.require(open('requirements.txt',mode='r'))" &>/dev/null || {
echo "Installing Python3 dependencies"
python3 -m pip install --upgrade -r requirements.txt || abort "Failed to install python3 dependencies"
}
deactivate
- name: Build WSA
id: wsa
if: env.iscustom == 'true' && success()
run: |
mkdir -p download
if [[ ${{ env.ismagisk }} == 'true' ]]; then
./scripts/build_with_lspinit.sh ${{ env.body }}
else
./scripts/build_with_mount.sh ${{ env.body }}
fi
- name: Pass to Windows
if: env.iscustom == 'true' && success()
uses: actions/cache/save@v4
with:
path: output
key: ${{ steps.wsa.outputs.artifact }}-${{ steps.wsa.outputs.built }}
enableCrossOsArchive: true
outputs:
artifact: ${{ steps.wsa.outputs.artifact }}
file_ext: ${{ steps.wsa.outputs.file_ext }}
arch: ${{ steps.wsa.outputs.arch }}
built: ${{ steps.wsa.outputs.built }}
comment-id: ${{ steps.comment.outputs.comment-id }}
iscustom: ${{ env.iscustom }}
make-pri:
if: needs.build.outputs.iscustom == 'true'
name: Merge PRI resources and Complete issue
runs-on: windows-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download built artifact
uses: actions/cache/restore@v4
with:
path: output
key: ${{ needs.build.outputs.artifact }}-${{ needs.build.outputs.built }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- name: Merge language and density resources
if: success()
run: |
if ("${{ needs.build.outputs.arch }}" -eq "x64") {
(Start-Process pwsh.exe -NoNewWindow -PassThru -Args "-ExecutionPolicy Bypass -File MakePri.ps1" -WorkingDirectory "${{ github.workspace }}\output\${{ needs.build.outputs.artifact }}").WaitForExit()
} else {
Copy-Item -Force "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\arm64\makepri.exe" "${{ github.workspace }}\output\${{ needs.build.outputs.artifact }}"
}
- name: Compact Images 💿
if: success()
run: |
foreach ($Partition in 'system','product','system_ext','vendor') {
Write-Output "Optimizing of $Partition..."
Write-Output "SELECT VDISK FILE=`"${{ github.workspace }}\output\${{ needs.build.outputs.artifact }}\$Partition.vhdx`"`
ATTACH VDISK READONLY`
COMPACT VDISK`
DETACH VDISK" | Set-Content -Path "$Partition.txt" -Encoding Ascii
Start-Process -NoNewWindow -Wait "diskpart.exe" -Args "/s $Partition.txt" -RedirectStandardOutput NUL
}
- name: Compress 7-Zip and Add checksum
if: success() && needs.build.outputs.file_ext == '7z'
working-directory: output
run: |
7z a -t7z -mx=6 -m0=LZMA2 -ms=on -mmt=8 -sdel -- "${{ needs.build.outputs.artifact }}.7z" "${{ needs.build.outputs.artifact }}\*"
($(Get-FileHash -Path "${{ needs.build.outputs.artifact }}.7z" -Algorithm SHA256).Hash.ToLower().ToString() + " " + "${{ needs.build.outputs.artifact }}.7z") | Out-File -FilePath sha256-checksum.txt -Encoding UTF8
- name: Upload to Artifacts
if: success()
uses: actions/upload-artifact@v4
with:
name: ${{ needs.build.outputs.artifact }}-built
path: output
retention-days: 5
- name: Update Comment Finish
if: success()
uses: actions-cool/issues-helper@v3
with:
actions: 'update-comment'
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ needs.build.outputs.comment-id }}
update-mode: replace
body: |
Hello ${{ env.issueauth }}.
Your custom WSA build has been built. Please go to the URL below to download it.
> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
----
PS:
When you downloaded your build, please comment "delete builds" to delete the build and log.
Thank you and hope you have a nice day !
>
----
emoji: hooray
- name: Close Issues
if: success()
uses: actions-cool/issues-helper@v3
with:
actions: 'close-issue'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ env.issuenumber }}
- name: Update Comment Fail
if: failure()
uses: actions-cool/issues-helper@v3
with:
actions: 'update-comment'
token: ${{ secrets.GITHUB_TOKEN }}
comment-id: ${{ needs.build.outputs.comment-id }}
update-mode: replace
body: |
Hello ${{ env.issueauth }}.
Your custom WSA build failed to build. Don't worry! Our admin will take a look soon.
> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
----
emoji: confused
delete_builds:
name: Delete build action
runs-on: ubuntu-latest
if: github.event_name == 'issue_comment' && contains('delete builds', github.event.comment.body)
steps:
- name: Find bots comments
id: find-bots
uses: actions-cool/issues-helper@v3
with:
actions: 'find-comments'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
comment-auth: 'github-actions[bot]'
- name: Find runs comments
id: find-runs
uses: actions-cool/issues-helper@v3
with:
actions: 'find-comments'
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
comment-auth: 'github-actions[bot]'
body-includes: '${{ github.server_url }}/${{ github.repository }}/actions/runs'
- name: Delete build Data
id: delete-build
uses: actions/github-script@v7
with:
script: |
async function main() {
var botscomments = ${{ steps.find-bots.outputs.comments }};
console.log("botscomments: " + botscomments);
var runscomments = ${{ steps.find-runs.outputs.comments }};
console.log("runscomments: " + runscomments);
var botids = [];
for (i = 0; i < botscomments.length; i++) {
botids.push(botscomments.at(i)["id"]);
}
console.log("botids: " + botids);
var runids = [];
for (i = 0; i < runscomments.length; i++) {
bodylines = runscomments.at(i)["body"].split("\n")
for (j = 0; j < bodylines.length; j++) {
if (bodylines.at(j).indexOf("runs/") != -1) {
let runid = bodylines.at(j).substring(bodylines.at(j).lastIndexOf('/') + 1).replace(/^\s+|\s+$/g, '');
runids.push({"id": runscomments.at(i)["id"], "runid": runid});
}
}
}
console.log("runids: " + runids);
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
if (runids.length > 0) {
var deleted = [];
for (index = 0; index < runids.length; index++) {
try {
if (false == deleted.includes(runids.at(index)["runid"])) {
const dellogs = await github.rest.actions.deleteWorkflowRunLogs({
owner,
repo,
run_id: runids.at(index)["runid"],
});
console.log("DELETE logs: %s", dellogs);
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runids.at(index)["runid"],
per_page: 100,
});
console.log("artifacts: %s", artifacts.data);
for (const artifact of artifacts.data.artifacts) {
console.log(`artifact id ${artifact.id} of ${artifact.name}`)
const delartifacts = await github.rest.actions.deleteArtifact({
owner,
repo,
artifact_id: artifact.id,
});
console.log(`DELETE artifacts(${artifact.id}): ${delartifacts}`)
}
deleted.push(runids.at(index)["runid"]);
}
} catch (error) {
core.setFailed(error.message);
}
}
}
if (botids.length > 0) {
for (index = 0; index < botids.length; index++) {
try {
const retcomments = await github.rest.issues.updateComment({
owner,
repo,
comment_id: botids.at(index),
body: '`deleted`'
})
console.log("PATCH emoji: %s", retcomments);
} catch (error) {
core.setFailed(error.message);
}
}
}
}
main();
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}