Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ci scripts to run the app after build #709

Merged
merged 7 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 65 additions & 4 deletions .github/workflows/release-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,72 @@ jobs:
name: OpenAdapt
path: OpenAdapt.zip

test_on_macos:
name: Test on macOS
runs-on: macos-latest
needs: [build-macos-executables]
outputs:
macos_build_status: ${{ steps.test_on_macos.outputs.status }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download macOS executable
uses: actions/download-artifact@v4
with:
name: OpenAdapt.app
path: dist/
- name: Run app
id: test_on_macos
run: |
./build_scripts/test_app_run_macos.sh
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
echo "macos_build_status=failed" >> $GITHUB_OUTPUT
fi

test_on_windows:
name: Test on Windows
runs-on: windows-latest
needs: [build-windows-executables]
outputs:
windows_build_status: ${{ steps.test_on_windows.outputs.windows_build_status }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Windows executable
uses: actions/download-artifact@v4
with:
name: OpenAdapt
path: dist/
- name: Run app
id: test_on_windows
shell: powershell
run: |
./build_scripts/test_app_run_windows.bat
if ($LastExitCode -ne 0) {
"windows_build_status=failed" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
}

consolidate_tests:
name: Consolidate test results
runs-on: ubuntu-latest
needs: [test_on_windows, test_on_macos]
steps:
- name: Consolidate test results
id: consolidate_test_results
run: |
if [ "${{ needs.test_on_windows.outputs.windows_build_status }}" = "failed" ] || [ "${{ needs.test_on_macos.outputs.macos_build_status }}" = "failed" ]; then
echo "Error: Tests failed"
exit 1
fi

release:
runs-on: ubuntu-latest
needs: [check_last_commit_author, build-macos-executables, build-windows-executables]
if: ${{ needs.check_last_commit_author.outputs.skip_ci != 'true' }}
needs: [consolidate_tests]
concurrency: release
permissions:
id-token: write
Expand Down Expand Up @@ -143,8 +205,7 @@ jobs:

publish:
name: Publish to PyPI
needs: [check_last_commit_author, release]
if: ${{ needs.check_last_commit_author.outputs.skip_ci != 'true' }}
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
55 changes: 55 additions & 0 deletions build_scripts/test_app_run_macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# unzip the app

ZIPFILE_PATH="$(pwd)/dist/OpenAdapt.app.zip"
unzip -o "$ZIPFILE_PATH" -d "$(pwd)/dist"

APP_PATH="$(pwd)/dist/OpenAdapt.app/Contents/MacOS/OpenAdapt.app"

# print current directory
echo "Current directory: $(pwd)"
echo "App path: $APP_PATH"

# Run the app
open "$APP_PATH"

# Allow some time for the application to launch
sleep 30

# Verify that the executable exists
if [ -z "$APP_PATH" ]; then
echo "Error: Could not find executable in $APP_PATH"
exit 1
fi

# Get the process IDs
PIDS=$(pgrep -f "$APP_PATH")

# Verify that the process IDs were found
if [ -z "$PIDS" ]; then
echo "Error: Could not find process IDs for $APP_PATH"
exit 1
fi

# Variable to track if any process is still running
ALL_PROCESSES_RUNNING=true

# Check if the processes are still running
for PID in $PIDS; do
if ! ps -p $PID > /dev/null; then
echo "Process $PID is not running"
ALL_PROCESSES_RUNNING=false
break
fi
done

# Set the exit code variable based on the processes' status
if [ "$ALL_PROCESSES_RUNNING" = true ]; then
EXIT_CODE=0
else
EXIT_CODE=1
fi

echo "Exit code: $EXIT_CODE"
exit $EXIT_CODE
51 changes: 51 additions & 0 deletions build_scripts/test_app_run_windows.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@echo off

REM Unzip the distribution
set "ZIP_PATH=%cd%\dist\OpenAdapt.zip"
7z x %ZIP_PATH% -o%cd%\dist

REM Path to the .exe file
set "APP_PATH=%cd%\dist\OpenAdapt\OpenAdapt.exe"

REM Run the app
start %APP_PATH%

REM Allow some time for the application to launch
ping -n 30 127.0.0.1 >nul

REM Verify that the executable exists
if not exist "%APP_PATH%" (
echo Error: Could not find executable in %APP_PATH%
exit /b 1
)

REM Get the process IDs
for /f "tokens=2" %%i in ('tasklist /fi "imagename eq OpenAdapt.exe" /nh') do (
set "PID=%%i"
)

REM Verify that the process ID was found
if not defined PID (
echo Error: Could not find process IDs for %APP_PATH%
exit /b 1
)

REM Variable to track if any process is still running
set "ALL_PROCESSES_RUNNING=true"

REM Check if the processes are still running
tasklist /fi "pid eq %PID%" /nh | find /i "OpenAdapt.exe" >nul
if errorlevel 1 (
echo Process %PID% is not running
set "ALL_PROCESSES_RUNNING=false"
)

REM Set the exit code variable based on the processes' status
if "%ALL_PROCESSES_RUNNING%"=="true" (
set "EXIT_CODE=0"
) else (
set "EXIT_CODE=1"
)

echo Exit code: %EXIT_CODE%
exit /b %EXIT_CODE%
22 changes: 15 additions & 7 deletions openadapt/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@
# This needs to be called before any code that uses multiprocessing
multiprocessing.freeze_support()

from datetime import datetime

from openadapt.alembic.context_loader import load_alembic_context
from openadapt.app import tray
from openadapt.build_utils import redirect_stdout_stderr
from openadapt.config import print_config
from openadapt.build_utils import get_root_dir_path, redirect_stdout_stderr


def run_openadapt() -> None:
"""Run OpenAdapt."""
print_config()
load_alembic_context()
tray._run()
try:
from openadapt.alembic.context_loader import load_alembic_context
from openadapt.app import tray
from openadapt.config import print_config

print_config()
load_alembic_context()
tray._run()
except Exception as exc:
data_dir = get_root_dir_path()
# TODO: log all exceptions to a file
with open(data_dir / "error.log", "a") as f:
f.write(f"{datetime.now()}: {exc}\n")


if __name__ == "__main__":
Expand Down
Loading