From dd7c35ea510d0e6839186ce8a33b2f1b8ba710ab Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 18:48:36 +0200 Subject: [PATCH 1/8] ci: Rename pre-commit workflow --- .github/workflows/pre-commit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 72eadf7..6c38da0 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -5,7 +5,7 @@ on: push: jobs: - deploy: + check: runs-on: ubuntu-latest steps: From bf7e3e43607aaa7d3840685b8acd711d8956b6bd Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 19:01:58 +0200 Subject: [PATCH 2/8] ci: Use common setup workflow --- .github/actions/setup-project/action.yml | 33 ++++++++++++++++++++++++ .github/workflows/docs.yml | 13 +++------- .github/workflows/pre-commit.yml | 13 +++------- .github/workflows/publish.yml | 12 +++------ .github/workflows/test.yml | 27 +++++-------------- 5 files changed, 48 insertions(+), 50 deletions(-) create mode 100644 .github/actions/setup-project/action.yml diff --git a/.github/actions/setup-project/action.yml b/.github/actions/setup-project/action.yml new file mode 100644 index 0000000..cdc21c0 --- /dev/null +++ b/.github/actions/setup-project/action.yml @@ -0,0 +1,33 @@ +name: Common Python + Poetry Setup + +inputs: + dependency-groups: + description: 'A comma-separated list of dependency groups to install' + default: 'main' + python-version: + description: 'The Python version to use' + default: '3.10' + +runs: + using: 'composite' + + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Load cached venv + id: cache-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: venv-${{ runner.os }}-python-${{ inputs.python-version }}-groups-${{ inputs.dependency-groups }}-lock-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cache-dependencies.outputs.cache-hit != 'true' + shell: bash + run: | + python -m pip install poetry + poetry config virtualenvs.in-project true + poetry install --with ${{ inputs.dependency-groups }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8e32a23..2066d1e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -16,17 +16,10 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 + + - uses: './.github/actions/setup-project' with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev + dependency-groups: 'docs' - name: Build documentation run: | diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 6c38da0..1498bc6 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -10,17 +10,10 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.10' - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev,test + - uses: './.github/actions/setup-project' + with: + dependency-groups: 'dev,test' - uses: pre-commit/action@v3.0.1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2812c62..162d774 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,16 +15,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + + - uses: './.github/actions/setup-project' with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev + dependency-groups: 'dev' - name: Prepare README run: ./scripts/refactor_readme.py README.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7a0215..8233c3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,17 +13,10 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 + + - uses: './.github/actions/setup-project' with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with dev + dependency-groups: 'dev' - id: supported-versions name: Get supported versions @@ -40,18 +33,10 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - uses: './.github/actions/setup-project' with: - python-version: "${{ matrix.py-version }}" - - - name: Install dependencies - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - - # Only install main dependencies - poetry install --with test + python-version: ${{ matrix.py-version }} + dependency-groups: 'test' - name: Run unit tests run: poetry run pytest From 9104d5543a8b145dbd367a0a07d686e1d9a715ae Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 19:29:51 +0200 Subject: [PATCH 3/8] ci: Fix cache key --- .github/actions/setup-project/action.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-project/action.yml b/.github/actions/setup-project/action.yml index cdc21c0..f2b3158 100644 --- a/.github/actions/setup-project/action.yml +++ b/.github/actions/setup-project/action.yml @@ -17,12 +17,19 @@ runs: with: python-version: ${{ inputs.python-version }} + - name: Get cache key + id: cache-key + shell: bash + run: | + key=$(echo "${{ inputs.dependency-groups }}" | sed 's/,/+/') + echo "key=$key" >> "$GITHUB_OUTPUT" + - name: Load cached venv id: cache-dependencies uses: actions/cache@v4 with: path: .venv - key: venv-${{ runner.os }}-python-${{ inputs.python-version }}-groups-${{ inputs.dependency-groups }}-lock-${{ hashFiles('**/poetry.lock') }} + key: venv-${{ runner.os }}-python-${{ inputs.python-version }}-groups-${{ steps.cache-key.outputs.key }}-${{ hashFiles('**/poetry.lock') }} - name: Install dependencies if: steps.cache-dependencies.outputs.cache-hit != 'true' From 48965e725f3257d202de557bfff286c9a3a4e791 Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 19:38:51 +0200 Subject: [PATCH 4/8] ci: Fail tests if version discovery fails --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8233c3d..a4d9263 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,9 @@ jobs: - id: supported-versions name: Get supported versions - run: echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" + run: | + set -e + echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" test: runs-on: ubuntu-latest From 5d0513f2505905ddaa5cf6e0023fbd9081cfabcb Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 19:46:29 +0200 Subject: [PATCH 5/8] ci: Fail tests if version discovery fails --- .github/workflows/test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a4d9263..8233c3d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,9 +20,7 @@ jobs: - id: supported-versions name: Get supported versions - run: | - set -e - echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" + run: echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" test: runs-on: ubuntu-latest From 0cd073f4ee41e8c1adb0409bc9c0d1e54df3c25e Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 19:48:09 +0200 Subject: [PATCH 6/8] ci: Install poetry even on cache hit --- .github/actions/setup-project/action.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup-project/action.yml b/.github/actions/setup-project/action.yml index f2b3158..4dfb260 100644 --- a/.github/actions/setup-project/action.yml +++ b/.github/actions/setup-project/action.yml @@ -17,6 +17,12 @@ runs: with: python-version: ${{ inputs.python-version }} + - name: Install poetry + shell: bash + run: | + python -m pip install poetry + poetry config virtualenvs.in-project true + - name: Get cache key id: cache-key shell: bash @@ -34,7 +40,4 @@ runs: - name: Install dependencies if: steps.cache-dependencies.outputs.cache-hit != 'true' shell: bash - run: | - python -m pip install poetry - poetry config virtualenvs.in-project true - poetry install --with ${{ inputs.dependency-groups }} + run: poetry install --with ${{ inputs.dependency-groups }} From abad1c037c427986e44e3bb757364c94e375efb0 Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 19:50:15 +0200 Subject: [PATCH 7/8] Revert "ci: Fail tests if version discovery fails" This reverts commit 5d0513f2505905ddaa5cf6e0023fbd9081cfabcb. --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8233c3d..a4d9263 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,9 @@ jobs: - id: supported-versions name: Get supported versions - run: echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" + run: | + set -e + echo "py-versions=$(poetry run ./scripts/supported_py_versions.py)" >> "$GITHUB_OUTPUT" test: runs-on: ubuntu-latest From 886b78c82c4df283072cf9d7cf676d70e30ee53a Mon Sep 17 00:00:00 2001 From: "Mike A." Date: Tue, 3 Sep 2024 19:59:48 +0200 Subject: [PATCH 8/8] ci: Add test result collection job --- .github/workflows/test.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a4d9263..6869e20 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,3 +42,15 @@ jobs: - name: Run unit tests run: poetry run pytest + + results: + runs-on: ubuntu-latest + needs: test + steps: + - run: | + result="${{ needs.test.result }}" + if [[ $result == "success" || $result == "skipped" ]]; then + exit 0 + else + exit 1 + fi