Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 69 additions & 5 deletions .github/workflows/template-security-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
templates = []
total_vulnerabilities = 0
affected_templates = []
failed_templates = []

for name in template_names:
audit_file = os.path.join(temp_dir, f"{name}.json")
Expand Down Expand Up @@ -119,13 +120,24 @@ jobs:
else:
print(f"❌ pip-audit failed for {name}: {entry['error']}")

if "error" in entry:
failed_templates.append(name)

templates.append(entry)

scan_total = len(template_names)
failed_count = len(failed_templates)
scanned_ok = scan_total - failed_count

results = {
"scan_date": scan_date,
"templates": templates,
"total_vulnerabilities": total_vulnerabilities,
"affected_templates": " ".join(affected_templates),
"scan_total": scan_total,
"scanned_ok": scanned_ok,
"failed_count": failed_count,
"failed_templates": " ".join(failed_templates),
}

with open(results_file, "w") as rf:
Expand All @@ -136,6 +148,10 @@ jobs:
with open(github_output, "a") as gh:
gh.write(f"total_vulnerabilities={total_vulnerabilities}\n")
gh.write(f"affected_templates={' '.join(affected_templates)}\n")
gh.write(f"scan_total={scan_total}\n")
gh.write(f"scanned_ok={scanned_ok}\n")
gh.write(f"failed_count={failed_count}\n")
gh.write(f"failed_templates={' '.join(failed_templates)}\n")
PYEOF

