Build the Gitea API payload with json.dumps so multiline coverage output is valid JSON, and fail the step when the API rejects the request. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.6 KiB
YAML
60 lines
1.6 KiB
YAML
name: Test Python Package
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version-file: .python-version
|
|
|
|
- name: Install uv
|
|
run: pip install uv
|
|
|
|
- name: Install dependencies
|
|
env:
|
|
UV_LINK_MODE: copy
|
|
run: uv sync --all-extras
|
|
|
|
- name: Run pytest
|
|
env:
|
|
PYTHONPATH: .
|
|
run: uv run pytest --cov=python_repositories --cov-report=term-missing > coverage.txt
|
|
|
|
- name: Post coverage summary to PR
|
|
if: github.event_name == 'pull_request'
|
|
env:
|
|
API_URL: ${{ vars.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: |
|
|
PAYLOAD=$(python3 -c '
|
|
import json
|
|
import pathlib
|
|
|
|
coverage = pathlib.Path("coverage.txt").read_text()
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"body": f"**Test Coverage Report:**\n```\n{coverage}\n```",
|
|
}
|
|
)
|
|
)
|
|
')
|
|
curl -sf -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 "$PAYLOAD"
|