Skip to content

Commit

Permalink
[PAN-1889] Matrix of Python versions (#9)
Browse files Browse the repository at this point in the history
* feat: added python version matrix

---------

Signed-off-by: Juan M. Tirado <[email protected]>
  • Loading branch information
juanmanuel-tirado authored May 16, 2024
1 parent 859cf06 commit 99cb7ff
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
24 changes: 12 additions & 12 deletions .github/actions/install-poetry/action.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
name: 'Install dependencies'
description: 'Set up Python and install Poetry'

inputs:
python-version:
required: true
description: "Python version to use"
runner-os:
required: true
description: "OS used by the runner"


runs:
using: composite
steps:
- uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
files.pythonhosted.org:443
github.com:443
install.python-poetry.org:443
pypi.org:443
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: ${{ inputs.python-version }}

- name: Load cached Poetry installation
id: cached-poetry
Expand All @@ -26,7 +25,7 @@ runs:
path: |
~/.local
~/.config
key: poetry-0
key: poetry-${{ inputs.runner-os }}-${{ inputs.python-version }}

- name: Install Poetry
if: steps.cached-poetry.outputs.cache-hit != 'true'
Expand All @@ -35,3 +34,4 @@ runs:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

25 changes: 13 additions & 12 deletions .github/actions/install-python-deps/action.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
name: 'Install dependencies'
description: 'Install Python library dependencies using Poetry'

inputs:
python-version:
required: true
description: "Python version to use"
runner-os:
required: true
description: "OS used by the runner"

runs:
using: composite
steps:
- uses: step-security/harden-runner@v2
- uses: pantos-io/ci-workflows/.github/actions/install-poetry@v1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
files.pythonhosted.org:443
github.com:443
install.python-poetry.org:443
pypi.org:443
python-version: ${{ inputs.python-version }}
runner-os: ${{ inputs.runner-os }}

- uses: pantos-io/ci-workflows/.github/actions/install-poetry@v1

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
path: ~/.venv
key: venv-${{ inputs.runner-os }}-${{ inputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
shell: bash
Expand Down
27 changes: 19 additions & 8 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ jobs:
run: make bandit

UnitTest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}
name: Unit test for Python ${{ matrix.python-version }} on ${{ matrix.os }}
services:
postgres:
image: ${{ (inputs.test-database) && 'postgres:latest' || '' }}
Expand All @@ -171,27 +177,32 @@ jobs:
with:
submodules: recursive
token: ${{ secrets.GH_TOKEN || github.token }}

- uses: pantos-io/ci-workflows/.github/actions/install-python-deps@v1
with:
python-version: ${{ matrix.python-version }}
runner-os: ${{ matrix.os }}

- name: UnitTest
env:
PYTHON_VERSION: '${{ matrix.python-version }}'
run: |
make coverage
poetry run coverage xml
poetry run coverage xml -o coverage-${{ matrix.python-version }}.xml
- uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: coverage.xml
name: code-coverage-report-${{ matrix.python-version }}
path: coverage-${{ matrix.python-version }}.xml

- name: PostgresUnitTest
if: ${{ inputs.test-database }}
run: |
make coverage-postgres
poetry run coverage xml -o postgres-coverage.xml
poetry run coverage xml -o postgres-${{ matrix.python-version }}.xml
- uses: actions/upload-artifact@v4
if: ${{ inputs.test-database }}
with:
name: code-coverage-postgres-report
path: postgres-coverage.xml
name: code-coverage-postgres-report-${{ matrix.python-version }}
path: postgres-coverage-${{ matrix.python-version }}.xml
9 changes: 7 additions & 2 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ permissions:
repository-projects: read
statuses: read
jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-22.04]
sonar:
name: Sonar
runs-on: ubuntu-latest
Expand Down Expand Up @@ -44,14 +49,14 @@ jobs:
- name: Download artifact from CI workflow
uses: actions/download-artifact@v4
with:
name: code-coverage-report
name: code-coverage-report-${{ matrix.python-version }}
github-token: ${{ github.token }}
repository: ${{ github.repository }}
run-id: ${{ steps.get-run-id.outputs.run-id }}
- uses: actions/download-artifact@v4
if: ${{ inputs.test-database }}
with:
name: code-coverage-postgres-report
name: code-coverage-postgres-report-${{ matrix.python-version }}
github-token: ${{ github.token }}
repository: ${{ github.repository }}
run-id: ${{ steps.get-run-id.outputs.run-id }}
Expand Down

0 comments on commit 99cb7ff

Please sign in to comment.