From ed20bbcbe682790f8c98be63005cf198007dd31b Mon Sep 17 00:00:00 2001 From: Kevin Montag Date: Mon, 19 Aug 2024 01:39:33 +0200 Subject: [PATCH] ci: add action to access CI server over VNC --- .github/macos_vnc.sh | 38 +++++++++++++++++++++++++ .github/workflows/macos_vnc.yml | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/macos_vnc.sh create mode 100644 .github/workflows/macos_vnc.yml diff --git a/.github/macos_vnc.sh b/.github/macos_vnc.sh new file mode 100644 index 0000000..7fdec7a --- /dev/null +++ b/.github/macos_vnc.sh @@ -0,0 +1,38 @@ +# From https://github.com/vnc-tools/debug-on-mac. +# +# macos_vnc.sh VNC_USER_PASSWORD VNC_PASSWORD NGROK_AUTH_TOKEN + +# Disable spotlight indexing +sudo mdutil -i off -a + +# Create new account +sudo dscl . -create /Users/vncuser +sudo dscl . -create /Users/vncuser UserShell /bin/bash +sudo dscl . -create /Users/vncuser RealName "VNC User" +sudo dscl . -create /Users/vncuser UniqueID 1001 +sudo dscl . -create /Users/vncuser PrimaryGroupID 80 +sudo dscl . -create /Users/vncuser NFSHomeDirectory /Users/vncuser +sudo dscl . -passwd /Users/vncuser $1 +sudo dscl . -passwd /Users/vncuser $1 +sudo createhomedir -c -u vncuser >/dev/null + +# Enable VNC +sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all +sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -clientopts -setvnclegacy -vnclegacy yes + +# Set VNC password +# This sets the password directly in the preferences file becuase MacOS 10.14 +# and later does not allows control the Screen Sharing without using the UI +# See: # http://hints.macworld.com/article.php?story=20071103011608872 +echo $2 | perl -we 'BEGIN { @k = unpack "C*", pack "H*", "1734516E8BA8C5E2FF1C39567390ADCA"}; $_ = <>; chomp; s/^(.{8}).*/$1/; @p = unpack "C*", $_; foreach (@k) { printf "%02X", $_ ^ (shift @p || 0) }; print "\n"' | sudo tee /Library/Preferences/com.apple.VNCSettings.txt + +# Start VNC/reset changes +sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -restart -agent -console +sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate + +# Install ngrok +brew install --cask ngrok + +# Configure ngrok and start it +ngrok authtoken $3 +ngrok tcp 5900 & diff --git a/.github/workflows/macos_vnc.yml b/.github/workflows/macos_vnc.yml new file mode 100644 index 0000000..e642e03 --- /dev/null +++ b/.github/workflows/macos_vnc.yml @@ -0,0 +1,50 @@ +# From https://github.com/vnc-tools/debug-on-mac. +# +# Set up the server for a VNC connection via ngrok. +name: macos_vnc +on: + workflow_dispatch: + inputs: + vnc_user_password: + description: Password for the created user (vncuser) + required: true + +defaults: + run: + shell: bash + +jobs: + build: + runs-on: macos-13 + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up environment + env: + NGROK_AUTH_TOKEN: ${{ secrets.NGROK_AUTH_TOKEN }} + VNC_USER_PASSWORD: ${{ github.event.inputs.vnc_user_password }} + VNC_PASSWORD: ${{ github.event.inputs.vnc_user_password }} + run: source .github/macos_vnc.sh "$VNC_USER_PASSWORD" "$VNC_PASSWORD" "$NGROK_AUTH_TOKEN" + + - name: Set up Homebrew + id: set-up-homebrew + uses: Homebrew/actions/setup-homebrew@master + + - name: Install Ableton Live + run: brew install --cask ableton-live-lite + + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.8 + cache: pip + + - run: python -m pip install poetry + - run: poetry install + + - name: ngrok is now listening to VNC connections on... + run: curl --silent http://127.0.0.1:4040/api/tunnels | jq '.tunnels[0].public_url' + + - name: Setup tmate session + uses: mxschmitt/action-tmate@v2