name: E2E test with video recording on: workflow_dispatch: inputs: ref: description: Branch or SHA to test required: false default: "" test_filter: description: "Test class or class/method (e.g. UpdatePillUITests or UpdatePillUITests/testSomething)" required: true test_timeout: description: "Per-test timeout in seconds" required: false default: "120" record_video: description: Record the virtual display during tests required: false default: true type: boolean jobs: e2e: runs-on: macos-15 env: TEST_REF: ${{ inputs.ref || github.ref }} steps: - name: Checkout uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 with: ref: ${{ inputs.ref || github.ref }} submodules: recursive - name: Capture SHA id: sha run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" - name: Select Xcode run: | set -euo pipefail if [ -d "/Applications/Xcode.app/Contents/Developer" ]; then XCODE_DIR="/Applications/Xcode.app/Contents/Developer" else XCODE_APP="$(ls -d /Applications/Xcode*.app 2>/dev/null | head -n 1 || true)" if [ -n "$XCODE_APP" ]; then XCODE_DIR="$XCODE_APP/Contents/Developer" else echo "No Xcode.app found under /Applications" >&2 exit 1 fi fi echo "DEVELOPER_DIR=$XCODE_DIR" >> "$GITHUB_ENV" export DEVELOPER_DIR="$XCODE_DIR" xcodebuild -version xcrun --sdk macosx --show-sdk-path - name: Download pre-built GhosttyKit.xcframework env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -euo pipefail GHOSTTY_SHA=$(git -C ghostty rev-parse HEAD) TAG="xcframework-$GHOSTTY_SHA" URL="https://github.com/manaflow-ai/ghostty/releases/download/$TAG/GhosttyKit.xcframework.tar.gz" echo "Downloading xcframework for ghostty $GHOSTTY_SHA" MAX_RETRIES=30 RETRY_DELAY=20 for i in $(seq 1 $MAX_RETRIES); do if curl -fSL -o GhosttyKit.xcframework.tar.gz "$URL"; then echo "Download succeeded on attempt $i" break fi if [ "$i" -eq "$MAX_RETRIES" ]; then echo "Failed to download xcframework after $MAX_RETRIES attempts" >&2 exit 1 fi echo "Attempt $i/$MAX_RETRIES failed, retrying in ${RETRY_DELAY}s..." sleep $RETRY_DELAY done tar xzf GhosttyKit.xcframework.tar.gz rm GhosttyKit.xcframework.tar.gz test -d GhosttyKit.xcframework - name: Create virtual display run: | set -euo pipefail echo "=== Display before ===" system_profiler SPDisplaysDataType 2>/dev/null || echo "(none)" echo "" clang -framework Foundation -framework CoreGraphics \ -o /tmp/create-virtual-display scripts/create-virtual-display.m /tmp/create-virtual-display & VDISPLAY_PID=$! echo "VDISPLAY_PID=$VDISPLAY_PID" >> "$GITHUB_ENV" sleep 3 echo "=== Display after ===" system_profiler SPDisplaysDataType 2>/dev/null || echo "(none)" - name: Install ffmpeg if: ${{ inputs.record_video }} run: | brew install --quiet ffmpeg FFMPEG_PATH=$(which ffmpeg) echo "ffmpeg: $FFMPEG_PATH" ffmpeg -version | head -1 echo "FFMPEG_PATH=$FFMPEG_PATH" >> "$GITHUB_ENV" - name: Grant TCC screen recording permission continue-on-error: true run: | TCC_DB="$HOME/Library/Application Support/com.apple.TCC/TCC.db" if [ -f "$TCC_DB" ]; then for client in /usr/sbin/screencapture "${FFMPEG_PATH:-/opt/homebrew/bin/ffmpeg}" /opt/homebrew/bin/ffmpeg /usr/local/bin/ffmpeg; do sqlite3 "$TCC_DB" "INSERT OR REPLACE INTO access (service, client, client_type, auth_value, auth_reason, auth_version) VALUES ('kTCCServiceScreenCapture', '$client', 1, 2, 4, 1);" 2>/dev/null || true done fi - name: Start screen recording if: ${{ inputs.record_video }} run: | # Detect screen capture device index. ffmpeg -list_devices always # exits non-zero; redirect noise to a temp file and parse it. DEVLIST=$( ffmpeg -f avfoundation -list_devices true -i "" 2>&1 || true ) echo "Available devices:" echo "$DEVLIST" | grep -E "AVFoundation|Capture screen" SCREEN_INDEX=$( echo "$DEVLIST" | grep "Capture screen" | head -1 \ | sed 's/.*\[\([0-9]*\)\].*/\1/' ) SCREEN_INDEX="${SCREEN_INDEX:-0}" echo "Using screen device index: $SCREEN_INDEX" # Start recording. Try detected index, fall back to 1 if it dies immediately. start_recording() { ffmpeg -f avfoundation -framerate 10 -capture_cursor 1 \ -i "$1:none" \ -c:v libx264 -preset ultrafast -pix_fmt yuv420p \ /tmp/test-recording.mp4 /tmp/ffmpeg.log 2>&1 & echo $! } RECORD_PID=$(start_recording "$SCREEN_INDEX") sleep 2 if ! kill -0 "$RECORD_PID" 2>/dev/null; then echo "Index $SCREEN_INDEX failed, trying index 1" cat /tmp/ffmpeg.log rm -f /tmp/test-recording.mp4 RECORD_PID=$(start_recording 1) sleep 2 fi if kill -0 "$RECORD_PID" 2>/dev/null; then echo "Recording started (PID $RECORD_PID)" else echo "::error::ffmpeg screen recording failed to start" cat /tmp/ffmpeg.log fi echo "RECORD_PID=$RECORD_PID" >> "$GITHUB_ENV" - name: Clean DerivedData run: rm -rf ~/Library/Developer/Xcode/DerivedData/GhosttyTabs-* - name: Resolve Swift packages run: | set -euo pipefail SOURCE_PACKAGES_DIR="$PWD/.ci-source-packages" rm -rf "$SOURCE_PACKAGES_DIR" mkdir -p "$SOURCE_PACKAGES_DIR" for attempt in 1 2 3; do if xcodebuild -project GhosttyTabs.xcodeproj -scheme cmux-unit -configuration Debug \ -clonedSourcePackagesDirPath "$SOURCE_PACKAGES_DIR" \ -resolvePackageDependencies; then exit 0 fi if [ "$attempt" -eq 3 ]; then echo "Failed to resolve Swift packages after 3 attempts" >&2 exit 1 fi echo "Package resolution failed on attempt $attempt, retrying..." sleep $((attempt * 5)) done - name: Run UI tests id: tests env: TEST_FILTER: ${{ inputs.test_filter }} TEST_TIMEOUT: ${{ inputs.test_timeout || '120' }} run: | set -euo pipefail SOURCE_PACKAGES_DIR="$PWD/.ci-source-packages" ONLY_TESTING="-only-testing:cmuxUITests/$TEST_FILTER" set +e OUTPUT=$(xcodebuild -project GhosttyTabs.xcodeproj -scheme cmux -configuration Debug \ -clonedSourcePackagesDirPath "$SOURCE_PACKAGES_DIR" \ -disableAutomaticPackageResolution \ -destination "platform=macOS" \ -maximum-test-execution-time-allowance "$TEST_TIMEOUT" \ $ONLY_TESTING test 2>&1) EXIT_CODE=$? set -e echo "$OUTPUT" # Save summary for the issue SUMMARY=$(echo "$OUTPUT" | grep -E "(Test Suite|Executed|FAIL|PASS)" | tail -20) { echo "test_summary<> "$GITHUB_OUTPUT" if [ "$EXIT_CODE" -eq 0 ]; then echo "test_result=passed" >> "$GITHUB_OUTPUT" else echo "test_result=failed" >> "$GITHUB_OUTPUT" # Save full output for the issue body { echo "test_output<> "$GITHUB_OUTPUT" exit 1 fi - name: Stop screen recording if: ${{ always() && inputs.record_video && env.RECORD_PID != '' }} run: | # Send quit signal to ffmpeg for clean finalization kill -INT "$RECORD_PID" 2>/dev/null || true for i in $(seq 1 15); do if ! kill -0 "$RECORD_PID" 2>/dev/null; then echo "Recording stopped after ${i}s" break fi sleep 1 done kill -9 "$RECORD_PID" 2>/dev/null || true echo "=== ffmpeg log ===" cat /tmp/ffmpeg.log 2>/dev/null || true echo "=== recording file ===" ls -lh /tmp/test-recording.mp4 2>/dev/null || echo "No recording file found" - name: Upload recording artifact if: ${{ always() && inputs.record_video }} uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 with: name: test-recording path: /tmp/test-recording.mp4 if-no-files-found: warn - name: Post results to cmux-dev-artifacts if: always() env: GH_TOKEN: ${{ secrets.DEV_ARTIFACTS_TOKEN }} TEST_RESULT: ${{ steps.tests.outputs.test_result || 'failed' }} TEST_SUMMARY: ${{ steps.tests.outputs.test_summary }} TEST_OUTPUT: ${{ steps.tests.outputs.test_output }} TEST_FILTER: ${{ inputs.test_filter }} COMMIT_SHA: ${{ steps.sha.outputs.sha }} RUN_ID: ${{ github.run_id }} RECORD_VIDEO: ${{ inputs.record_video }} run: | set -euo pipefail LABEL="$TEST_RESULT" if [ "$TEST_RESULT" = "passed" ]; then STATUS_EMOJI="PASSED" else STATUS_EMOJI="FAILED" fi REF_DISPLAY="${{ inputs.ref || github.ref_name }}" RUN_URL="https://github.com/${{ github.repository }}/actions/runs/$RUN_ID" ARTIFACT_URL="$RUN_URL#artifacts" # Build issue body (no leading whitespace) BODY="**Status:** $STATUS_EMOJI **Ref:** \`$REF_DISPLAY\` **SHA:** [\`${COMMIT_SHA:0:12}\`](https://github.com/${{ github.repository }}/commit/$COMMIT_SHA) **Test:** \`$TEST_FILTER\` **Workflow run:** $RUN_URL" if [ "$RECORD_VIDEO" = "true" ]; then BODY="$BODY **Recording:** [Download from artifacts]($ARTIFACT_URL)" fi if [ -n "$TEST_OUTPUT" ]; then BODY="$BODY
Test output (last 200 lines) \`\`\` $TEST_OUTPUT \`\`\`
" fi if [ -n "$TEST_SUMMARY" ]; then BODY="$BODY \`\`\` $TEST_SUMMARY \`\`\`" fi ISSUE_URL=$(gh issue create \ --repo manaflow-ai/cmux-dev-artifacts \ --title "[$STATUS_EMOJI] $TEST_FILTER @ ${COMMIT_SHA:0:7} ($REF_DISPLAY)" \ --body "$BODY" \ --label "$LABEL") echo "Issue posted: $ISSUE_URL" echo "::notice title=Test Result Issue::$ISSUE_URL"