Playground #107
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Playground | |
on: | |
workflow_dispatch: | |
inputs: | |
os: | |
type: choice | |
description: OS version | |
options: | |
- ubuntu-latest | |
- ubuntu-24.04 | |
- ubuntu-22.04 | |
- ubuntu-20.04 | |
- windows-latest | |
- windows-2022 | |
- windows-2019 | |
- macos-latest | |
- macos-15 | |
- macos-14 | |
- macos-13 | |
- macos-12 | |
jobs: | |
action: | |
runs-on: ${{ github.event.inputs.os }} | |
steps: | |
# Connect with ZeroTier | |
- uses: zerotier/[email protected] | |
with: | |
network_id: ${{ secrets.NETWORK_ID }} | |
auth_token: ${{ secrets.ACCESS_TOKEN }} | |
- uses: kildom/[email protected] | |
with: | |
auth_token: ${{ secrets.ACCESS_TOKEN }} | |
ip: '${{ secrets.IP }} ${{ vars.IP }}' | |
name: 'Actions Playground' | |
# 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: Move repo and keys | |
shell: bash | |
env: | |
RUNNER_TEMP: ${{ runner.temp }} | |
run: | | |
mv repo $RUNNER_TEMP/ | |
mv keys $RUNNER_TEMP/repo/ | |
# 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 | |
# Make sure that we use correct python executable | |
- shell: cmd | |
if: startsWith(github.event.inputs.os, 'windows') | |
run: echo "_PLAYGROUND_IGNORE_PYTHON=python.exe" >> %GITHUB_ENV% | |
- shell: bash | |
if: (!startsWith(github.event.inputs.os, 'windows')) | |
run: echo "_PLAYGROUND_IGNORE_PYTHON=python3" >> $GITHUB_ENV | |
# Collect environment variables for different shells | |
- shell: bash | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
$_PLAYGROUND_IGNORE_PYTHON src/script/collect_env.py > ../bash.json | |
- shell: cmd | |
if: startsWith(github.event.inputs.os, 'windows') | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
%_PLAYGROUND_IGNORE_PYTHON% src\script\collect_env.py > ..\cmd.json | |
- shell: pwsh | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
& $env:_PLAYGROUND_IGNORE_PYTHON src/script/collect_env.py > ../pwsh.json | |
- shell: bash | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
$_PLAYGROUND_IGNORE_PYTHON src/script/collect_env.py > ../bash2.json | |
- shell: cmd | |
if: startsWith(github.event.inputs.os, 'windows') | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
%_PLAYGROUND_IGNORE_PYTHON% src\script\collect_env.py > ..\cmd2.json | |
- shell: pwsh | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
& $env:_PLAYGROUND_IGNORE_PYTHON src/script/collect_env.py > ../pwsh2.json | |
# Change password | |
- if: startsWith(github.event.inputs.os, 'ubuntu') | |
run: | | |
echo -e "${{ secrets.PASSWORD }}\n${{ secrets.PASSWORD }}" | sudo passwd `whoami` | |
- if: startsWith(github.event.inputs.os, 'macos') | |
run: | | |
sysadminctl -adminUser runner \ | |
-adminPassword `sudo python3 ${{ runner.temp }}/repo/src/script/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 | |
- if: startsWith(github.event.inputs.os, 'windows') | |
shell: cmd | |
run: | | |
net user runneradmin "${{ secrets.PASSWORD }}" | |
# 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 | |
# 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 | |
run: | | |
sudo -u "`whoami`" ${{ env.TTYD_CMD }} -W -d 0 -p 8080 -w '${{ github.workspace }}' -c 'runner:${{ secrets.PASSWORD }}' bash & | |
sudo ps aux | |
ps aux | |
sleep 21600 | |
- name: Your work starts here (windows non-bash) | |
shell: cmd | |
if: startsWith(github.event.inputs.os, 'windows') | |
working-directory: ${{ runner.temp }}/repo | |
env: | |
RUNNER_TEMP: ${{ runner.temp }} | |
run: | | |
start /i /b "" %RUNNER_TEMP%\ttyd.exe -W -d 0 -p 8080 -w "${{ github.workspace }}" -c "runneradmin:${{ secrets.PASSWORD }}" cmd.exe | |
python -c "import time; time.sleep(21600)" | |
# 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 |