diff --git a/.github/workflows/lint-include.yml b/.github/workflows/lint-include.yml
index 09233b67..55ed377d 100644
--- a/.github/workflows/lint-include.yml
+++ b/.github/workflows/lint-include.yml
@@ -101,6 +101,11 @@ on:
required: false
type: boolean
default: false
+ lint-ruff:
+ description: "Run ruff (Python linting and formatting) when the repository has Python files — uploads SARIF"
+ required: false
+ type: boolean
+ default: false
lint-config-drift:
description: "Check local config files match central DevSecNinja/.github repo"
required: false
@@ -117,8 +122,8 @@ on:
type: boolean
default: false
upload-sarif:
- description: "Upload checkov/trivy/zizmor results to GitHub code scanning (requires GitHub Advanced Security). Set
- false for private repos without GHAS to gate on exit codes with console output instead."
+ description: "Upload checkov/trivy/zizmor/ruff results to GitHub code scanning (requires GitHub Advanced Security).
+ Set false for private repos without GHAS to gate on exit codes with console output instead."
required: false
type: boolean
default: true
@@ -165,6 +170,7 @@ jobs:
lint-checkov: ${{ inputs.lint-checkov }}
lint-trivy: ${{ inputs.lint-trivy }}
lint-zizmor: ${{ inputs.lint-zizmor }}
+ lint-ruff: ${{ inputs.lint-ruff }}
lint-config-drift: ${{ inputs.lint-config-drift }}
lint-inline-scripts: ${{ inputs.lint-inline-scripts }}
lint-inline-scripts-blocking: ${{ inputs.lint-inline-scripts-blocking }}
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 4ee34452..69012017 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -93,6 +93,11 @@ on:
required: false
type: boolean
default: true
+ lint-ruff:
+ description: "Run ruff (Python linting and formatting) when the repository has Python files — uploads SARIF"
+ required: false
+ type: boolean
+ default: true
lint-config-drift:
description: "Check local config files match central DevSecNinja/.github repo"
required: false
@@ -112,8 +117,8 @@ on:
type: boolean
default: false
upload-sarif:
- description: "Upload checkov/trivy/zizmor results to GitHub code scanning (requires GitHub Advanced Security). Set
- false for private repos without GHAS to gate on exit codes with console output instead."
+ description: "Upload checkov/trivy/zizmor/ruff results to GitHub code scanning (requires GitHub Advanced Security).
+ Set false for private repos without GHAS to gate on exit codes with console output instead."
required: false
type: boolean
default: true
@@ -674,6 +679,67 @@ jobs:
sarif_file: ${{ runner.temp }}/zizmor.sarif
category: zizmor
+ ruff:
+ name: ruff
+ if: ${{ inputs.lint-ruff && (inputs.lint-job-mode == 'parallel' || (inputs.lint-job-mode == 'auto' && !github.event.repository.private))
+ }}
+ continue-on-error: ${{ ! inputs.lint-fail-on-error }}
+ runs-on: ubuntu-24.04
+ timeout-minutes: 10
+ permissions:
+ contents: read
+ security-events: write
+ steps:
+ - name: Checkout lint scripts
+ # The linter scripts ship with this reusable workflow: fetch them from
+ # the same commit of DevSecNinja/.github that the caller pinned.
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ repository: ${{ job.workflow_repository }}
+ ref: ${{ job.workflow_sha }}
+ path: .devsecninja-lint
+ sparse-checkout: |-
+ scripts/lint/
+ scripts/lint-inline-scripts.py
+ sparse-checkout-cone-mode: false
+ persist-credentials: false
+
+ - name: Move lint scripts out of the workspace
+ # Outside the workspace the caller's linters don't scan them, and the
+ # code checkout doesn't delete them.
+ run: mv .devsecninja-lint "${RUNNER_TEMP}/devsecninja-lint"
+
+ - name: Checkout code
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Find Python files
+ # Repositories without Python skip the mise install and ruff.
+ id: python-files
+ run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/detect-language.sh" python
+
+ - name: Install mise
+ if: ${{ steps.python-files.outputs.found == 'true' }}
+ uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0
+ with:
+ install: true
+ version: ${{ inputs.mise-version }}
+
+ - name: Run ruff
+ id: ruff
+ if: ${{ steps.python-files.outputs.found == 'true' }}
+ env:
+ UPLOAD_SARIF: ${{ inputs.upload-sarif }}
+ run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/ruff.sh"
+
+ - name: Upload SARIF report
+ if: ${{ !cancelled() && steps.ruff.outputs.sarif == 'true' }}
+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
+ with:
+ sarif_file: ${{ runner.temp }}/ruff.sarif
+ category: ruff
+
config-drift:
name: config drift
if: ${{ inputs.lint-config-drift && (inputs.lint-job-mode == 'parallel' || (inputs.lint-job-mode == 'auto' && !github.event.repository.private))
@@ -798,11 +864,17 @@ jobs:
fetch-depth: ${{ !inputs.lint-gitleaks && 1 || 0 }}
persist-credentials: false
+ - name: Find Python files
+ # Repositories without Python skip ruff (and its mise install).
+ id: python-files
+ if: ${{ inputs.lint-ruff }}
+ run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/detect-language.sh" python
+
- name: Install mise
if: >-
${{ inputs.lint-dprint || inputs.lint-yamlfmt || inputs.lint-yamllint || inputs.lint-actionlint || inputs.lint-gitleaks
|| inputs.lint-shellcheck || inputs.lint-shfmt || inputs.lint-checkov || inputs.lint-trivy || inputs.lint-zizmor
- }}
+ || steps.python-files.outputs.found == 'true' }}
uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0
with:
install: true
@@ -986,6 +1058,23 @@ jobs:
sarif_file: ${{ runner.temp }}/zizmor.sarif
category: zizmor
+ - name: Run ruff
+ id: ruff
+ if: ${{ steps.python-files.outputs.found == 'true' }}
+ continue-on-error: true
+ env:
+ UPLOAD_SARIF: ${{ inputs.upload-sarif }}
+ run: bash "${RUNNER_TEMP}/devsecninja-lint/scripts/lint/ruff.sh"
+
+ - name: Upload ruff SARIF report
+ id: ruff-sarif
+ if: ${{ !cancelled() && steps.ruff.outputs.sarif == 'true' }}
+ continue-on-error: true
+ uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
+ with:
+ sarif_file: ${{ runner.temp }}/ruff.sarif
+ category: ruff
+
- name: Check config drift against central repo
id: config-drift
if: ${{ inputs.lint-config-drift }}
diff --git a/.mise.toml b/.mise.toml
index 409e423e..98df7a9c 100644
--- a/.mise.toml
+++ b/.mise.toml
@@ -10,6 +10,7 @@ git-cliff = "2.14.2"
"pipx:checkov" = "3.3.30"
"pipx:json5" = "0.17.3"
"pipx:yamllint" = "1.38.0"
+ruff = "0.17.5"
shellcheck = "0.11.0"
shfmt = "3.14.1"
trivy = "0.76.1"
diff --git a/actions/ai-commits-badge/ai_commits_badge.py b/actions/ai-commits-badge/ai_commits_badge.py
old mode 100644
new mode 100755
index 451e616b..ac094de3
--- a/actions/ai-commits-badge/ai_commits_badge.py
+++ b/actions/ai-commits-badge/ai_commits_badge.py
@@ -5,6 +5,7 @@
Outputs in --out: ai-commits.svg, ai-commits.json (Shields endpoint),
ai-commits-stats.json and ai-commits-card.svg (auto light/dark).
"""
+
import argparse
import json
import re
@@ -34,8 +35,21 @@
]
PURPLE, GREY = "#8250df", "#8c959f"
SPARKLE = "M5 0 6.2 3.8 10 5 6.2 6.2 5 10 3.8 6.2 0 5 3.8 3.8Z"
-VERDANA = {" ": 3.9, "%": 11.9, "/": 4.7, "I": 4.6, "A": 7.5, "i": 3.1, "m": 10.7, "t": 4.3,
- "s": 5.7, "c": 5.7, "o": 6.7, "n": 7.0, "a": 6.6}
+VERDANA = {
+ " ": 3.9,
+ "%": 11.9,
+ "/": 4.7,
+ "I": 4.6,
+ "A": 7.5,
+ "i": 3.1,
+ "m": 10.7,
+ "t": 4.3,
+ "s": 5.7,
+ "c": 5.7,
+ "o": 6.7,
+ "n": 7.0,
+ "a": 6.6,
+}
def text_width(s):
@@ -57,8 +71,11 @@ def ai_tool(identity):
def git(repo_dir, *args):
return subprocess.run(
- ["git", "-C", str(repo_dir), *args], check=True,
- capture_output=True, text=True, encoding="utf-8",
+ ["git", "-C", str(repo_dir), *args],
+ check=True,
+ capture_output=True,
+ text=True,
+ encoding="utf-8",
).stdout
@@ -114,10 +131,12 @@ def tooltip(st, name):
return f"{name}: no commits to measure"
window = f" since {st['since']}" if st["since"] else ""
by_tool = ", ".join(f"{t} {n}" for t, n in st["tools"].items()) or "none"
- return (f"{name}: {st['ai_commits']:,} of {st['commits']:,} commits{window} ({message(st)}) involved AI: "
- f"{st['agent']:,} by an AI agent, {st['coauthored']:,} co-authored with AI, "
- f"{st['unattributed']:,} {NO_ATTRIBUTION}. "
- f"By tool: {by_tool}. Excludes merges and {st['excluded_automation']:,} bot-automation commits.")
+ return (
+ f"{name}: {st['ai_commits']:,} of {st['commits']:,} commits{window} ({message(st)}) involved AI: "
+ f"{st['agent']:,} by an AI agent, {st['coauthored']:,} co-authored with AI, "
+ f"{st['unattributed']:,} {NO_ATTRIBUTION}. "
+ f"By tool: {by_tool}. Excludes merges and {st['excluded_automation']:,} bot-automation commits."
+ )
def badge_svg(st, name, label="AI commits"):
@@ -135,10 +154,12 @@ def badge_svg(st, name, label="AI commits"):
def txt(cx, t):
tl = text_width(t) * 10
- return (f'{escape(t)}'
- f'{escape(t)}')
+ return (
+ f'{escape(t)}'
+ f'{escape(t)}'
+ )
return (
f'