Skip to content

add os-specific paths to github workflow #61

add os-specific paths to github workflow

add os-specific paths to github workflow #61

# This workflow will install Python dependencies, lint with a variety of Python versions
# Based on github's default "Python package" workflow.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
# And https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#using-ruff-to-lint-code
name: Test update cycle
on: [push]
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest]
# for supported versions see https://devguide.python.org/versions/
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
defaults:
run:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
shell: pwsh # use PowerShell Core, also on macOS
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt --upgrade
pip install -r requirements.txt --upgrade
- name: lint with ruff
run: ruff --output-format=github .
- name: identify powershell version
run: $PSVersionTable # or $PSVersionTable.PSEdition
# https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context
- name: specify app directories for Windows
if: runner.os == 'Windows'
run: |
# make directories accessible as environment variables in subsequent steps
Add-Content -Path $Env:GITHUB_ENV -Value "MYAPP_INSTALL_DIR=$env:LOCALAPPDATA/Programs/my_app"
Add-Content -Path $Env:GITHUB_ENV -Value "MYAPP_TARGETS_DIR=$env:LOCALAPPDATA/my_app/update_cache/targets"
- name: specify app directories for macOS
if: runner.os == 'macOS'
run: |
# make directories accessible as environment variables in subsequent steps
Add-Content -Path $Env:GITHUB_ENV -Value "MYAPP_INSTALL_DIR=$HOME/Applications/my_app"
Add-Content -Path $Env:GITHUB_ENV -Value "MYAPP_TARGETS_DIR=$HOME/Library/my_app/update_cache/targets"
- name: add src to python path
run: Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;./src"
- run: $Env:PYTHONPATH
- name: initialize tufup repository
run: python repo_init.py
- name: create my_app v1.0 bundle using pyinstaller
run: pyinstaller "main.spec" --clean -y --distpath "temp_my_app/dist" --workpath "temp_my_app/build"
- name: add my_app v1.0 to tufup repository
run: python repo_add_bundle.py
- name: mock install my_app v1.0
run: |
$myapp_v1_archive = "./temp_my_app/repository/targets/my_app-1.0.tar.gz"
# create install dir and extract archive into it
New-Item -Path $Env:MYAPP_INSTALL_DIR -ItemType "directory"
tar -xf $myapp_v1_archive --directory=$Env:MYAPP_INSTALL_DIR
dir $Env:MYAPP_INSTALL_DIR
# create targets dir and copy the archive into it (this enables patch updates)
New-Item -Path $Env:MYAPP_TARGETS_DIR -ItemType "directory" -Force
Copy-Item $myapp_v1_archive -Destination $Env:MYAPP_TARGETS_DIR
- name: mock develop my_app v2.0
shell: python
run: |
import pathlib
settings_path = pathlib.Path('./src/myapp/settings.py')
settings_text = settings_path.read_text().replace('1.0', '2.0')
settings_path.write_text(settings_text)
# - run: cat ./src/myapp/settings.py
- name: create my_app v2.0 bundle using pyinstaller
run: pyinstaller "main.spec" --clean -y --distpath "temp_my_app/dist" --workpath "temp_my_app/build"
- name: add my_app v2.0 to tufup repository
run: python repo_add_bundle.py
- name: run update server and update my_app from v1 to v2
run: |
python -m http.server -d ./temp_my_app/repository &
sleep 5
Invoke-Expression "$Env:MYAPP_INSTALL_DIR/main.exe skip"
- name: proof of the pudding (i.e. verify that install dir contains my_app v2.0)
run: |
python -m http.server -d ./temp_my_app/repository &
sleep 5
$output = Invoke-Expression "$Env:MYAPP_INSTALL_DIR/main.exe skip"
$pattern = "my_app 2.0"
if ( $output -match $pattern ) {
Write-Output "success: $pattern found"
} else {
Write-Output "fail: $pattern not found in:`n$output"
exit 1
}