From 967d5efff1458d365dab3e9fa7666b38946bfdef Mon Sep 17 00:00:00 2001 From: Tiara Lena Hock Date: Wed, 6 Aug 2025 15:53:52 +0200 Subject: [PATCH 1/4] CI: Improve python caching * Check for existing python installation before installing new * Base caching method on found lockfile type --- .github/actions/setup/action.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 67ebe453..3df7181d 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -13,11 +13,32 @@ runs: if [ ! -f "requirements.txt" ]; then echo "python-gardenlinux-lib @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}" | tee -a requirements.txt fi + - name: Check for Python + id: python-check + run: | + if command -v python &/dev/null; then + echo "python_installed=true" >> $GITHUB_OUTPUT + else + echo "python_installed=false" >> $GITHUB_OUTPUT + fi + - name: Activate caching based on lockfile + id: lockfile + run: | + if [ -f poetry.lock ]; then + echo "cache_type=poetry" >> $GITHUB_OUTPUT + elif [ -f requirements.txt ]; then + echo "cache_type=pip" >> $GITHUB_OUTPUT + else + # no lockfile present: create empty requirements.txt and use pip caching + touch requirements.txt + echo "cache_type=pip" >> $GITHUB_OUTPUT + fi - name: Set up Python 3.13 + if: steps.python-check.outputs.python_installed == 'false' uses: actions/setup-python@v5 with: python-version: "3.13" - cache: 'pip' + cache: ${{ steps.lockfile.outputs.cache_type }} - name: Install GardenLinux Python library shell: bash run: | From 4a322d354170dc50931207c7df28fabcd9853cfe Mon Sep 17 00:00:00 2001 From: Tiara Lena Hock Date: Thu, 7 Aug 2025 13:42:07 +0200 Subject: [PATCH 2/4] CI: Consolidate python environment evaluation steps * Format Code * Combine cache type evaluation and installation verification into one * Expose cache_type as output to invoked actions --- .github/actions/setup/action.yml | 93 ++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 3df7181d..05a50e99 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -1,45 +1,56 @@ name: python_lib description: Installs the given GardenLinux Python library + inputs: - version: - description: GardenLinux Python library version - default: "0.8.9" + version: + description: GardenLinux Python library version + default: "0.8.9" + +outputs: + version: + description: "Detected Python cache strategy." + value: ${{ steps.env-check.outputs.cache_type }} + runs: - using: composite - steps: - - name: Verify requirements.txt for "actions/setup-python" with enabled "pip" cache - shell: bash - run: | - if [ ! -f "requirements.txt" ]; then - echo "python-gardenlinux-lib @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}" | tee -a requirements.txt - fi - - name: Check for Python - id: python-check - run: | - if command -v python &/dev/null; then - echo "python_installed=true" >> $GITHUB_OUTPUT - else - echo "python_installed=false" >> $GITHUB_OUTPUT - fi - - name: Activate caching based on lockfile - id: lockfile - run: | - if [ -f poetry.lock ]; then - echo "cache_type=poetry" >> $GITHUB_OUTPUT - elif [ -f requirements.txt ]; then - echo "cache_type=pip" >> $GITHUB_OUTPUT - else - # no lockfile present: create empty requirements.txt and use pip caching - touch requirements.txt - echo "cache_type=pip" >> $GITHUB_OUTPUT - fi - - name: Set up Python 3.13 - if: steps.python-check.outputs.python_installed == 'false' - uses: actions/setup-python@v5 - with: - python-version: "3.13" - cache: ${{ steps.lockfile.outputs.cache_type }} - - name: Install GardenLinux Python library - shell: bash - run: | - pip install git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }} + using: composite + steps: + - name: Verify requirements.txt for "actions/setup-python" with enabled "pip" cache + shell: bash + run: | + if [ ! -f "requirements.txt" ]; then + echo "gardenlinux @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}" | tee -a requirements.txt + fi + + - name: Evaluate Python Environment + id: env-check + shell: bash + run: | + # Check if python is installed + if command -v python &> /dev/null; then + echo "python_installed=true" >> $GITHUB_OUTPUT + else + echo "python_installed=false" >> $GITHUB_OUTPUT + fi + + # Determine cache type based on available lockfile + if [ -f poetry.lock ]; then + echo "cache_type=poetry" >> $GITHUB_OUTPUT + elif [ -f requirements.txt ]; then + echo "cache_type=pip" >> $GITHUB_OUTPUT + else + # no lockfile present: create empty requirements.txt and use pip caching + touch requirements.txt + echo "cache_type=pip" >> $GITHUB_OUTPUT + fi + + - name: Set up Python 3.13 + if: steps.env-check.outputs.python_installed == 'false' + uses: actions/setup-python@v5 + with: + python-version: "3.13" + cache: ${{ steps.env-check.outputs.cache_type }} + + - name: Install GardenLinux Python library + shell: bash + run: | + pip install git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }} From 18e1814fa8227538a5acfbf5fc0cf4454baddf61 Mon Sep 17 00:00:00 2001 From: Tiara Lena Hock Date: Thu, 7 Aug 2025 14:35:24 +0200 Subject: [PATCH 3/4] CI: Remove evaluation of python installation --- .github/actions/setup/action.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 05a50e99..73a79c80 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -25,13 +25,6 @@ runs: id: env-check shell: bash run: | - # Check if python is installed - if command -v python &> /dev/null; then - echo "python_installed=true" >> $GITHUB_OUTPUT - else - echo "python_installed=false" >> $GITHUB_OUTPUT - fi - # Determine cache type based on available lockfile if [ -f poetry.lock ]; then echo "cache_type=poetry" >> $GITHUB_OUTPUT @@ -44,7 +37,6 @@ runs: fi - name: Set up Python 3.13 - if: steps.env-check.outputs.python_installed == 'false' uses: actions/setup-python@v5 with: python-version: "3.13" From 8759217545ab00734da30688b4a66b8500bf5850 Mon Sep 17 00:00:00 2001 From: Tobias Wolf Date: Fri, 8 Aug 2025 06:55:02 +0200 Subject: [PATCH 4/4] Improve Python version handling and fix `poetry` installation Signed-off-by: Tobias Wolf --- .github/actions/setup/action.yml | 40 ++++++++++++++++++-------------- .github/workflows/pytests.yml | 10 ++++---- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 73a79c80..47a974f0 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -5,42 +5,48 @@ inputs: version: description: GardenLinux Python library version default: "0.8.9" + python_version: + description: Python version to setup + default: "3.13" outputs: version: + description: GardenLinux Python library version + value: ${{ inputs.version }} + python_version: + description: Python version to setup + value: ${{ inputs.python_version }} + package_tool: description: "Detected Python cache strategy." - value: ${{ steps.env-check.outputs.cache_type }} + value: ${{ steps.env-check.outputs.package_tool }} runs: using: composite steps: - - name: Verify requirements.txt for "actions/setup-python" with enabled "pip" cache - shell: bash - run: | - if [ ! -f "requirements.txt" ]; then - echo "gardenlinux @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}" | tee -a requirements.txt - fi - - - name: Evaluate Python Environment + - name: Evaluate Python environment id: env-check shell: bash run: | # Determine cache type based on available lockfile if [ -f poetry.lock ]; then - echo "cache_type=poetry" >> $GITHUB_OUTPUT + echo "package_tool=poetry" >> $GITHUB_OUTPUT elif [ -f requirements.txt ]; then - echo "cache_type=pip" >> $GITHUB_OUTPUT + echo "package_tool=pip" >> $GITHUB_OUTPUT else - # no lockfile present: create empty requirements.txt and use pip caching - touch requirements.txt - echo "cache_type=pip" >> $GITHUB_OUTPUT + # no lockfile present: create one and use pip caching + echo "gardenlinux @ git+https://github.com/gardenlinux/python-gardenlinux-lib.git@${{ inputs.version }}" | tee -a requirements.txt + echo "package_tool=pip" >> $GITHUB_OUTPUT fi - - name: Set up Python 3.13 + - name: Install Poetry + if: steps.env-check.outputs.package_tool == 'poetry' + uses: snok/install-poetry@v1 + + - name: Set up Python ${{ inputs.python_version }} uses: actions/setup-python@v5 with: - python-version: "3.13" - cache: ${{ steps.env-check.outputs.cache_type }} + python-version: ${{ inputs.python_version }} + cache: ${{ steps.env-check.outputs.package_tool }} - name: Install GardenLinux Python library shell: bash diff --git a/.github/workflows/pytests.yml b/.github/workflows/pytests.yml index 24498bc1..11092064 100644 --- a/.github/workflows/pytests.yml +++ b/.github/workflows/pytests.yml @@ -11,6 +11,9 @@ jobs: test: name: Run tests and collect coverage runs-on: ubuntu-latest + strategy: + matrix: + python_version: [ "3.13" ] steps: - name: Checkout uses: actions/checkout@v4 @@ -19,9 +22,8 @@ jobs: - name: Setup Gardenlinux uses: ./.github/actions/setup - - - name: Install Poetry - uses: snok/install-poetry@v1 + with: + python_version: ${{ matrix.python_version }} - name: Install dependencies run: poetry install --with dev @@ -30,7 +32,7 @@ jobs: run: make install-test - name: Run tests - run: | + run: | export GLOCI_REGISTRY_TOKEN="invalid" make test-coverage-ci