Skip to content

knoepfel checking Python code #102

knoepfel checking Python code

knoepfel checking Python code #102

Workflow file for this run

name: Python Check
run-name: "${{ github.actor }} checking Python code"
permissions:
contents: read
pull-requests: read
on:
pull_request:
branches: [ main, develop ]
workflow_dispatch:
jobs:
pre-check:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.detect_act.outputs.is_act }}
steps:
- name: Detect act environment
id: detect_act
uses: Framework-R-D/phlex/.github/actions/detect-act-env@main
detect-changes:
needs: pre-check
if: github.event_name != 'workflow_dispatch' && needs.pre-check.outputs.is_act != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
outputs:
has_changes: ${{ steps.filter.outputs.matched }}
steps:
- name: Checkout code
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
fetch-depth: 0
path: phlex-src
- name: Detect Python changes
id: filter
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
with:
repo-path: phlex-src
base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
head-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
file-type: python
- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No python check relevant changes detected; job will be skipped."
else
echo "::group::Python check relevant files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi
python-check:
needs: [pre-check, detect-changes]
if: >
github.event_name == 'workflow_dispatch' ||
needs.pre-check.outputs.is_act == 'true' ||
(needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes == 'true')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
path: phlex-src
- name: Set up Python
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
with:
python-version: '3.x'
- name: Install Python dependencies
run: |
pip install ruff mypy
- name: Run ruff and mypy checks
working-directory: phlex-src
env:
FORCE_COLOR: 1 # `ruff`/`colored` crate
run: |
failed=0
echo "➡️ Checking Python code with ruff..."
echo "::group::Running ruff check"
if ! ruff check; then
failed=1
echo "::endgroup::"
echo "::error:: Ruff check failed."
else
echo "::endgroup::"
echo "✅ Ruff check passed."
fi
echo "➡️ Checking Python code with mypy..."
echo "::group::Running mypy"
if ! mypy --color-output .; then
failed=1
echo "::endgroup::"
echo "::error:: MyPy check failed."
else
echo "::endgroup::"
echo "✅ MyPy check passed."
fi
exit $failed
python-check-skipped:
needs: [pre-check, detect-changes]
if: >
github.event_name != 'workflow_dispatch' &&
needs.pre-check.outputs.is_act != 'true' &&
needs.detect-changes.result == 'success' &&
needs.detect-changes.outputs.has_changes != 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: No relevant Python changes detected
run: echo "No Python relevant changes detected; check skipped."