From a072a6ff87ac9254262e93896bf26aaa634cbacd Mon Sep 17 00:00:00 2001 From: Scott Numamoto Date: Fri, 3 Oct 2025 13:11:35 -0700 Subject: [PATCH] Add GitHub actions for Python --- .github/workflows/python-ci.yml | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 .github/workflows/python-ci.yml diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..49d73d3 --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,101 @@ +name: Python CI +permissions: + contents: read + +on: + push: + branches: [ main ] + paths: + - 'python/**' + - '.github/workflows/python-ci.yml' + pull_request: + paths: + - 'python/**' + - '.github/workflows/python-ci.yml' + +defaults: + run: + working-directory: ./python + +jobs: + lint-and-format: + name: Lint and Format Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.13 + uses: actions/setup-python@v5 + with: + python-version: '3.13' + + - name: Install Poetry + uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a + with: + version: latest + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: ./python/.venv + key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root + + - name: Install project + run: poetry install --no-interaction + + - name: Run formatting check with tox + run: poetry run tox -e format + + - name: Run linting with tox + run: poetry run tox -e lint + + test: + name: Test Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ['3.10', '3.11', '3.12', '3.13'] + # Note: Python 3.14 is not yet available in GitHub Actions + # Will be added when it becomes available + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Poetry + uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a + with: + version: latest + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: ./python/.venv + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root + + - name: Install project + run: poetry install --no-interaction + + - name: Run tests with tox + run: poetry run tox -e py$(echo ${{ matrix.python-version }} | tr -d '.')