From 65b3ea110bb0df64cf89e10ba246c01dab1f0ef9 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:44:28 +0100 Subject: [PATCH 01/14] add macos to github workflow work in progress: expected to fail --- .github/workflows/test-update-cycle.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index dfaeb64..92c0aac 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -10,13 +10,20 @@ on: [push] jobs: build: - runs-on: windows-latest 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 }} @@ -32,6 +39,13 @@ jobs: 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: echo "Windows" # TEMP + - name: specify app directories for macOS + if: ${{ runner.os }} == "macOS" + run: echo "macOS" # TEMP - name: add src to python path run: Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;.\src" - run: $Env:PYTHONPATH From 33c062ff668c54b059e58926e7ffbf6089b83496 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:55:20 +0100 Subject: [PATCH 02/14] fix github workflow ifs --- .github/workflows/test-update-cycle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 92c0aac..5b751ad 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -41,10 +41,10 @@ jobs: 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" + if: runner.os == "Windows" run: echo "Windows" # TEMP - name: specify app directories for macOS - if: ${{ runner.os }} == "macOS" + if: runner.os == "macOS" run: echo "macOS" # TEMP - name: add src to python path run: Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;.\src" From f6aa392cafb5222e089a715d6f3d3500ce2af407 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:57:52 +0100 Subject: [PATCH 03/14] fix github workflow ifs more --- .github/workflows/test-update-cycle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 5b751ad..a5adcd7 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -41,10 +41,10 @@ jobs: 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" + if: runner.os == Windows run: echo "Windows" # TEMP - name: specify app directories for macOS - if: runner.os == "macOS" + if: runner.os == macOS run: echo "macOS" # TEMP - name: add src to python path run: Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;.\src" From fc74e72152a885876b40345f9d4d372688a19003 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:00:46 +0100 Subject: [PATCH 04/14] fix github workflow ifs even more --- .github/workflows/test-update-cycle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index a5adcd7..9ab98e3 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -41,10 +41,10 @@ jobs: 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 + if: ${{ runner.os == "Windows" }} run: echo "Windows" # TEMP - name: specify app directories for macOS - if: runner.os == macOS + if: ${{ runner.os == "macOS" }} run: echo "macOS" # TEMP - name: add src to python path run: Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;.\src" From fc74b55db4fcd245a8d60fd896104d9beace71f5 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:07:34 +0100 Subject: [PATCH 05/14] fix github workflow ifs truly, hopefully, with single quotes... --- .github/workflows/test-update-cycle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 9ab98e3..9ea0b7a 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -41,10 +41,10 @@ jobs: 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" }} + if: runner.os == 'Windows' run: echo "Windows" # TEMP - name: specify app directories for macOS - if: ${{ runner.os == "macOS" }} + if: runner.os == 'macOS' run: echo "macOS" # TEMP - name: add src to python path run: Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;.\src" From 5118617f8a5a1c15620d8e41c0eefe1dcb0f41e8 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:18:28 +0100 Subject: [PATCH 06/14] try forward slash paths in github workflow --- .github/workflows/test-update-cycle.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 9ea0b7a..733eb37 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -47,19 +47,19 @@ jobs: if: runner.os == 'macOS' run: echo "macOS" # TEMP - name: add src to python path - run: Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;.\src" + 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: cmd.exe /c .\create_pyinstaller_bundle_win.bat + run: cmd.exe /c ./create_pyinstaller_bundle_win.bat - 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" - $myapp_install_dir = "$env:LOCALAPPDATA\Programs\my_app" - $myapp_targets_dir = "$env:LOCALAPPDATA\my_app\update_cache\targets" + $myapp_v1_archive = "./temp_my_app/repository/targets/my_app-1.0.tar.gz" + $myapp_install_dir = "$env:LOCALAPPDATA/Programs/my_app" + $myapp_targets_dir = "$env:LOCALAPPDATA/my_app/update_cache/targets" # make install dir accessible as environment variable in subsequent steps Add-Content -Path $Env:GITHUB_ENV -Value "MYAPP_INSTALL_DIR=$myapp_install_dir" # create install dir and extract archive into it @@ -73,24 +73,24 @@ jobs: shell: python run: | import pathlib - settings_path = pathlib.Path('.\src\myapp\settings.py') + 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 +# - run: cat ./src/myapp/settings.py - name: create my_app v2.0 bundle using pyinstaller - run: cmd.exe /c .\create_pyinstaller_bundle_win.bat + run: cmd.exe /c ./create_pyinstaller_bundle_win.bat - 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 & + python -m http.server -d ./temp_my_app/repository & sleep 5 - Invoke-Expression "$Env:MYAPP_INSTALL_DIR\main.exe skip" + 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 & + python -m http.server -d ./temp_my_app/repository & sleep 5 - $output = Invoke-Expression "$Env:MYAPP_INSTALL_DIR\main.exe skip" + $output = Invoke-Expression "$Env:MYAPP_INSTALL_DIR/main.exe skip" $pattern = "my_app 2.0" if ( $output -match $pattern ) { Write-Output "success: $pattern found" From 462fdb950c0dfbc50d941c82a6aefba8c8490ba8 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:29:10 +0100 Subject: [PATCH 07/14] call pyinstaller directly in github workflow --- .github/workflows/test-update-cycle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 733eb37..ffb9d10 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -52,7 +52,7 @@ jobs: - name: initialize tufup repository run: python repo_init.py - name: create my_app v1.0 bundle using pyinstaller - run: cmd.exe /c ./create_pyinstaller_bundle_win.bat + run: pyinstaller "main.spec" --clean -y --distpath "${{ runner.temp }}/dist" --workpath "${{ runner.temp }}/build" - name: add my_app v1.0 to tufup repository run: python repo_add_bundle.py - name: mock install my_app v1.0 @@ -78,7 +78,7 @@ jobs: settings_path.write_text(settings_text) # - run: cat ./src/myapp/settings.py - name: create my_app v2.0 bundle using pyinstaller - run: cmd.exe /c ./create_pyinstaller_bundle_win.bat + run: pyinstaller "main.spec" --clean -y --distpath "${{ runner.temp }}/dist" --workpath "${{ runner.temp }}/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 From c87a7680684ffa436a9338aad53bf2c50f8f7f40 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:48:26 +0100 Subject: [PATCH 08/14] add os-specific paths to github workflow --- .github/workflows/test-update-cycle.yml | 28 +++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index ffb9d10..d0059cf 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -42,33 +42,35 @@ jobs: # https://docs.github.com/en/actions/learn-github-actions/contexts#runner-context - name: specify app directories for Windows if: runner.os == 'Windows' - run: echo "Windows" # TEMP + 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: echo "macOS" # TEMP + 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 "${{ runner.temp }}/dist" --workpath "${{ runner.temp }}/build" + 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" - $myapp_install_dir = "$env:LOCALAPPDATA/Programs/my_app" - $myapp_targets_dir = "$env:LOCALAPPDATA/my_app/update_cache/targets" - # make install dir accessible as environment variable in subsequent steps - Add-Content -Path $Env:GITHUB_ENV -Value "MYAPP_INSTALL_DIR=$myapp_install_dir" # create install dir and extract archive into it - New-Item -Path $myapp_install_dir -ItemType "directory" - tar -xf $myapp_v1_archive --directory=$myapp_install_dir - dir $myapp_install_dir + 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 $myapp_targets_dir -ItemType "directory" -Force - Copy-Item $myapp_v1_archive -Destination $myapp_targets_dir + 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: | @@ -78,7 +80,7 @@ jobs: 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 "${{ runner.temp }}/dist" --workpath "${{ runner.temp }}/build" + 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 From d2abc203203f3d359106308114a2c4d37331730b Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:59:22 +0100 Subject: [PATCH 09/14] set PYTHONPATH per os in github workflow --- .github/workflows/test-update-cycle.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index d0059cf..8f52e2c 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -46,15 +46,16 @@ jobs: # 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" + # add src directory to python path + Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH;./src" - 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 + # add src directory to python path + Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH:src" - name: initialize tufup repository run: python repo_init.py - name: create my_app v1.0 bundle using pyinstaller From d99f9c2dd458e7c3db850001587b5b836541275f Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:03:31 +0100 Subject: [PATCH 10/14] try to fix PYTHONPATH on macos in github workflow --- .github/workflows/test-update-cycle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 8f52e2c..17637b3 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -55,7 +55,7 @@ jobs: 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" # add src directory to python path - Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH:src" + Add-Content -Path $Env:GITHUB_ENV -Value "PYTHONPATH=$Env:PYTHONPATH:./src" - name: initialize tufup repository run: python repo_init.py - name: create my_app v1.0 bundle using pyinstaller From f39bb2b6346c88e4630879799d9af5c5e6037fe4 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:45:48 +0100 Subject: [PATCH 11/14] temp debug step --- .github/workflows/test-update-cycle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 17637b3..b3de590 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -79,11 +79,11 @@ jobs: 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 + - run: dir $Env:MYAPP_INSTALL_DIR # TEMP - name: run update server and update my_app from v1 to v2 run: | python -m http.server -d ./temp_my_app/repository & From 5b41cc5882cd8ea3382ac9a6bddc2102696b8feb Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:00:34 +0100 Subject: [PATCH 12/14] remove suffix from executable call in github workflow --- .github/workflows/test-update-cycle.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index b3de590..398381b 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -83,12 +83,12 @@ jobs: 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 - - run: dir $Env:MYAPP_INSTALL_DIR # TEMP + - run: Get-ChildItem -Force -LiteralPath $Env:MYAPP_INSTALL_DIR # TEMP - 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" + Invoke-Expression "$Env:MYAPP_INSTALL_DIR/main 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 & From 979d9217379c9025f0e2f209935abdf0b3c2f8eb Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:03:44 +0100 Subject: [PATCH 13/14] forgot one... --- .github/workflows/test-update-cycle.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-update-cycle.yml b/.github/workflows/test-update-cycle.yml index 398381b..2a1639e 100644 --- a/.github/workflows/test-update-cycle.yml +++ b/.github/workflows/test-update-cycle.yml @@ -83,7 +83,6 @@ jobs: 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 - - run: Get-ChildItem -Force -LiteralPath $Env:MYAPP_INSTALL_DIR # TEMP - name: run update server and update my_app from v1 to v2 run: | python -m http.server -d ./temp_my_app/repository & @@ -93,7 +92,7 @@ jobs: run: | python -m http.server -d ./temp_my_app/repository & sleep 5 - $output = Invoke-Expression "$Env:MYAPP_INSTALL_DIR/main.exe skip" + $output = Invoke-Expression "$Env:MYAPP_INSTALL_DIR/main skip" $pattern = "my_app 2.0" if ( $output -match $pattern ) { Write-Output "success: $pattern found" From e5053ca19aaca3990a73456f8f49c9796035c845 Mon Sep 17 00:00:00 2001 From: dennisvang <29799340+dennisvang@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:03:38 +0100 Subject: [PATCH 14/14] adapt test_update_cycle powershell script to work on macos as well (tested on windows but not yet on macos...) --- test_update_cycle.ps1 | 46 ++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/test_update_cycle.ps1 b/test_update_cycle.ps1 index 3ff67f3..4413ec8 100644 --- a/test_update_cycle.ps1 +++ b/test_update_cycle.ps1 @@ -24,6 +24,8 @@ # but workflow failures are easier to debug when broken down into # separate steps +# requires Powershell 6 or higher + # exit on cmdlet errors $ErrorActionPreference = "stop" @@ -41,11 +43,21 @@ $enable_patch_update = $true # directories where this script creates files and deletes files (note these must end # with $app_name and must be consistent with myapp.settings and repo_settings) -$repo_dir = $PSScriptRoot -$temp_dir = "$repo_dir\temp_$app_name" -$app_install_dir = "$env:LOCALAPPDATA\Programs\$app_name" -$app_data_dir = "$env:LOCALAPPDATA\$app_name" -$targets_dir = "$app_data_dir\update_cache\targets" +$repo_dir = "$PSScriptRoot" +$temp_dir = Join-Path "$repo_dir" "temp_$app_name" +if ( $IsWindows ) { + $app_install_dir = Join-Path "$env:LOCALAPPDATA" "Programs" "$app_name" + $app_data_dir = Join-Path "$env:LOCALAPPDATA" "$app_name" + $path_separator = ";" +} elseif ( $IsMacOS ) { + $app_install_dir = Join-Path "$HOME" "Applications" "$app_name" + $app_data_dir = Join-Path "$HOME" "Library" "$app_name" + $path_separator = ":" +} else { + Write-Host "unsupported OS" -ForegroundColor red + exit 1 +} +$targets_dir = Join-Path "$app_data_dir" "update_cache" "targets" $all_app_dirs = @($temp_dir, $app_install_dir, $app_data_dir) function Remove-MyAppDirectory { @@ -68,7 +80,7 @@ function Remove-MyApp { } function Invoke-PyInstaller { - pyinstaller.exe "$repo_dir\main.spec" --clean -y --distpath "$temp_dir\dist" --workpath "$temp_dir\build" + pyinstaller "$repo_dir/main.spec" --clean -y --distpath "$temp_dir/dist" --workpath "$temp_dir/build" Assert-ExeSuccess } @@ -86,7 +98,7 @@ New-Item -Path $targets_dir -ItemType "directory" -Force | Out-Null # this script requires an active python environment, with tufup installed # (we'll assume there's a venv in the repo_dir) -$venv_path = "$repo_dir\venv\Scripts\activate.ps1" +$venv_path = Join-Path "$repo_dir" "venv" "Scripts" "activate.ps1" if (Test-Path $venv_path) { & $venv_path Write-Host "venv activated" -ForegroundColor green @@ -95,11 +107,11 @@ if (Test-Path $venv_path) { } # make sure python can find myapp -$Env:PYTHONPATH += ";$repo_dir\src" +$Env:PYTHONPATH += "$path_separator$repo_dir/src" # - initialize new repository Write-Host "initializing tuf repository for $app_name" -ForegroundColor green -python "$repo_dir\repo_init.py" +python "$repo_dir/repo_init.py" Assert-ExeSuccess # - create my_app v1.0 bundle using pyinstaller @@ -108,12 +120,12 @@ Invoke-PyInstaller # - add my_app v1.0 to tufup repository Write-Host "adding $app_name v1.0 bundle to repo" -ForegroundColor green -python "$repo_dir\repo_add_bundle.py" +python "$repo_dir/repo_add_bundle.py" Assert-ExeSuccess # - mock install my_app v1.0 Write-Host "installing $app_name v1.0 in $app_install_dir" -ForegroundColor green -$myapp_v1_archive = "$temp_dir\repository\targets\$app_name-1.0.tar.gz" +$myapp_v1_archive = Join-Path "$temp_dir" "repository" "targets" "$app_name-1.0.tar.gz" tar -xf $myapp_v1_archive --directory=$app_install_dir # put a copy of the archive in the targets dir, to enable patch updates if ($enable_patch_update) { @@ -125,7 +137,7 @@ if ($enable_patch_update) { # (quick and dirty, this modifies the actual source, # but the change is rolled back later...) Write-Host "bumping $app_name version to v2.0 (temporary)" -ForegroundColor green -$settings_path = "$repo_dir\src\myapp\settings.py" +$settings_path = Join-Path "$repo_dir" "src" "myapp" "settings.py" (Get-Content $settings_path).Replace("1.0", "2.0") | Set-Content $settings_path # - create my_app v2.0 bundle using pyinstaller @@ -134,7 +146,7 @@ Invoke-PyInstaller # - add my_app v2.0 to tufup repository Write-Host "adding $app_name v2.0 bundle to repo" -ForegroundColor green -python "$repo_dir\repo_add_bundle.py" +python "$repo_dir/repo_add_bundle.py" Assert-ExeSuccess # - roll-back modified source @@ -143,7 +155,7 @@ Write-Host "rolling back temporary source modification" -ForegroundColor green # - start update server Write-Host "starting update server" -ForegroundColor green -$job = Start-Job -ArgumentList @("$temp_dir\repository") -ScriptBlock { +$job = Start-Job -ArgumentList @("$temp_dir/repository") -ScriptBlock { param($repository_path) python -m http.server -d $repository_path Assert-ExeSuccess @@ -152,14 +164,16 @@ sleep 1 # not sure if this is required, but cannot hurt # - run my_app to update from v1 to v2 Write-Host "running $app_name for update..." -ForegroundColor green -Invoke-Expression "$app_install_dir\main.exe" +& "$app_install_dir\main" Assert-ExeSuccess # - run my_app again to verify we now have v2.0 Write-Host "hit enter to proceed, after console has closed:" -ForegroundColor yellow -NoNewLine Read-Host # no text: we use write host to add color Write-Host "running $app_name again to verify version" -ForegroundColor green -$output = Invoke-Expression "$app_install_dir\main.exe" +# https://devblogs.microsoft.com/powershell/invoke-expression-considered-harmful/ +# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.4#call-operator- +$output = & "$app_install_dir/main" Assert-ExeSuccess # - stop update server