Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: 2
updates:
# Python dependencies (pip)
- package-ecosystem: "pip"
# Python dependencies (pyproject.toml + uv.lock)
- package-ecosystem: "uv"
directory: "/"
schedule:
interval: "weekly"
Expand All @@ -12,7 +12,7 @@ updates:
commit-message:
prefix: "deps"

# GitHub Actions
# GitHub Actions (pinned to full commit SHAs; Dependabot bumps the SHA and the version comment)
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
4 changes: 4 additions & 0 deletions .github/pip-audit-allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Vulnerability IDs accepted by the pip-audit CI job (.github/scripts/pip-audit.sh).
# One ID per line, followed by a comment explaining why it is accepted and when to revisit it.
# Example:
# GHSA-xxxx-xxxx-xxxx # dev-only tool, not reachable from the library; drop when upstream releases a fix
51 changes: 51 additions & 0 deletions .github/scripts/pip-audit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Audit every locked dependency (runtime + all dependency groups) for known vulnerabilities.
# Exits non-zero when pip-audit finds a vulnerability that is not in the allowlist.
set -euo pipefail

# Pinned so a new pip-audit release cannot change CI behaviour silently.
PIP_AUDIT_VERSION="2.10.1"
ALLOWLIST=".github/pip-audit-allowlist.txt"
# Every supported Python version (same list as the test matrix in ci.yml; checked by tests/test_workflows.py).
PYTHON_VERSIONS=("3.10" "3.11" "3.12" "3.13" "3.14")

workdir="$(mktemp -d)"
trap 'rm -rf "$workdir"' EXIT

# Export the exact pinned versions from uv.lock; the project itself is not on PyPI under this version.
uv export --frozen --all-groups --no-hashes --no-emit-project --output-file "$workdir/requirements.txt" >/dev/null

