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
8 changes: 5 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: PyDoctor CLI - CI/CD
on:
push:
branches: [main, release]
tags: ["v*"]
# Release tags only (v2.3.0). The moving major tag (v2) used by the
# GitHub Action must not trigger a PyPI release.
tags: ["v*.*.*"]
pull_request:
branches: [main, release]

Expand Down Expand Up @@ -84,7 +86,7 @@ jobs:
name: Deploy to Production PyPI
needs: test
# Run only on pushes to release branch or new semantic tags
if: github.event_name == 'push' && (github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/v'))
if: github.event_name == 'push' && (github.ref == 'refs/heads/release' || startsWith(github.ref, 'refs/tags/v') && contains(github.ref_name, '.'))
runs-on: ubuntu-latest
environment:
name: production
Expand All @@ -106,7 +108,7 @@ jobs:
github-release:
name: GitHub Release
needs: [deploy-pypi]
if: startsWith(github.ref, 'refs/tags/v')
if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref_name, '.')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/pydoctor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Runs this repository's own GitHub Action against itself, so every pull
# request exercises the action and shows pydoctor's findings in code scanning.
name: pydoctor (self-scan)

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
scan:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install project dependencies
run: python -m pip install --upgrade --upgrade-strategy eager -e .

- name: pydoctor
uses: ./
with:
version: local
# Report findings in code scanning; the publish workflow is the gate.
fail-on-findings: "false"
23 changes: 23 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# pre-commit hooks for pydoctor-cli. See https://pre-commit.com
#
# pydoctor-ci: secrets and workflow checks. Runs in its own environment and
# doesn't need your project's dependencies or network access.
- id: pydoctor-ci
name: pydoctor (secrets and CI/CD guard)
description: Block commits that add secrets, .env files or risky GitHub Actions workflows.
entry: pydoctor check --ci
language: python
pass_filenames: false
always_run: true
stages: [pre-commit, pre-push]