- name: Upload scan results
Expand All @@ -160,6 +176,11 @@ jobs:
try {
const results = JSON.parse(fs.readFileSync('security_scan_results.json', 'utf8'));

issueBody += `**Scanned:** ${results.scanned_ok}/${results.scan_total} templates\n\n`;
if (results.failed_count > 0) {
issueBody += `> ⚠️ **Incomplete scan:** pip-audit failed for ${results.failed_count} template(s): ${results.failed_templates}\n\n`;
}

results.templates.forEach(template => {
if (template.error) {
issueBody += `### ❌ ${template.template}\n\n`;
Expand Down Expand Up @@ -215,16 +236,59 @@ jobs:

- name: Report Summary
if: always()
env:
TOTAL_VULNERABILITIES: ${{ steps.scan.outputs.total_vulnerabilities }}
AFFECTED_TEMPLATES: ${{ steps.scan.outputs.affected_templates }}
SCAN_TOTAL: ${{ steps.scan.outputs.scan_total }}
SCANNED_OK: ${{ steps.scan.outputs.scanned_ok }}
FAILED_TEMPLATES: ${{ steps.scan.outputs.failed_templates }}
run: |
echo "## 🔒 Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Scanned: ${SCANNED_OK:-0}/${SCAN_TOTAL:-0} templates" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

if [ -z "$SCAN_TOTAL" ] || [ "$SCAN_TOTAL" = "0" ]; then
echo "❌ **No templates were scanned (scan did not run or no templates were discovered). The result is incomplete.**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
elif [ "$SCANNED_OK" != "$SCAN_TOTAL" ]; then
echo "❌ **Some scans failed, so the result is incomplete.**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Failed templates: $FAILED_TEMPLATES" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi

if [ "${{ steps.scan.outputs.total_vulnerabilities }}" = "0" ]; then
echo "✅ **No vulnerabilities found in any template!**" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ **Found ${{ steps.scan.outputs.total_vulnerabilities }} vulnerabilities**" >> $GITHUB_STEP_SUMMARY
if [ "$TOTAL_VULNERABILITIES" = "0" ]; then
if [ -n "$SCAN_TOTAL" ] && [ "$SCAN_TOTAL" != "0" ] && [ "$SCANNED_OK" = "$SCAN_TOTAL" ]; then
echo "✅ **No vulnerabilities found in any template!**" >> $GITHUB_STEP_SUMMARY
else
echo "No vulnerabilities found in the templates that were scanned." >> $GITHUB_STEP_SUMMARY
fi
elif [ -n "$TOTAL_VULNERABILITIES" ]; then
echo "⚠️ **Found $TOTAL_VULNERABILITIES vulnerabilities**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Affected templates: ${{ steps.scan.outputs.affected_templates }}" >> $GITHUB_STEP_SUMMARY
echo "Affected templates: $AFFECTED_TEMPLATES" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "A GitHub Issue has been created with detailed information." >> $GITHUB_STEP_SUMMARY
fi

- name: Fail if any scan did not complete
if: always()
env:
SCAN_OUTCOME: ${{ steps.scan.outcome }}
SCAN_TOTAL: ${{ steps.scan.outputs.scan_total }}
SCANNED_OK: ${{ steps.scan.outputs.scanned_ok }}
FAILED_TEMPLATES: ${{ steps.scan.outputs.failed_templates }}
run: |
if [ "$SCAN_OUTCOME" != "success" ]; then
echo "::error::Scan step did not complete successfully (outcome: $SCAN_OUTCOME)"
exit 1
fi
if [ -z "$SCAN_TOTAL" ] || [ "$SCAN_TOTAL" = "0" ]; then
echo "::error::No templates were discovered to scan"
exit 1
fi
if [ "$SCANNED_OK" != "$SCAN_TOTAL" ]; then
echo "::error::Scan incomplete ($SCANNED_OK/$SCAN_TOTAL). Failed templates: $FAILED_TEMPLATES"
exit 1
fi
78 changes: 75 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,32 @@ on:

jobs:
test-fastapi-fastkit-sources:
runs-on: ubuntu-latest
name: test (${{ matrix.os }}, py${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
python-version:
- "3.12" # the only supported version (requires-python = ">=3.12")
- "3.12" # the oldest supported version (requires-python = ">=3.12")
- "3.13"
- "3.14"
fail-fast: false
include:
# Windows: the oldest and the newest supported Python.
- os: windows-latest
python-version: "3.12"
- os: windows-latest
python-version: "3.14"
defaults:
run:
shell: bash
env:
# Hard links from the uv cache fail across drives on Windows runners.
UV_LINK_MODE: copy
# PYTHONUTF8 / PYTHONIOENCODING are deliberately not set: the Windows
# runner's cp1252 console is part of what these jobs test.
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -40,14 +58,68 @@ jobs:
run: pdm install -G dev

- name: Run tests with coverage
if: runner.os == 'Linux'
run: |
pdm run pytest --cov=src/fastapi_fastkit --cov-report=term-missing --cov-report=xml --cov-fail-under=70

- name: Run tests
if: runner.os != 'Linux'
run: pdm run pytest

- name: Upload coverage to Codecov
if: runner.os == 'Linux'
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

# Windows runners use cp1252; this job covers what they cannot: implicit
# locale encodings (EncodingWarning) and a non-UTF-8 C locale, which is how
# cp949 / cp932 / cp936 machines read files that lack an explicit encoding.
encoding-guard:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
UV_LINK_MODE: copy
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Setup PDM
uses: pdm-project/setup-pdm@v4

- name: Install package managers for tests
run: |
pip install uv
pip install poetry

- name: Install dependencies
run: pdm install -G dev

- name: Fail on implicit text encodings in fastapi_fastkit
env:
PYTHONWARNDEFAULTENCODING: "1"
# An ini-style filter (-o) matches the module as a prefix, so it
# covers every fastapi_fastkit submodule; -W would only match the
# top-level package name exactly.
run: |
pdm run pytest -q -o "filterwarnings=error::EncodingWarning:fastapi_fastkit"

- name: Run tests under a non-UTF-8 C locale
env:
LC_ALL: C
LANG: C
PYTHONCOERCECLOCALE: "0"
PYTHONUTF8: "0"
# Keeps pytest's own output readable; file reads still use the
# C locale's ASCII codec unless fastkit passes an encoding.
PYTHONIOENCODING: utf-8
run: pdm run pytest -q -m "not extended"
Loading
Loading