-
Notifications
You must be signed in to change notification settings - Fork 1
415 lines (369 loc) · 15.7 KB
/
playground.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
name: Playground
on:
workflow_dispatch:
inputs:
os:
type: choice
description: OS version
options:
- ubuntu-latest
- ubuntu-22.04
- ubuntu-20.04
- windows-latest
- windows-2022
- windows-2019
- macos-latest
- macos-13
- macos-12
- macos-11
service:
type: choice
description: Tunneling service
options:
- pinggy.io and localhost.run
- pinggy.io
- zrok.io
- ZeroTier
- localhost.run
shell:
type: choice
description: Shell
options:
- bash
- cmd
- powershell
- pwsh
jobs:
action:
runs-on: ${{ github.event.inputs.os }}
steps:
- name: Get Wiki
uses: actions/checkout@v3
with:
repository: ${{github.repository}}.wiki
path: wiki
- name: Set Wiki initial message
shell: bash
env:
RUNNER_TEMP: ${{ runner.temp }}
run: |
mv wiki $RUNNER_TEMP/
git config --global credential.helper ""
git config --global --replace-all credential.helper store
echo "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com" >> ~/.git-credentials
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
cd $RUNNER_TEMP/wiki
echo Initializing... > ${{ github.run_id }}.md
echo >> ${{ github.run_id }}.md
echo Wait a moment and refresh this page to see the updates. >> ${{ github.run_id }}.md
git add ${{ github.run_id }}.md
git commit -m "Add ${{ github.run_id }} run page"
git push origin
# Check shell
- name: Check shell
shell: bash
if: github.event.inputs.shell != 'bash' && !startsWith(github.event.inputs.os, 'windows')
run: |
echo Shell can be changed only on Windows
exit 1
# Connect with ZeroTier
- uses: zerotier/[email protected]
if: github.event.inputs.service == 'ZeroTier'
with:
network_id: ${{ secrets.NETWORK_ID }}
auth_token: ${{ secrets.ACCESS_TOKEN }}
- uses: kildom/[email protected]
if: github.event.inputs.service == 'ZeroTier'
id: zerotier
with:
auth_token: ${{ secrets.ACCESS_TOKEN }}
ip: '${{ secrets.IP }} ${{ vars.IP }}'
name: 'Actions Playground'
# Copy Github action contexts
- name: Copy Github action contexts
shell: bash
env:
RUNNER_TEMP: ${{ runner.temp }}
run: |
cat << 'EnDOfThIssTrIng' > $RUNNER_TEMP/contexts.json
{
"github": ${{ toJSON(github) }},
"env": ${{ toJSON(env) }},
"vars": ${{ toJSON(vars) }},
"job": ${{ toJSON(job) }},
"steps": ${{ toJSON(steps) }},
"runner": ${{ toJSON(runner) }},
"secrets": ${{ toJSON(secrets) }},
"needs": ${{ toJSON(needs) }},
"inputs": ${{ toJSON(inputs) }}
}
EnDOfThIssTrIng
# Checkout repo and keys and move to runner.temp
- name: Get main branch
uses: actions/checkout@v3
with:
path: repo
- name: Get keys branch
uses: actions/checkout@v3
with:
ref: keys
path: keys
- name: Keep cache keys
shell: bash
run: |
echo PIP_KEY=${{ github.event.inputs.os }}-${{ hashFiles('repo/scripts/requirements.txt') }}-`date +%Y%m` >> $GITHUB_ENV
pip3 cache dir > t || pip cache dir > t
echo PIP_CACHE_DIR=`cat t` >> $GITHUB_ENV
rm t
- name: Move repo and keys
shell: bash
env:
RUNNER_TEMP: ${{ runner.temp }}
run: |
mv repo $RUNNER_TEMP/
mv keys $RUNNER_TEMP/repo/
# Change password
- name: Password (ubuntu)
if: startsWith(github.event.inputs.os, 'ubuntu')
run: |
echo -e "${{ secrets.PASSWORD }}\n${{ secrets.PASSWORD }}" | sudo passwd `whoami`
- name: Password (macos) and VNC
if: startsWith(github.event.inputs.os, 'macos')
run: |
sysadminctl -adminUser runner \
-adminPassword `sudo python3 ${{ runner.temp }}/repo/scripts/getpwd.py` \
-resetPasswordFor runner -newPassword ${{ secrets.PASSWORD }}
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart \
-activate -configure -access -on -clientopts -setvnclegacy -vnclegacy yes \
-clientopts -setvncpw -vncpw ${{ secrets.PASSWORD }} -restart -agent -privs -all
- name: Password (windows)
shell: cmd
if: startsWith(github.event.inputs.os, 'windows')
run: |
net user runneradmin "${{ secrets.PASSWORD }}"
# Cache
- uses: actions/cache@v3
with:
path: ${{ env.PIP_CACHE_DIR }}
key: ${{ env.PIP_KEY }}
# Install Windows SSH
- name: Install SSH (windows)
if: startsWith(github.event.inputs.os, 'windows')
working-directory: ${{ runner.temp }}/repo
shell: cmd
run: |
curl -L -o sshd.msi https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.1.0.0p1-Beta/OpenSSH-Win64-v9.1.0.0.msi
msiexec /quiet /qn /i sshd.msi
net stop sshd
- name: Set cmd as default shell (windows)
shell: powershell
if: github.event.inputs.shell == 'cmd'
run: |
echo "TTYD_SHELL=C:\Windows\System32\cmd.exe" >> $ENV:GITHUB_ENV
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\cmd.exe" -PropertyType String -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value "/c" -PropertyType String -Force
- name: Set powershell as default shell (windows)
shell: powershell
if: github.event.inputs.shell == 'powershell'
run: |
echo "TTYD_SHELL=C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" >> $ENV:GITHUB_ENV
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value "/c" -PropertyType String -Force
- name: Set pwsh as default shell (windows)
shell: powershell
if: github.event.inputs.shell == 'pwsh'
run: |
echo "TTYD_SHELL=C:\Program Files\PowerShell\7\pwsh.exe" >> $ENV:GITHUB_ENV
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value "/c" -PropertyType String -Force
- name: Set bash as default shell (windows)
shell: powershell
if: github.event.inputs.shell == 'bash' && startsWith(github.event.inputs.os, 'windows')
run: |
echo "TTYD_SHELL=C:\Program Files\Git\usr\bin\bash.exe" >> $ENV:GITHUB_ENV
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\usr\bin\bash.exe" -PropertyType String -Force
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShellCommandOption -Value "-c" -PropertyType String -Force
# Python requirements
- name: Python requirements (non-windows)
if: (!startsWith(github.event.inputs.os, 'windows'))
working-directory: ${{ runner.temp }}/repo
run: |
sudo pip3 install -r scripts/requirements.txt
- name: Python requirements (windows)
shell: cmd
if: startsWith(github.event.inputs.os, 'windows')
working-directory: ${{ runner.temp }}/repo
run: |
pip install -r scripts/requirements.txt
# Download ttyd
- name: Download ttyd (windows)
shell: cmd
if: startsWith(github.event.inputs.os, 'windows')
working-directory: ${{ runner.temp }}
run: |
curl -L https://github.com/tsl0922/ttyd/releases/latest/download/ttyd.win32.exe --output ttyd.exe
net stop /y W3SVC
netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80
- name: Download ttyd (ubuntu)
if: startsWith(github.event.inputs.os, 'ubuntu')
working-directory: ${{ runner.temp }}
run: |
curl -L https://github.com/tsl0922/ttyd/releases/latest/download/ttyd.x86_64 --output ttyd
chmod 755 ttyd
echo TTYD_CMD=${{ runner.temp }}/ttyd >> $GITHUB_ENV
- name: Download ttyd (macos)
if: startsWith(github.event.inputs.os, 'macos')
working-directory: ${{ runner.temp }}
run: |
brew install ttyd
echo TTYD_CMD=ttyd >> $GITHUB_ENV
# Download File Browser
- name: Download And Setup File Browser
working-directory: ${{ runner.temp }}
shell: bash
run: |
mkdir -p _file_browser
cd _file_browser
curl -fsSL https://raw.githubusercontent.com/prasathmani/tinyfilemanager/8de16a4c8a195ebce998f55b3aa567fab5c4bedc/tinyfilemanager.php -o index.php
echo '<?php' > config.php
echo '$auth_users=array(' >> config.php
echo "'runner'=>" >> config.php
echo '${{ secrets.PASSWORD }}' | php -r 'echo("\x27".password_hash(trim(file_get_contents("php://stdin")), PASSWORD_DEFAULT)."\x27");' >> config.php
echo ",'runneradmin'=>" >> config.php
echo '${{ secrets.PASSWORD }}' | php -r 'echo("\x27".password_hash(trim(file_get_contents("php://stdin")), PASSWORD_DEFAULT)."\x27");' >> config.php
echo ');' >> config.php
echo '$root_path="/./";' >> config.php
echo '$CONFIG = '\''{"lang":"en","error_reporting":false,"show_hidden":true,"hide_Cols":false,"theme":"dark"}'\'';' >> config.php
echo '$readonly_users = array();' >> config.php
- name: Setup File Browser For Windows
shell: cmd
if: startsWith(github.event.inputs.os, 'windows')
working-directory: ${{ runner.temp }}
run: |
cd _file_browser
mkdir D:\DiskC
echo select volume C: > conf.txt
echo assign mount=D:\DiskC >> conf.txt
diskpart < conf.txt
# Collect env
- name: Collect env (cmd)
shell: cmd
if: startsWith(github.event.inputs.os, 'windows')
working-directory: ${{ runner.temp }}
run: |
python -c "import json; import os; print(json.dumps(dict(os.environ)))" > cmd_env.json
- name: Collect env
shell: bash
working-directory: ${{ runner.temp }}
run: |
env > bash_env.txt
# Do rest of the work in Python, it's easier there
- name: Your work starts here (non-windows)
if: (!startsWith(github.event.inputs.os, 'windows'))
working-directory: ${{ runner.temp }}/repo
env:
RUNNER_TEMP: ${{ runner.temp }}
run: |
php -S 127.0.0.1:8080 -t $RUNNER_TEMP/_file_browser 2> /dev/null > /dev/null &
env > bash_env.txt
bash scripts/redir_fifo.sh &
sudo --preserve-env=RUNNER_TEMP python3 scripts/main.py --as-root
sudo -u "`whoami`" ${{ env.TTYD_CMD }} -W -d 0 -p 80 -w '${{ github.workspace }}' -c 'runner:${{ secrets.PASSWORD }}' bash &
python3 scripts/main.py
- name: Your work starts here (windows non-bash)
shell: cmd
if: github.event.inputs.shell != 'bash' && startsWith(github.event.inputs.os, 'windows')
working-directory: ${{ runner.temp }}/repo
env:
RUNNER_TEMP: ${{ runner.temp }}
run: |
start /b "" php -S 127.0.0.1:8080 -t %RUNNER_TEMP%\_file_browser
python -c "import json; import os; print(json.dumps(dict(os.environ)))" > cmd_env.json
start /b "" node scripts\redir_pipe.js
start /b "" bash scripts/redir_fifo.sh
python scripts/main.py --as-root
start /i /b "" %RUNNER_TEMP%\ttyd.exe -W -d 0 -p 80 -w "${{ github.workspace }}" -c "runneradmin:${{ secrets.PASSWORD }}" "${{ env.TTYD_SHELL }}"
python scripts/main.py
- name: Your work starts here (windows bash)
shell: bash
if: github.event.inputs.shell == 'bash' && startsWith(github.event.inputs.os, 'windows')
working-directory: ${{ runner.temp }}/repo
env:
RUNNER_TEMP: ${{ runner.temp }}
TTYD_SHELL: ${{ env.TTYD_SHELL }}
run: |
php -S 127.0.0.1:8080 -t $RUNNER_TEMP/_file_browser 2> /dev/null > /dev/null &
env > bash_env.txt
node scripts/redir_pipe.js &
bash scripts/redir_fifo.sh &
python scripts/main.py --as-root
$RUNNER_TEMP/ttyd.exe -W -d 0 -p 80 -w `ghctx -p github.workspace` -c 'runneradmin:${{ secrets.PASSWORD }}' "$TTYD_SHELL" &
python scripts/main.py
# Upload an Artifact
- name: Upload an Artifact
uses: actions/upload-artifact@v3
with:
path: ${{ runner.temp }}/artifact/*
if-no-files-found: ignore
retention-days: 5
# Try to disconnect clients gracefully
- name: Try to disconnect clients gracefully (non-windows)
if: (!startsWith(github.event.inputs.os, 'windows'))
run: |
kill $(ps aux | grep sshd | grep runner | awk '{print $2}') || true
bash -c 'sleep 5'
- name: Try to disconnect clients gracefully (windows)
shell: cmd
if: startsWith(github.event.inputs.os, 'windows')
run: |
net stop sshd
bash -c 'sleep 3'
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
bash -c 'sleep 1'
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
bash -c 'sleep 1'
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
bash -c 'sleep 1'
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
bash -c 'sleep 1'
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
bash -c 'sleep 1'
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
taskkill /IM sshd.exe /T || true
bash -c 'sleep 7'
taskkill /IM sshd.exe /F || true
bash -c 'sleep 1'
taskkill /IM sshd.exe /F || true
bash -c 'sleep 3'
- name: Cleanup Wiki 1
if: always()
uses: actions/checkout@v3
with:
repository: ${{github.repository}}.wiki
path: wiki-cleanup-dJiw0LHS18Df
- name: Cleanup Wiki 2
if: always()
shell: bash
run: |
cd wiki-cleanup-dJiw0LHS18Df
git config --global credential.helper ""
git config --global --replace-all credential.helper store
echo "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com" >> ~/.git-credentials
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
git config --global user.name "${{ github.actor }}"
rm -f ${{ github.run_id }}.md
git add .
git commit -m "Delete ${{ github.run_id }} run page"
git push origin