# pydoctor-check: the full scan, using the pydoctor you installed yourself so
# it scans your project's environment. Needs network access. Best at pre-push.
- id: pydoctor-check
name: pydoctor (full scan)
description: Full pydoctor scan of the project's environment before pushing.
entry: pydoctor check
language: system
pass_filenames: false
always_run: true
stages: [pre-push]
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,44 @@ Run a comprehensive check-up on your project.
pydoctor diagnose
```

### In CI: GitHub Action

Findings appear as code-scanning alerts on pull requests, and the job fails on new problems:

```yaml
permissions:
contents: read
security-events: write

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: "3.12" }
- run: pip install -r requirements.txt
- uses: iamAgbaCoder/pydoctor-cli@v2
```

Set `ci-only: "true"` to run only the secrets and workflow checks. Any CI system can use `pydoctor check --sarif pydoctor.sarif` directly.

### Adopting it in an existing project: baselines

```bash
pydoctor baseline # accept today's issues; commit .pydoctor-baseline.json
pydoctor check # now fails only on new issues
```

Problems with the scan itself (unreadable environment, unreachable vulnerability database) are never baselined.

### pre-commit

```yaml
repos:
- repo: https://github.com/iamAgbaCoder/pydoctor-cli
rev: v2.3.0
hooks:
- id: pydoctor-ci # blocks commits that add secrets or risky workflows
```

### Automated Fixes

Let PyDoctor perform the heavy lifting. It will offer to install missing packages, upgrade outdated ones, and clean up your environment.
Expand All @@ -85,6 +123,15 @@ pydoctor fix

## Release History

### v2.3.0
Built for CI: adopt pydoctor in an existing project without a wall of failures, and see findings where you review code.

- **Baselines:** `pydoctor baseline` records today's issues in `.pydoctor-baseline.json`; scans then fail only on new ones and tell you when baselined issues are fixed. Fingerprints survive unrelated edits (a secret moved down by new lines stays known) and package upgrades. `--ci` updates only the CI-guard entries. `--baseline FILE` / `--no-baseline` on every scan command. Broken scans are never baselined.
- **SARIF output:** `--sarif FILE` on every scan command (SARIF 2.1.0, schema-validated). Vulnerabilities carry their CVSS score as security severity and point at the line that declares the package; secrets and workflow findings point at their file and line.
- **GitHub Action:** `uses: iamAgbaCoder/pydoctor-cli@v2` installs pydoctor in isolation, uploads findings to code scanning, and fails the job on new problems.
- **pre-commit hooks:** `pydoctor-ci` blocks commits that add secrets, `.env` files or risky workflows; `pydoctor-check` runs the full scan at pre-push.
- **Docs links:** every issue links to its page on pydoctor-docs.thally.app (`docs_url` in JSON; shown in the terminal for errors).

### v2.2.0
Results you can trust: every fix in this release removes a case where PyDoctor reported a problem as fine, or got a severity wrong.

Expand Down
80 changes: 80 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "pydoctor"
description: "Scan a Python project for vulnerable, conflicting and unused dependencies, committed secrets and risky workflows."
author: "Favour Bamgboye"
branding:
icon: "activity"
color: "orange"

inputs:
path:
description: "Project directory to scan."
default: "."
ci-only:
description: "Only run the CI/CD guard (secrets and workflow checks). Doesn't need the project's dependencies installed."
default: "false"
python:
description: "Python interpreter of the project. Default: auto-detect (the setup-python interpreter on PATH)."
default: ""
args:
description: "Extra arguments passed to `pydoctor check`, e.g. `--no-baseline`."
default: ""
version:
description: "pydoctor-cli version to install: an exact version (2.3.0), `local` to install from this action's source, or empty to match the action's tag (v2 → latest 2.x)."
default: ""
sarif-file:
description: "Where to write the SARIF report."
default: "pydoctor.sarif"
upload-sarif:
description: "Upload the SARIF report to GitHub code scanning. Needs `permissions: security-events: write`."
default: "true"
fail-on-findings:
description: "Fail the step when pydoctor exits with code 1 (new error or critical issues, or score below min_health_score)."
default: "true"

outputs:
exit-code:
description: "pydoctor's exit code (0 clean, 1 findings, 2 usage error)."
value: ${{ steps.scan.outputs.exit-code }}
sarif-file:
description: "Path of the SARIF report."
value: ${{ steps.scan.outputs.sarif-file }}

runs:
using: "composite"
steps:
- name: Install pydoctor (isolated)
id: install
shell: bash
env:
PYDOCTOR_VERSION: ${{ inputs.version }}
ACTION_REF: ${{ github.action_ref }}
run: bash "$GITHUB_ACTION_PATH/action/install.sh"

- name: Run pydoctor
id: scan
shell: bash
env:
PYDOCTOR_BIN: ${{ steps.install.outputs.bin }}
INPUT_PATH: ${{ inputs.path }}
INPUT_CI_ONLY: ${{ inputs.ci-only }}
INPUT_PYTHON: ${{ inputs.python }}
INPUT_ARGS: ${{ inputs.args }}
INPUT_SARIF_FILE: ${{ inputs.sarif-file }}
run: bash "$GITHUB_ACTION_PATH/action/scan.sh"

- name: Upload SARIF to code scanning
if: ${{ always() && inputs.upload-sarif == 'true' && steps.scan.outputs.sarif-written == 'true' }}
continue-on-error: true
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan.outputs.sarif-file }}
category: pydoctor

- name: Fail on findings
if: ${{ inputs.fail-on-findings == 'true' && steps.scan.outputs.exit-code != '0' }}
shell: bash
env:
CODE: ${{ steps.scan.outputs.exit-code }}
run: |
echo "::error title=pydoctor::pydoctor exited with code $CODE. See the scan step for details."
exit "$CODE"
41 changes: 41 additions & 0 deletions action/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Install pydoctor-cli into its own virtual environment so it can't change, or
# be counted as part of, the project's environment. Prints `bin=<path>` to
# $GITHUB_OUTPUT.
set -euo pipefail

spec="pydoctor-cli"
version="${PYDOCTOR_VERSION:-}"
ref="${ACTION_REF:-}"

if [[ "$version" == "local" ]]; then
spec="${GITHUB_ACTION_PATH:?}"
elif [[ -n "$version" ]]; then
spec="pydoctor-cli==${version#v}"
elif [[ "$ref" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
spec="pydoctor-cli==${ref#v}"
elif [[ "$ref" =~ ^v([0-9]+)$ ]]; then
major="${BASH_REMATCH[1]}"
spec="pydoctor-cli>=${major},<$((major + 1))"
fi

if [[ -n "${PYDOCTOR_DRY_RUN:-}" ]]; then
echo "$spec"
exit 0
fi

base="${RUNNER_TEMP:-${TMPDIR:-/tmp}}/pydoctor-venv"
# On Windows runners RUNNER_TEMP is a Windows path; use the POSIX form in bash.
if command -v cygpath >/dev/null 2>&1; then
base="$(cygpath -u "$base")"
fi
py="$(command -v python3 || command -v python)"
"$py" -m venv "$base"
if [[ -x "$base/bin/python" ]]; then
venv_py="$base/bin/python"; bin="$base/bin/pydoctor"
else
venv_py="$base/Scripts/python.exe"; bin="$base/Scripts/pydoctor.exe"
fi
"$venv_py" -m pip install --quiet --disable-pip-version-check "$spec"
"$bin" --version
echo "bin=$bin" >> "${GITHUB_OUTPUT:-/dev/null}"
25 changes: 25 additions & 0 deletions action/scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Run `pydoctor check`, write SARIF, and record the exit code without failing,
# so the SARIF upload step still runs. The action's last step fails the job.
set -uo pipefail

args=(check --path "${INPUT_PATH:-.}" --sarif "${INPUT_SARIF_FILE:-pydoctor.sarif}")
[[ "${INPUT_CI_ONLY:-false}" == "true" ]] && args+=(--ci)
[[ -n "${INPUT_PYTHON:-}" ]] && args+=(--python "$INPUT_PYTHON")
if [[ -n "${INPUT_ARGS:-}" ]]; then
read -r -a extra <<< "$INPUT_ARGS"
args+=("${extra[@]}")
fi

"${PYDOCTOR_BIN:?}" "${args[@]}"
code=$?

out="${GITHUB_OUTPUT:-/dev/null}"
echo "exit-code=$code" >> "$out"
echo "sarif-file=${INPUT_SARIF_FILE:-pydoctor.sarif}" >> "$out"
if [[ -f "${INPUT_SARIF_FILE:-pydoctor.sarif}" ]]; then
echo "sarif-written=true" >> "$out"
else
echo "sarif-written=false" >> "$out"
fi
exit 0
2 changes: 1 addition & 1 deletion pydoctor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
License: MIT
"""

__version__ = "2.2.0"
__version__ = "2.3.0"
__author__ = "Favour Bamgboye"
__description__ = "Python environment diagnostic CLI — your project's doctor."
Loading
Loading