initial commit

This commit is contained in:
Brian Bjarke Jensen
2025-09-19 19:20:47 +02:00
parent a481796d07
commit 0abd398c10
8 changed files with 956 additions and 2 deletions
+101
View File
@@ -0,0 +1,101 @@
name: Python Test Pipeline
on:
workflow_call:
inputs:
python-version:
description: 'Python version to use (e.g., "3.12")'
required: false
type: string
default: "3.12"
working-directory:
description: 'Working directory for the project'
required: false
type: string
default: "."
uv-extras:
description: 'UV extras to install (e.g., "dev,test")'
required: false
type: string
default: "all-extras"
pytest-args:
description: 'Additional arguments to pass to pytest'
required: false
type: string
default: ""
coverage-package:
description: 'Package name for coverage reporting (e.g., "my_package")'
required: false
type: string
default: ""
skip-coverage-comment:
description: 'Skip posting coverage comment to PR'
required: false
type: boolean
default: false
api-url:
description: 'Gitea API URL for posting comments'
required: false
type: string
default: ""
secrets:
CI_RUNNER_TOKEN:
description: 'Token for posting PR comments'
required: false
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Install uv
run: pip install uv
- name: Install dependencies
env:
UV_LINK_MODE: copy
run: |
if [ "${{ inputs.uv-extras }}" = "all-extras" ]; then
uv sync --all-extras
else
uv sync --extra ${{ inputs.uv-extras }}
fi
- name: Run pytest
env:
PYTHONPATH: .
run: |
if [ -n "${{ inputs.coverage-package }}" ]; then
uv run pytest --cov=${{ inputs.coverage-package }} --cov-report=term-missing ${{ inputs.pytest-args }} > coverage.txt
else
uv run pytest ${{ inputs.pytest-args }}
fi
- name: Post coverage summary to PR
if: ${{ !inputs.skip-coverage-comment && inputs.coverage-package != '' && github.event_name == 'pull_request' && inputs.api-url != '' }}
env:
API_URL: ${{ inputs.api-url }}
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
CI_RUNNER_TOKEN: ${{ secrets.CI_RUNNER_TOKEN }}
run: |
if [ -f coverage.txt ]; then
COVERAGE=$(cat coverage.txt)
COMMENT_BODY="**Test Coverage Report:**\n\`\`\`\n$COVERAGE\n\`\`\`"
curl -s -X POST "$API_URL/repos/$REPO_OWNER/$REPO_NAME/issues/$PR_NUMBER/comments" \
-H "Authorization: token $CI_RUNNER_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"body\": \"$COMMENT_BODY\"}"
fi