|
| 1 | +name: Reusable Python Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + python-version: |
| 7 | + description: Python version to use |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: '3.11' |
| 11 | + install-system-deps: |
| 12 | + description: Install Linux system dependencies and unlock keyring |
| 13 | + required: false |
| 14 | + type: boolean |
| 15 | + default: true |
| 16 | + install-extras: |
| 17 | + description: Optional extras to install from pyproject (for example test,typing) |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + default: '' |
| 21 | + extra-packages: |
| 22 | + description: Optional extra packages to install with uv pip |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + default: '' |
| 26 | + run-tests: |
| 27 | + description: Run tests |
| 28 | + required: false |
| 29 | + type: boolean |
| 30 | + default: false |
| 31 | + test-command: |
| 32 | + description: Test command to run when run-tests=true |
| 33 | + required: false |
| 34 | + type: string |
| 35 | + default: 'pytest -q' |
| 36 | + run-mypy: |
| 37 | + description: Run mypy |
| 38 | + required: false |
| 39 | + type: boolean |
| 40 | + default: false |
| 41 | + mypy-target: |
| 42 | + description: Package/module path to type-check |
| 43 | + required: false |
| 44 | + type: string |
| 45 | + default: '' |
| 46 | + run-pre-commit: |
| 47 | + description: Run pre-commit |
| 48 | + required: false |
| 49 | + type: boolean |
| 50 | + default: false |
| 51 | + |
| 52 | +jobs: |
| 53 | + python-checks: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + |
| 56 | + steps: |
| 57 | + - name: Install system dependencies |
| 58 | + if: inputs.install-system-deps |
| 59 | + run: | |
| 60 | + sudo apt-get update |
| 61 | + sudo apt-get install -y libdbus-1-3 libdbus-1-dev libglib2.0-dev |
| 62 | +
|
| 63 | + - name: Checkout |
| 64 | + uses: actions/checkout@v6 |
| 65 | + |
| 66 | + - name: Setup UV |
| 67 | + uses: astral-sh/setup-uv@v7 |
| 68 | + with: |
| 69 | + version: latest |
| 70 | + python-version: ${{ inputs.python-version }} |
| 71 | + activate-environment: true |
| 72 | + |
| 73 | + - name: Install dependencies |
| 74 | + run: | |
| 75 | + uv pip install . |
| 76 | + if [[ -n "${{ inputs.install-extras }}" ]]; then |
| 77 | + uv pip install ".[${{ inputs.install-extras }}]" |
| 78 | + fi |
| 79 | + if [[ -n "${{ inputs.extra-packages }}" ]]; then |
| 80 | + uv pip install ${{ inputs.extra-packages }} |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Unlock keyring |
| 84 | + if: inputs.install-system-deps |
| 85 | + uses: t1m0thyj/unlock-keyring@v1 |
| 86 | + |
| 87 | + - name: Configure git to use https |
| 88 | + run: git config --global hub.protocol https |
| 89 | + |
| 90 | + - name: Run tests |
| 91 | + if: inputs.run-tests |
| 92 | + run: ${{ inputs.test-command }} |
| 93 | + |
| 94 | + - name: Run mypy |
| 95 | + if: inputs.run-mypy |
| 96 | + run: mypy ${{ inputs.mypy-target }} |
| 97 | + |
| 98 | + - name: Run pre-commit |
| 99 | + if: inputs.run-pre-commit |
| 100 | + run: pre-commit run --all-files |
0 commit comments