Skip to content

Commit

Permalink
Make it OS agnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Dec 27, 2024
1 parent fb2b906 commit 96956f4
Showing 1 changed file with 52 additions and 40 deletions.
92 changes: 52 additions & 40 deletions .github/workflows/python-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,65 @@ on:
workflow_call:
inputs:
runs-on:
type: string
description: 'The type of runner that the job will run on'
required: true
required: false
default: 'windows-latest'

jobs:
linters:
setup-matrix:
runs-on: ${{ inputs.runs-on }}

outputs:
python-versions: ${{ steps.set-matrix.outputs.versions }}
steps:
- uses: actions/checkout@v4

- name: Read Python versions
id: read-python-versions
id: set-matrix
run: |
if [ ! -f .python-version ]; then
echo ".python-version file not found"
exit 1
if [[ "$RUNNER_OS" == "Windows" ]]; then
# Windows: Use PowerShell to read the file
if (-Not (Test-Path ".python-version")) {
Write-Error ".python-version file not found"
exit 1
}
$pythonVersions = Get-Content .python-version -Raw | -split ','
$matrixOutput = $pythonVersions | ForEach-Object { $_.Trim() }
$jsonOutput = $matrixOutput -join '","'
$jsonOutput = "[\"$jsonOutput\"]"
echo "::set-output name=versions::$jsonOutput"
else
# Linux/macOS: Use Bash to read the file
if [ ! -f .python-version ]; then
echo ".python-version file not found"
exit 1
fi
PYTHON_VERSIONS=$(cat .python-version | tr ',' '\n' | xargs)
echo "::set-output name=versions::$(echo \"$PYTHON_VERSIONS\" | jq -R 'split(\" \")')"
fi
PYTHON_VERSIONS=$(cat .python-version | tr ',' '\n' | xargs)
echo "PYTHON_VERSIONS=$PYTHON_VERSIONS" >> $GITHUB_ENV
echo "::set-output name=versions::$(echo $PYTHON_VERSIONS | jq -R 'split(" ")')"
- name: Set up matrix dynamically
uses: actions/github-script@v6
with:
script: |
const versions = process.env.PYTHON_VERSIONS.split(" ");
return { python: versions };
- name: Run tests on matrix
strategy:
matrix:
python-version: ${{ fromJSON(steps.read-python-versions.outputs.versions) }}
fail-fast: false
name: Run tests on Python ${{ matrix.python-version }}

steps:
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync --extra dev
- name: Run ruff format
run: uv run ruff format . --config .\pyproject.toml
- name: Run ruff check
run: uv run ruff check . --config .\pyproject.toml
- name: Run codespell
run: uv run codespell .
shell: bash

linters:
needs: setup-matrix
runs-on: ${{ inputs.runs-on }}
strategy:
matrix:
python-version: ${{ fromJSON(needs.setup-matrix.outputs.python-versions) }}
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: uv sync --extra dev

- name: Run ruff format
run: uv run ruff format . --config .\pyproject.toml

- name: Run ruff check
run: uv run ruff check . --config .\pyproject.toml

- name: Run codespell
run: uv run codespell .

0 comments on commit 96956f4

Please sign in to comment.