-
Notifications
You must be signed in to change notification settings - Fork 53
Add pre-commit config for repo hygiene and secret detection #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,13 @@ on: | |
| pull_request: | ||
| branches: [ main ] | ||
|
|
||
| # Least privilege for this workflow (no PR comments from gitleaks-action) | ||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| PYTHON_VERSION: "3.12" | ||
| GITLEAKS_VERSION: "8.28.0" | ||
|
|
||
| jobs: | ||
| pre-commit: | ||
|
|
@@ -17,6 +22,11 @@ jobs: | |
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Full history so gitleaks can scan all commits in CI | ||
| fetch-depth: 0 | ||
| # Do not persist GITHUB_TOKEN in local git config for later steps | ||
| persist-credentials: false | ||
|
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy lift 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- workflow ---'
cat -n .github/workflows/pre-commit.yml
printf '%s\n' '--- workflow references and related controls ---'
rg -n --hidden -g '!node_modules' -g '!dist' -e 'pre-commit|pull_request|pull_request_target|gitleaks|dependency-review|scorecard|fetch-depth|persist-credentials|uv pip install|pre-commit' .github README.md pyproject.toml 2>/dev/null || true
printf '%s\n' '--- changed files and recent commits ---'
git status --short
git diff --stat
git log --oneline -8 -- .github/workflows/pre-commit.ymlRepository: redhat-data-and-ai/template-agent Length of output: 4426 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- project configuration ---'
sed -n '1,240p' pyproject.toml
printf '%s\n' '--- pre-commit configuration candidates ---'
find . -maxdepth 3 -type f \( -iname '*pre-commit*' -o -name '.pre-commit-config.yaml' -o -name '.pre-commit-config.yml' \) -print
for f in .pre-commit-config.yaml .pre-commit-config.yml; do
if [ -f "$f" ]; then
printf '%s\n' "--- $f ---"
cat -n "$f"
fi
done
printf '%s\n' '--- package/build entry points ---'
rg -n '^\[build-system\]|^build-backend|^backend-path|^packages|^include|^scripts|entry.?points|console_scripts|setup.py|setup.cfg|tox|nox|Makefile|local:' pyproject.toml .pre-commit-config.yaml .pre-commit-config.yml src tests 2>/dev/null || true
printf '%s\n' '--- repository object and ref summary ---'
git count-objects -v
git show-ref | head -30 || true
git rev-list --all --countRepository: redhat-data-and-ai/template-agent Length of output: 8809 🌐 Web query:
💡 Result: In GitHub Actions, using Citations:
🏁 Script executed: #!/bin/bash
set -eu
python3 - <<'PY'
from pathlib import Path
import re
workflow = Path(".github/workflows/pre-commit.yml").read_text()
hook_config = Path(".pre-commit-config.yaml").read_text()
checks = {
"pull_request_trigger": bool(re.search(r"(?m)^\s*pull_request:\s*$", workflow)),
"full_history_checkout": "fetch-depth: 0" in workflow,
"editable_dev_install": 'uv pip install -e ".[dev]"' in workflow,
"run_all_pre_commit_files": "pre-commit run --all-files" in workflow,
"gitleaks_all_refs_scan": 'gitleaks git --log-opts="--all"' in workflow,
"third_party_pre_commit_repositories": bool(re.search(r"(?m)^\s*-\s*repo:\s*https?://", hook_config)),
}
print("\n".join(f"{name}={value}" for name, value in checks.items()))
print("workflow_actions=" + ",".join(re.findall(r"uses:\s*([^\s]+)", workflow)))
print("workflow_files=" + ",".join(sorted(str(p) for p in Path(".github/workflows").glob("*"))))
PY
printf '%s\n' '--- action references ---'
rg -n '^\s*uses:' .github/workflows
printf '%s\n' '--- required supply-chain control references ---'
rg -n -i 'dependency-review|ossf-scorecard|scorecard' .github/workflows .github 2>/dev/null || trueRepository: redhat-data-and-ai/template-agent Length of output: 890 Separate the full-history Gitleaks scan from PR-controlled execution. 🤖 Prompt for AI Agents |
||
|
|
||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@v3 | ||
|
|
@@ -33,3 +43,16 @@ jobs: | |
| - name: Run Pre Commit | ||
| run: | | ||
| source .venv/bin/activate && pre-commit run --all-files | ||
|
|
||
| # The gitleaks pre-commit hook runs `gitleaks git --pre-commit --staged`, | ||
| # which only scans staged changes. A clean CI checkout has nothing staged. | ||
| # Use the open-source CLI (no GITLEAKS_LICENSE) and scan full git history. | ||
| - name: Install Gitleaks | ||
| run: | | ||
| curl -sSL "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" \ | ||
| | tar -xz gitleaks | ||
| sudo install -m 0755 gitleaks /usr/local/bin/gitleaks | ||
|
Comment on lines
+52
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Verify the Gitleaks archive before installation: the 🤖 Prompt for AI Agents |
||
| gitleaks version | ||
|
|
||
| - name: Gitleaks full history scan | ||
| run: gitleaks git --log-opts="--all" --redact --verbose | ||
Uh oh!
There was an error while loading. Please reload this page.