initial commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
name: Python Code Quality 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: "."
|
||||
skip-mypy:
|
||||
description: 'Skip mypy type checking'
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
skip-pyupgrade:
|
||||
description: 'Skip pyupgrade check'
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
uv-extras:
|
||||
description: 'UV extras to install (e.g., "dev,test")'
|
||||
required: false
|
||||
type: string
|
||||
default: "all-extras"
|
||||
|
||||
jobs:
|
||||
code-quality:
|
||||
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: Type check with mypy
|
||||
if: ${{ !inputs.skip-mypy }}
|
||||
run: uv run mypy .
|
||||
|
||||
- name: Ruff lint
|
||||
run: uv run ruff check .
|
||||
|
||||
- name: Ruff format
|
||||
run: uv run ruff format --check .
|
||||
|
||||
- name: Pyupgrade check
|
||||
if: ${{ !inputs.skip-pyupgrade }}
|
||||
run: uv run pyupgrade --py312-plus $(git ls-files '*.py') && git diff --exit-code
|
||||
@@ -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
|
||||
@@ -0,0 +1,87 @@
|
||||
name: Web/General Formatting Pipeline
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
working-directory:
|
||||
description: 'Working directory for the project'
|
||||
required: false
|
||||
type: string
|
||||
default: "."
|
||||
node-version:
|
||||
description: 'Node.js version to use for prettier (e.g., "20")'
|
||||
required: false
|
||||
type: string
|
||||
default: "20"
|
||||
skip-prettier:
|
||||
description: 'Skip prettier formatting check'
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
prettier-config:
|
||||
description: 'Path to prettier config file (optional)'
|
||||
required: false
|
||||
type: string
|
||||
default: ""
|
||||
check-yaml:
|
||||
description: 'Check YAML files with yamllint'
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
check-json:
|
||||
description: 'Check JSON files for validity'
|
||||
required: false
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
jobs:
|
||||
formatting:
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Node.js
|
||||
if: ${{ !inputs.skip-prettier }}
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: ${{ inputs.node-version }}
|
||||
|
||||
- name: Install prettier
|
||||
if: ${{ !inputs.skip-prettier }}
|
||||
run: npm install --save-dev --save-exact prettier
|
||||
|
||||
- name: Run prettier check
|
||||
if: ${{ !inputs.skip-prettier }}
|
||||
run: |
|
||||
if [ -n "${{ inputs.prettier-config }}" ]; then
|
||||
npx prettier --check . --config ${{ inputs.prettier-config }}
|
||||
else
|
||||
npx prettier --check .
|
||||
fi
|
||||
|
||||
- name: Set up Python for YAML linting
|
||||
if: ${{ inputs.check-yaml }}
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install yamllint
|
||||
if: ${{ inputs.check-yaml }}
|
||||
run: pip install yamllint
|
||||
|
||||
- name: Check YAML files
|
||||
if: ${{ inputs.check-yaml }}
|
||||
run: yamllint .
|
||||
|
||||
- name: Check JSON files
|
||||
if: ${{ inputs.check-json }}
|
||||
run: |
|
||||
find . -name "*.json" -type f | while read -r file; do
|
||||
echo "Checking $file"
|
||||
python -m json.tool "$file" > /dev/null
|
||||
done
|
||||
Reference in New Issue
Block a user