# Build one --ignore-vuln flag per allowlisted ID (text before '#', blank lines skipped).
ignore_args=()
if [[ -f "$ALLOWLIST" ]]; then
while IFS= read -r line || [[ -n "$line" ]]; do
vuln_id="$(echo "${line%%#*}" | xargs)"
if [[ -n "$vuln_id" ]]; then
ignore_args+=(--ignore-vuln "$vuln_id")
fi
done <"$ALLOWLIST"
fi

# pip-audit evaluates environment markers with the interpreter it runs on and silently skips
# lines that do not match (e.g. `python_full_version < '3.11'`). The lock pins different versions
# per Python, so audit the same export once per supported version (keep in sync with ci.yml).
failed_versions=()
for python_version in "${PYTHON_VERSIONS[@]}"; do
echo "::group::pip-audit on Python ${python_version}"
# --no-deps/--disable-pip: the export is already fully resolved, so audit it as-is.
if ! uvx --python "$python_version" "pip-audit==${PIP_AUDIT_VERSION}" \
--requirement "$workdir/requirements.txt" \
--no-deps \
--disable-pip \
--progress-spinner off \
"${ignore_args[@]}"; then
failed_versions+=("$python_version")
fi
echo "::endgroup::"
done

# Fail if any single Python version has a known vulnerability.
if ((${#failed_versions[@]} > 0)); then
echo "pip-audit found vulnerabilities on Python: ${failed_versions[*]}" >&2
exit 1
fi
41 changes: 33 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
name: CI

# Pull requests run the checks directly. Pushes to main run them through
# publish.yml (via workflow_call), so a release can only happen after the same
# checks have passed on the exact commit being published.
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_call:

# Least privilege by default: every job only reads the repository.
permissions:
contents: read

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: tox-dev/action-pre-commit-uv@v1
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false
- uses: tox-dev/action-pre-commit-uv@9316eafda3550b0365575c60b9f53725a81d0cfd # v1.1.2

test:
runs-on: ubuntu-latest
Expand All @@ -20,10 +28,12 @@ jobs:
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false

- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
Expand All @@ -38,7 +48,7 @@ jobs:
run: uv run coverage lcov -o coverage.lcov

- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: coverage.lcov
Expand All @@ -51,7 +61,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Coveralls finished
uses: coverallsapp/github-action@v2
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2.3.8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

# Fail on known vulnerabilities in any locked dependency (runtime and all groups).
# Accepted exceptions live in .github/pip-audit-allowlist.txt, one ID per line with a reason.
pip-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false

- name: Install uv
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0

- name: Audit locked dependencies
run: bash .github/scripts/pip-audit.sh
8 changes: 4 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0

- name: Install dependencies
run: uv sync --group docs
Expand All @@ -35,7 +35,7 @@ jobs:
run: uv run mkdocs build

- name: Upload artifact
uses: actions/upload-pages-artifact@v4
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
with:
path: docs/site

Expand All @@ -48,4 +48,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v5
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
153 changes: 92 additions & 61 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,115 +1,146 @@
name: Publish

# Never add a pull_request (or pull_request_target) trigger here: this workflow can
# mint an OIDC token for PyPI and write tags/releases. tests/test_workflows.py enforces it.
#
# - push to main: runs the full CI, then publishes official x.y.z versions only.
# - workflow_dispatch: manual run (gated by the `pypi` environment reviewers);
# publishes pre-releases from any branch, official versions only from main.
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

# Least privilege by default; jobs that need more ask for it explicitly.
permissions:
contents: read

# Never run two publishes at once, and never cancel one that is in progress.
concurrency:
group: publish
cancel-in-progress: false

jobs:
# Same checks as pull requests (tests, pre-commit, pip-audit) on the exact commit to publish.
ci:
uses: ./.github/workflows/ci.yml

check-version:
runs-on: ubuntu-latest
outputs:
should_publish: ${{ steps.check.outputs.should_publish }}
version: ${{ steps.check.outputs.version }}
is_official: ${{ steps.check.outputs.is_official }}
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
fetch-depth: 0
persist-credentials: false

- name: Install uv
uses: astral-sh/setup-uv@v7

# Extract version from pyproject.toml, check if tag exists, and determine version type
# Read the version from pyproject.toml, skip if its tag already exists, and decide
# whether this event is allowed to publish this kind of version.
- name: Check version
id: check
env:
EVENT_NAME: ${{ github.event_name }}
REF: ${{ github.ref }}
run: |
VERSION=$(uv run python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
TAG="v${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"

# Check if version matches x.y.z (official) or has pre-release suffix
# Official versions are x.y.z (optionally .postN); anything else is a pre-release
if echo "$VERSION" | grep -qP '^\d+\.\d+\.\d+(\.post\d+)?$'; then
echo "is_official=true" >> "$GITHUB_OUTPUT"
echo "Version $VERSION is an official release"
IS_OFFICIAL=true
else
echo "is_official=false" >> "$GITHUB_OUTPUT"
echo "Version $VERSION is a pre-release"
IS_OFFICIAL=false
fi
echo "is_official=${IS_OFFICIAL}" >> "$GITHUB_OUTPUT"

if git tag -l "$TAG" | grep -q "$TAG"; then
SHOULD_PUBLISH=true
if git tag -l "$TAG" | grep -qx "$TAG"; then
echo "Tag $TAG already exists, skipping publish"
echo "should_publish=false" >> "$GITHUB_OUTPUT"
SHOULD_PUBLISH=false
elif [ "$IS_OFFICIAL" = "true" ] && [ "$REF" != "refs/heads/main" ]; then
echo "Official version $VERSION can only be published from main, skipping"
SHOULD_PUBLISH=false
elif [ "$IS_OFFICIAL" = "false" ] && [ "$EVENT_NAME" != "workflow_dispatch" ]; then
echo "Pre-release $VERSION is only published by a manual workflow_dispatch run, skipping"
SHOULD_PUBLISH=false
else
echo "Tag $TAG does not exist, will publish"
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "Will publish $VERSION (official=${IS_OFFICIAL})"
fi
echo "should_publish=${SHOULD_PUBLISH}" >> "$GITHUB_OUTPUT"

# Pre-release versions (e.g. 1.0.0-rc.1, 1.0.0-beta.1) are published from PRs
publish-prerelease:
needs: check-version
if: >-
needs.check-version.outputs.should_publish == 'true'
&& needs.check-version.outputs.is_official == 'false'
&& github.event_name == 'pull_request'
# Build without any write permission; the publish job only receives the artifacts.
build:
needs: [ci, check-version]
if: needs.check-version.outputs.should_publish == 'true'
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
with:
persist-credentials: false

- name: Install uv
uses: astral-sh/setup-uv@v7
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0

- name: Build
run: uv build

- name: Publish to PyPI
run: uv publish

- name: Create git tag and GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="v${{ needs.check-version.outputs.version }}"
git tag "$TAG"
git push origin "$TAG"
gh release create "$TAG" dist/* --generate-notes --prerelease
- name: Upload distributions
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dist
path: dist/
if-no-files-found: error

# Official versions (x.y.z) are published only from pushes to main
# Trusted publishing (OIDC, no stored token). The action also generates and uploads
# PEP 740 provenance attestations for every distribution.
publish:
needs: check-version
if: >-
needs.check-version.outputs.should_publish == 'true'
&& needs.check-version.outputs.is_official == 'true'
&& github.event_name == 'push'
needs: [check-version, build]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/fastapi-task-manager/${{ needs.check-version.outputs.version }}/
permissions:
id-token: write
contents: write
steps:
- uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Build
run: uv build
- name: Download distributions
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/

- name: Publish to PyPI
run: uv publish
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3

# Tag and GitHub Release only after PyPI accepted the upload.
release:
needs: [check-version, publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download distributions
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dist
path: dist/

# gh creates the tag on the published commit, so no checkout or git push is needed.
- name: Create git tag and GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.check-version.outputs.version }}
IS_OFFICIAL: ${{ needs.check-version.outputs.is_official }}
run: |
TAG="v${{ needs.check-version.outputs.version }}"
git tag "$TAG"
git push origin "$TAG"
gh release create "$TAG" dist/* --generate-notes
PRERELEASE_FLAG=""
if [ "$IS_OFFICIAL" != "true" ]; then
PRERELEASE_FLAG="--prerelease"
fi
gh release create "v${VERSION}" dist/* \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
--generate-notes \
$PRERELEASE_FLAG
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dev = [
"pydantic-settings>=2.12.0",
"pytest>=8.3.5",
"pytest-asyncio>=1.3.0",
"pyyaml>=6.0.3",
"ruff>=0.14.10",
"setuptools>=80.8.0", # Added to fix pycharm test discovery
"ty>=0.0.5",
Expand Down
Loading
Loading