Files
homelable/.github/workflows/security.yml
T
Pouzor 37a3aee9cc ci(security): retry the npm audit when the registry endpoint is down
`npm audit` exits 1 both for a real advisory and for a registry that
refuses to answer, so a 503 from the audit endpoint reddened PRs that
changed no dependency at all — as it did on #409.

Retry up to three times, but only when the output names a transport or
availability failure. An advisory at or above high severity still fails
on the first attempt, unretried.

ha-relevant: no
2026-09-04 10:01:35 +02:00

70 lines
2.4 KiB
YAML

name: Security
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 9 * * 1' # Weekly on Monday
permissions:
contents: read
jobs:
secrets-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect secrets
uses: trufflesecurity/trufflehog@main
with:
path: ./
# Lob (a direct-mail API this project does not use) matches any
# `test_`-prefixed identifier of ~35 chars and reports it verified,
# because Lob test keys authenticate unconditionally. Every pytest
# function named at that length trips it — the first was
# `test_updates_an_existing_device_in_place`.
extra_args: --exclude-detectors=Lob
dependency-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: NPM Audit
# --omit=dev: only ship-time deps gate the build. Dev-only tooling
# (shadcn CLI and its transitive tree: hono, fast-uri, …) is never
# bundled or served, so its advisories must not fail release CI.
#
# `npm audit` exits 1 both for a real advisory and for a registry that
# would not answer (the audit endpoint 503s often enough to redden PRs
# that changed no dependency). Only the second case is retried; an
# advisory still fails on the first attempt.
run: |
cd frontend
for attempt in 1 2 3; do
if out=$(npm audit --omit=dev --audit-level=high 2>&1); then
echo "$out"
exit 0
fi
echo "$out"
if ! grep -qiE 'audit endpoint returned an error|service unavailable|ETIMEDOUT|ECONNRESET|ENOTFOUND|socket hang up' <<<"$out"; then
echo "::error::npm audit reported advisories at or above high severity"
exit 1
fi
echo "::warning::npm audit endpoint unreachable (attempt $attempt/3)"
if [ "$attempt" -lt 3 ]; then sleep 30; fi
done
echo "::error::npm audit endpoint unreachable after 3 attempts"
exit 1
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Pip audit
run: pip install pip-audit && pip-audit -r backend/requirements.txt