From e272243fc232bf5e49e9108eaab7d60eaea92426 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 6 Jun 2025 16:33:32 -0500 Subject: [PATCH 1/8] github: Add tests for setup-python and setup-poetry --- .github/workflows/test_actions.yml | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index cbe4154..060a267 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -5,6 +5,54 @@ on: workflow_dispatch: jobs: + test_setup_python: + name: Test setup-python + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + steps: + - name: Check out repo + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Python + uses: ./setup-python + with: + python-version: ${{ matrix.python-version }} + - name: Check Python version + run: | + import sys + version = sys.version_info[:2] + expected_version = tuple("${{ matrix.python-version }}".split(".")) + if version != expected_version: + print(f"::error title=Test Failure::The Python version does not match. Got {version}, expected {expected_version}.") + sys.exit(1) + shell: python + test_setup_poetry: + name: Test setup-poetry + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + steps: + - name: Check out repo + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Python + uses: ./setup-python + with: + python-version: ${{ matrix.python-version }} + - name: Set up Poetry + uses: ./setup-poetry + - name: Create project + run: poetry new test-project + - name: Check that the project was created + run: | + if [ ! -f test-project/pyproject.toml ]; then + echo "::error title=Test Failure::The project file does not exist." + exit 1 + fi + shell: bash test_check_project_version: name: Test check-project-version runs-on: ubuntu-latest From 9c487341092224a2e20b8e5acb9d54be5eebd132 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 6 Jun 2025 16:37:05 -0500 Subject: [PATCH 2/8] github: Fix version parsing --- .github/workflows/test_actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 060a267..2dddf9e 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -23,7 +23,7 @@ jobs: run: | import sys version = sys.version_info[:2] - expected_version = tuple("${{ matrix.python-version }}".split(".")) + expected_version = tuple(map(int, "${{ matrix.python-version }}".split("."))) if version != expected_version: print(f"::error title=Test Failure::The Python version does not match. Got {version}, expected {expected_version}.") sys.exit(1) From 786fcc6e3d337057012fd1d38e1e3fc6914f62ad Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 6 Jun 2025 16:47:33 -0500 Subject: [PATCH 3/8] github: Add another job to combine test results for status checks --- .github/workflows/test_actions.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 2dddf9e..3f8fac9 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -28,6 +28,7 @@ jobs: print(f"::error title=Test Failure::The Python version does not match. Got {version}, expected {expected_version}.") sys.exit(1) shell: python + test_setup_poetry: name: Test setup-poetry runs-on: ${{ matrix.os }} @@ -53,6 +54,7 @@ jobs: exit 1 fi shell: bash + test_check_project_version: name: Test check-project-version runs-on: ubuntu-latest @@ -86,6 +88,7 @@ jobs: run: | echo "::error title=Test Failure::The previous step did not fail as expected." exit 1 + test_update_project_version: name: Test update-project-version runs-on: ubuntu-latest @@ -132,3 +135,15 @@ jobs: with: project-directory: test-project expected-version: 1.0.2.dev1 + + # This job is intended to combine the test results so we don't have to list + # each matrix combination in the required status check settings. There are a + # lot of corner cases that make this harder than it should be; see See + # https://github.com/orgs/community/discussions/26822 for more info. + test_results: + name: Test Results + runs-on: ubuntu-latest + needs: [test_setup_python, test_setup_poetry, test_check_project_version, test_update_project_version] + if: ${{ !cancelled() }} + steps: + - run: exit 0 \ No newline at end of file From 0ec25937e95b441713b8340abde26e8f4a3fe982 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 6 Jun 2025 18:47:57 -0500 Subject: [PATCH 4/8] setup-poetry: Add use-cache input and cache-hit output --- setup-poetry/action.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/setup-poetry/action.yml b/setup-poetry/action.yml index 783e852..7362157 100644 --- a/setup-poetry/action.yml +++ b/setup-poetry/action.yml @@ -3,6 +3,17 @@ description: Install Poetry, add it to the PATH, and cache it to speed up workfl inputs: poetry-version: default: 1.8.2 + use-cache: + description: > + A Boolean specifying whether to use the cache. Set this to false to work + around caching problems. + default: true +outputs: + cache-hit: + description: > + A Boolean indicating whether Poetry was loaded from the cache. This is + mainly intended for testing the action. + value: ${{ steps.cache-poetry.outputs.cache-hit }} runs: using: composite steps: @@ -38,6 +49,7 @@ runs: echo "poetry-home=$POETRY_HOME" >> "$GITHUB_OUTPUT" shell: bash - name: Cache poetry + if: ${{ inputs.use-cache == 'true' }} id: cache-poetry uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 with: From 5c4800511798f611967fcff70224faab5530a1b0 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 6 Jun 2025 18:50:11 -0500 Subject: [PATCH 5/8] github: Add test for setup-poetry caching --- .github/workflows/test_actions.yml | 36 +++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 3f8fac9..73bbe88 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -55,6 +55,40 @@ jobs: fi shell: bash + test_setup_poetry_caching: + name: Test setup-poetry caching + runs-on: ${{ matrix.os }} + needs: test_setup_poetry + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + steps: + - name: Check out repo + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Python + uses: ./setup-python + with: + python-version: ${{ matrix.python-version }} + - name: Set up Poetry + id: setup-poetry + uses: ./setup-poetry + - name: Check that Poetry was loaded from the cache + if: steps.setup-poetry.outputs.cache-hit != 'true' + run: | + echo "::error title=Test Failure::The cache was not hit." + exit 1 + shell: bash + - name: Create project + run: poetry new test-project + - name: Check that the project was created + run: | + if [ ! -f test-project/pyproject.toml ]; then + echo "::error title=Test Failure::The project file does not exist." + exit 1 + fi + shell: bash + test_check_project_version: name: Test check-project-version runs-on: ubuntu-latest @@ -143,7 +177,7 @@ jobs: test_results: name: Test Results runs-on: ubuntu-latest - needs: [test_setup_python, test_setup_poetry, test_check_project_version, test_update_project_version] + needs: [test_setup_python, test_setup_poetry, test_setup_poetry_caching, test_check_project_version, test_update_project_version] if: ${{ !cancelled() }} steps: - run: exit 0 \ No newline at end of file From 07d0119deba315fa0d79b2097c7cf18333789773 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Fri, 6 Jun 2025 18:54:35 -0500 Subject: [PATCH 6/8] setup-poetry: Document new input and output --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index f069fbd..a4af285 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,9 @@ - [Usage](#usage-1) - [Inputs](#inputs-1) - [`poetry-version`](#poetry-version) + - [`use-cache`](#use-cache) + - [Outputs](#outputs-1) + - [`cache-hit`](#cache-hit) - [`ni/python-actions/check-project-version`](#nipython-actionscheck-project-version) - [Usage](#usage-2) - [Inputs](#inputs-2) @@ -125,6 +128,17 @@ steps: - run: poetry install -v ``` +#### `use-cache` + +If you run into caching problems, you can disable caching by specifying `use-cache: false`. + +### Outputs + +#### `cache-hit` + +You can use `cache-hit` to check whether Poetry was loaded from cache. This is mainly intended for +testing the action. + ## `ni/python-actions/check-project-version` The `check-project-version` action uses Poetry to get the version of a Python project and checks From 559b8a6c9a7596e1d4ad2f2f46edbefa00196f00 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Sat, 7 Jun 2025 12:36:47 -0500 Subject: [PATCH 7/8] github: Add a use_cache=false test --- .github/workflows/test_actions.yml | 51 ++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 73bbe88..47b186c 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -55,8 +55,8 @@ jobs: fi shell: bash - test_setup_poetry_caching: - name: Test setup-poetry caching + test_setup_poetry_cache_hit: + name: Test setup-poetry (cache hit) runs-on: ${{ matrix.os }} needs: test_setup_poetry strategy: @@ -73,11 +73,43 @@ jobs: - name: Set up Poetry id: setup-poetry uses: ./setup-poetry - - name: Check that Poetry was loaded from the cache + - name: Expect cache hit if: steps.setup-poetry.outputs.cache-hit != 'true' + run: echo "::error title=Test Failure::Expected cache hit."; exit 1 + shell: bash + - name: Create project + run: poetry new test-project + - name: Check that the project was created run: | - echo "::error title=Test Failure::The cache was not hit." - exit 1 + if [ ! -f test-project/pyproject.toml ]; then + echo "::error title=Test Failure::The project file does not exist." + exit 1 + fi + shell: bash + + test_setup_poetry_no_cache: + name: Test setup-poetry (no cache) + runs-on: ${{ matrix.os }} + needs: test_setup_poetry + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + python-version: [3.9, '3.10', 3.11, 3.12, 3.13] + steps: + - name: Check out repo + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Python + uses: ./setup-python + with: + python-version: ${{ matrix.python-version }} + - name: Set up Poetry + id: setup-poetry + uses: ./setup-poetry + with: + use-cache: false + - name: Expect cache miss + if: steps.setup-poetry.outputs.cache-hit == 'true' + run: echo "::error title=Test Failure::Expected cache miss."; exit 1 shell: bash - name: Create project run: poetry new test-project @@ -177,7 +209,14 @@ jobs: test_results: name: Test Results runs-on: ubuntu-latest - needs: [test_setup_python, test_setup_poetry, test_setup_poetry_caching, test_check_project_version, test_update_project_version] + needs: [ + test_setup_python, + test_setup_poetry, + test_setup_poetry_cache_hit, + test_setup_poetry_no_cache, + test_check_project_version, + test_update_project_version + ] if: ${{ !cancelled() }} steps: - run: exit 0 \ No newline at end of file From a04989872859a4830f8cc02802946bb1a8e2d890 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Sat, 7 Jun 2025 12:41:19 -0500 Subject: [PATCH 8/8] github: Change conditional step names to reflect result of condition, not the check --- .github/workflows/test_actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_actions.yml b/.github/workflows/test_actions.yml index 47b186c..4127ebb 100644 --- a/.github/workflows/test_actions.yml +++ b/.github/workflows/test_actions.yml @@ -73,7 +73,7 @@ jobs: - name: Set up Poetry id: setup-poetry uses: ./setup-poetry - - name: Expect cache hit + - name: Error if cache miss if: steps.setup-poetry.outputs.cache-hit != 'true' run: echo "::error title=Test Failure::Expected cache hit."; exit 1 shell: bash @@ -107,7 +107,7 @@ jobs: uses: ./setup-poetry with: use-cache: false - - name: Expect cache miss + - name: Error if cache hit if: steps.setup-poetry.outputs.cache-hit == 'true' run: echo "::error title=Test Failure::Expected cache miss."; exit 1 shell: bash