Playground #123
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 | |
shell: | |
type: choice | |
description: Shell | |
options: | |
- bash | |
- pwsh | |
- cmd | |
tunnel: | |
type: choice | |
description: Tunnel service | |
options: | |
- bore | |
- zrok | |
- ZeroTier | |
- srv.us + SSH-J.com | |
- localhost.run + SSH-J.com | |
- ngrok + SSH-J.com | |
jobs: | |
action: | |
runs-on: ${{ github.event.inputs.os }} | |
steps: | |
# Connect with ZeroTier if needed | |
- name: Connect to ZeroTier | |
uses: zerotier/[email protected] | |
if: (github.event.inputs.tunnel == 'ZeroTier') || (vars.DEBUG == 'yes') | |
with: | |
network_id: ${{ secrets.ZEROTIER_NETWORK_ID }} | |
auth_token: ${{ secrets.ZEROTIER_ACCESS_TOKEN }} | |
- name: Setup ZeroTier | |
uses: kildom/[email protected] | |
if: (github.event.inputs.tunnel == 'ZeroTier') || (vars.DEBUG == 'yes') | |
with: | |
auth_token: ${{ secrets.ZEROTIER_ACCESS_TOKEN }} | |
ip: '${{ secrets.IP }} ${{ vars.IP }}' | |
name: 'Actions Playground' | |
# Setup debug channel if debug more is enabled | |
- name: Download ttyd for debug mode (windows) | |
if: vars.DEBUG == 'yes' && startsWith(github.event.inputs.os, 'windows') | |
shell: cmd | |
working-directory: ${{ runner.temp }} | |
run: | | |
curl -L https://github.com/tsl0922/ttyd/releases/latest/download/ttyd.win32.exe --output ttyd.exe | |
netsh advfirewall firewall add rule name="Open Port 8080" dir=in action=allow protocol=TCP localport=8080 | |
- name: Download ttyd for debug mode (ubuntu) | |
if: vars.DEBUG == 'yes' && 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 for debug mode (macos) | |
if: vars.DEBUG == 'yes' && startsWith(github.event.inputs.os, 'macos') | |
working-directory: ${{ runner.temp }} | |
run: | | |
brew install ttyd | |
echo TTYD_CMD=ttyd >> $GITHUB_ENV | |
# Checkout repo and keys and move to runner.temp | |
- name: Get main branch | |
uses: actions/checkout@v3 | |
with: | |
path: repo | |
fetch-depth: 0 | |
- 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 | |
- name: Check python executable (windows) | |
shell: cmd | |
if: startsWith(github.event.inputs.os, 'windows') | |
run: echo _PLAYGROUND_IGNORE_PYTHON=python.exe >> %GITHUB_ENV% | |
- name: Check python executable (non-windows) | |
shell: bash | |
if: (!startsWith(github.event.inputs.os, 'windows')) | |
run: echo _PLAYGROUND_IGNORE_PYTHON=python3 >> $GITHUB_ENV | |
# Collect environment variables for different shells | |
- name: Collect environment variables for bash | |
shell: bash | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
$_PLAYGROUND_IGNORE_PYTHON src/collect_env.py > ../bash.json | |
- name: Collect environment variables for cmd | |
shell: cmd | |
if: startsWith(github.event.inputs.os, 'windows') | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
%_PLAYGROUND_IGNORE_PYTHON% src\collect_env.py > ..\cmd.json | |
- name: Collect environment variables for pwsh | |
shell: pwsh | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
& $env:_PLAYGROUND_IGNORE_PYTHON src/collect_env.py > ../pwsh.json | |
# Change password | |
- name: Change system password (ubuntu) | |
if: startsWith(github.event.inputs.os, 'ubuntu') | |
run: | | |
echo -e "${{ secrets.PASSWORD }}\n${{ secrets.PASSWORD }}" | sudo passwd `whoami` | |
- name: Change system password (macos) | |
if: startsWith(github.event.inputs.os, 'macos') | |
run: | | |
sysadminctl -adminUser runner \ | |
-adminPassword `sudo python3 ${{ runner.temp }}/repo/src/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: Change system password (windows) | |
if: startsWith(github.event.inputs.os, 'windows') | |
shell: cmd | |
run: | | |
net user runneradmin "${{ secrets.PASSWORD }}" | |
# Do rest of the work in Python, it's easier there | |
- name: Debug mode (non-windows) | |
if: vars.DEBUG == 'yes' && !startsWith(github.event.inputs.os, 'windows') | |
working-directory: ${{ runner.temp }} | |
env: | |
RUNNER_TEMP: ${{ runner.temp }} | |
run: | | |
${{ env.TTYD_CMD }} -W -d 0 -p 8080 -w "$RUNNER_TEMP" -c 'runner:${{ secrets.PASSWORD }}' bash & | |
python3 -c "import time; time.sleep(21600)" | |
- name: Debug mode (windows non-bash) | |
if: vars.DEBUG == 'yes' && startsWith(github.event.inputs.os, 'windows') | |
shell: cmd | |
working-directory: ${{ runner.temp }} | |
env: | |
RUNNER_TEMP: ${{ runner.temp }} | |
run: | | |
start /i /b "" ttyd.exe -W -d 0 -p 8080 -w "%RUNNER_TEMP%" -c "runner:${{ secrets.PASSWORD }}" cmd.exe | |
python -c "import time; time.sleep(21600)" | |
- name: Your work starts here (non-windows) | |
if: vars.DEBUG != 'yes' | |
shell: bash | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
$_PLAYGROUND_IGNORE_PYTHON src/main.py | |
# Upload an Artifact | |
- name: Upload an Artifact | |
if: always() | |
uses: actions/upload-artifact@v3 | |
with: | |
path: ${{ runner.temp }}/artifact/* | |
if-no-files-found: ignore | |
retention-days: 5 | |
# Cleanup | |
- name: Cleanup | |
if: always() | |
shell: bash | |
working-directory: ${{ runner.temp }}/repo | |
run: | | |
$_PLAYGROUND_IGNORE_PYTHON src/cleanup.py |