diff --git a/.github/workflows/python-linting.yml b/.github/workflows/python-linting.yml index 58cc331..592d8bd 100644 --- a/.github/workflows/python-linting.yml +++ b/.github/workflows/python-linting.yml @@ -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 . \ No newline at end of file + 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 . \ No newline at end of file