Repository navigation
ci: publish on merge to stable (publishing policy 1.8.0) - #475
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #475 +/- ##
=======================================
Coverage 99.29% 99.29%
=======================================
Files 31 31
Lines 3259 3259
=======================================
Hits 3236 3236
Misses 23 23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
en0f
left a comment
There was a problem hiding this comment.
Reviewed at ddd8d45.
🟢 The release path is bbot's v1.5.0 flow, with every credential behind the release environment
publish.yml is bbot's v1.5.0 publish.yml without the Docker job, including enable-cache: false on the build. All ten action pins resolve to the commit of the tag in their comment (V01, V02). It runs only on a push to stable (V03), and the only job that can mint an OIDC token is pypi, inside environment: release (V04); release-check's credentials job and the shared release job sit in the same environment. The [tool.hatch.version] path gives manifest.py a static 1.3.0 (V14), so release-check works with the dynamic version, and because v1.3.0 already exists the first push to stable publishes nothing until the version is bumped.
🟢 The branch-push PyPI token publish and pull_request_target are gone from the test workflow
At the base, tests.yaml held contents: write, a pull_request_target trigger, tag-pinned actions on ubuntu-latest, and published to PyPI from a push to main with PYPI_API_TOKEN, tagging by hand. tests.yml now only tests, on contents: read and SHA pins, and lint runs the project's own ruff==0.15.10, locked at that version (V05 to V09, V12). No workflow reads a stored PyPI token any more, which is what ci.md § Naming and § Secrets ask for.
Reproduce this review
# save the script below as verify-475.sh and the control patch as control-475.patch, then:
bash verify-475.sh blacklanternsecurity/badsecrets ddd8d45c6a115d75ebdccafa7e4b15b0a71c64e5
# expected: SUMMARY 14 PASS, 0 FAIL, 0 SKIP, 0 BROKEN
# control: bash verify-475.sh blacklanternsecurity/badsecrets ddd8d45c6a115d75ebdccafa7e4b15b0a71c64e5 control-475.patch -> V01 to V14 FAIL#!/usr/bin/env bash
# verify-475.sh: reproducible checks for blacklanternsecurity/badsecrets#475
# Usage: bash verify-475.sh <owner/repo> <sha> [<control-patch>]
# Changes nothing outside a mktemp directory and nothing on GitHub (PR-VF-02).
#
# CONTROL: patch control-475.patch
# CONTROL-EXPECT: V01=FAIL V02=FAIL V03=FAIL V04=FAIL V05=FAIL V06=FAIL V07=FAIL V08=FAIL V09=FAIL V10=FAIL V11=FAIL V12=FAIL V13=FAIL V14=FAIL
set -uo pipefail
REPO="${1:?owner/repo}"; SHA="${2:?sha}"; PATCH="${3:-}"
PASS=0; FAIL=0; SKIP=0; BROKEN=0
pass() { echo "PASS $1 $2"; PASS=$((PASS+1)); }
fail() { echo "FAIL $1 $2 -- $3"; FAIL=$((FAIL+1)); }
skip() { echo "SKIP $1 $2 -- $3"; SKIP=$((SKIP+1)); }
broken() { echo "BROKEN $1 $2 -- $3"; BROKEN=$((BROKEN+1)); }
summary() { echo "SUMMARY $PASS PASS, $FAIL FAIL, $SKIP SKIP, $BROKEN BROKEN"; [ "$FAIL" -eq 0 ] && [ "$BROKEN" -eq 0 ]; }
echo "script_sha256 $(shasum -a 256 "$0" | cut -d' ' -f1)"
echo "git $(git --version | cut -d' ' -f3)"
echo "python3 $(python3 -c 'import sys;print(sys.version.split()[0])')"
echo "gh $(gh --version | head -1 | cut -d' ' -f3)"
[ -n "$PATCH" ] && PATCH="$(cd "$(dirname "$PATCH")" && pwd)/$(basename "$PATCH")"
WORK="$(mktemp -d)"; trap 'rm -rf "$WORK"' EXIT
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1 GIT_TERMINAL_PROMPT=0
GIT=(git -c credential.helper= -c 'credential.helper=!gh auth git-credential')
"${GIT[@]}" clone --quiet --filter=blob:none --no-checkout "https://github.com/$REPO.git" "$WORK/src" || { broken V00 "clone" "clone failed"; summary; exit 1; }
cd "$WORK/src"
"${GIT[@]}" cat-file -e "$SHA^{commit}" 2>/dev/null || "${GIT[@]}" fetch --quiet origin "+refs/pull/*/head:refs/remotes/pr/*" || true
"${GIT[@]}" checkout --quiet --detach "$SHA" || { broken V00 "checkout $SHA" "checkout failed"; summary; exit 1; }
[ "$(git rev-parse HEAD)" = "$SHA" ] || { broken V00 "HEAD is $SHA" "HEAD mismatch"; summary; exit 1; }
if [ -n "$PATCH" ]; then git apply "$PATCH" || { broken V00 "apply control patch" "git apply failed"; summary; exit 1; }; fi
W=.github/workflows
for f in $W/publish.yml $W/tests.yml $W/dev-security.yml $W/stable-guard.yml .github/CODEOWNERS .github/secret_scanning.yml .github/dependabot.yml pyproject.toml uv.lock; do
[ -f "$f" ] || { broken V00 "file $f exists" "missing"; summary; exit 1; }
done
CHANGED_WF="$W/publish.yml $W/tests.yml $W/dev-security.yml $W/stable-guard.yml"
# V01 every remote uses: in the changed workflows is a full 40-hex SHA
bad=$(cat $CHANGED_WF | grep -E '^[[:space:]]*(-[[:space:]]+)?uses:' | grep -v 'uses: \./' | grep -Ev 'uses: [^@[:space:]]+@[0-9a-f]{40}([[:space:]]|$)' || true)
if [ -z "$bad" ]; then pass V01 "every remote uses: in the changed workflows is pinned to a 40-character SHA"; else fail V01 "every remote uses: in the changed workflows is pinned to a 40-character SHA" "$(echo "$bad" | head -1 | tr -s ' ')"; fi
# V02 each pin equals the commit its trailing tag comment resolves to (GET only)
v02_bad=""; v02_n=0
while read -r ref tag; do
repo="${ref%@*}"; repo=$(echo "$repo" | cut -d/ -f1-2); pin="${ref#*@}"
obj=$(gh api --method GET "repos/$repo/git/ref/tags/$tag" --jq '.object.type + " " + .object.sha' 2>/dev/null) || { v02_bad="$v02_bad $repo@$tag(unresolvable)"; continue; }
t=${obj%% *}; s=${obj#* }
[ "$t" = tag ] && s=$(gh api --method GET "repos/$repo/git/tags/$s" --jq .object.sha 2>/dev/null)
v02_n=$((v02_n+1)); [ "$s" = "$pin" ] || v02_bad="$v02_bad $repo@$tag(pin $pin != $s)"
done < <(cat $CHANGED_WF | grep -E 'uses: [^.]' | sed -E 's/.*uses: ([^[:space:]]+)[[:space:]]*#[[:space:]]*([^[:space:]]+).*/\1 \2/' | grep -E '^[^ ]+ v[0-9]' | sort -u)
if [ -z "$v02_bad" ] && [ "$v02_n" -gt 0 ]; then pass V02 "each of $v02_n pinned SHAs is the commit of the tag in its comment"; else fail V02 "each pinned SHA is the commit of the tag in its comment" "${v02_bad:-no pins found}"; fi
# Job-level parsing helper (stdlib only)
jobs_py='
import re,sys,json
txt=open(sys.argv[1]).read().splitlines()
jobs={};cur=None;inj=False
for l in txt:
if re.match(r"^jobs:\s*$",l): inj=True; continue
if inj and re.match(r"^\S",l): inj=False
if not inj: continue
m=re.match(r"^ ([A-Za-z0-9_-]+):\s*$",l)
if m: cur=m.group(1); jobs[cur]=[]; continue
if cur: jobs[cur].append(l)
on=[];ino=False
for l in txt:
if re.match(r"^on:\s*$",l): ino=True; continue
if ino and re.match(r"^\S",l): break
if ino: on.append(l)
print(json.dumps({"jobs":{k:"\n".join(v) for k,v in jobs.items()},"on":"\n".join(on)}))'
# V03 publish.yml triggers on push to stable only
P=$(python3 -c "$jobs_py" $W/publish.yml)
on=$(echo "$P" | python3 -c 'import json,sys;print(json.load(sys.stdin)["on"])')
norm=$(echo "$on" | tr -d ' \n')
if [ "$norm" = "push:branches:[stable]" ]; then pass V03 "publish.yml runs only on a push to stable (no tags, PRs or manual dispatch)"; else fail V03 "publish.yml runs only on a push to stable" "on: $norm"; fi
# V04 the only job that can mint an OIDC token is pypi, and it runs in the release environment
v04=$(echo "$P" | python3 -c '
import json,sys,re
j=json.load(sys.stdin)["jobs"]
oidc=[k for k,v in j.items() if re.search(r"id-token:\s*write",v)]
envok=all(re.search(r"^\s+environment:\s*release\s*$",j[k],re.M) for k in oidc)
print("ok" if oidc==["pypi"] and envok else "oidc=%s env_release=%s"%(oidc,envok))')
if [ "$v04" = ok ]; then pass V04 "only the pypi job holds id-token: write, and it runs in environment release"; else fail V04 "only the pypi job holds id-token: write, in environment release" "$v04"; fi
# V05 no workflow other than cla.yml uses pull_request_target
prt=""; for f in $W/*; do case "$f" in *cla.yml) continue;; esac; grep -qE '^[[:space:]]*pull_request_target:' "$f" && prt="$prt $f"; done
if [ -z "$prt" ]; then pass V05 "no workflow other than cla.yml uses pull_request_target"; else fail V05 "no workflow other than cla.yml uses pull_request_target" "found in$prt"; fi
# V06 every changed workflow declares a top-level permissions block
miss=""; for f in $CHANGED_WF; do grep -qE '^permissions:' "$f" || miss="$miss $f"; done
if [ -z "$miss" ]; then pass V06 "every changed workflow declares top-level permissions"; else fail V06 "every changed workflow declares top-level permissions" "missing in$miss"; fi
# V07 no workflow reads a stored PyPI token
if cat $W/* | grep -qE 'PYPI_API_TOKEN|pypi_token|password: \$\{\{ *secrets'; then fail V07 "no workflow reads a stored PyPI token" "$(cat $W/* | grep -E 'PYPI_API_TOKEN|pypi_token|password:' | head -1 | tr -s ' ')"; else pass V07 "no workflow reads a stored PyPI token"; fi
# V08 no changed workflow runs on a floating runner image
if cat $CHANGED_WF | grep -qE 'runs-on:.*-latest'; then fail V08 "no changed workflow runs on a -latest runner" "$(cat $CHANGED_WF | grep -E 'runs-on:.*-latest' | head -1 | tr -s ' ')"; else pass V08 "no changed workflow runs on a -latest runner"; fi
# V09 ruff is pinned with == in the dev group and the lock holds that exact version
cat > "$WORK/v09.py" <<'PY'
import tomllib,re
p=tomllib.load(open("pyproject.toml","rb"))
dev=[d for d in p.get("dependency-groups",{}).get("dev",[]) if d.replace(" ","").startswith("ruff")]
lock=tomllib.load(open("uv.lock","rb"))
locked=[x["version"] for x in lock.get("package",[]) if x["name"]=="ruff"]
m=re.fullmatch(r"ruff==([0-9.]+)",dev[0].replace(" ","")) if len(dev)==1 else None
print("ok" if m and locked==[m.group(1)] else "dev=%s locked=%s"%(dev,locked))
PY
v09=$(python3 "$WORK/v09.py")
if [ "$v09" = ok ]; then pass V09 "ruff is pinned with == in the dev group and uv.lock locks the same version"; else fail V09 "ruff is pinned with == and locked at that version" "$v09"; fi
# V10 CODEOWNERS names bbot-leads on the catch-all line
if grep -E '^\*[[:space:]]' .github/CODEOWNERS | grep -q '@blacklanternsecurity/bbot-leads'; then pass V10 "CODEOWNERS names @blacklanternsecurity/bbot-leads for every path"; else fail V10 "CODEOWNERS names @blacklanternsecurity/bbot-leads for every path" "$(grep -E '^\*' .github/CODEOWNERS)"; fi
# V11 secret scanning ignores only the known-secrets corpus
ign=$(grep -E '^[[:space:]]*-[[:space:]]' .github/secret_scanning.yml | tr -d ' "-' | sort | tr '\n' ' ')
if [ "$ign" = "badsecrets/resources/** " ]; then pass V11 "secret_scanning.yml ignores only badsecrets/resources/**"; else fail V11 "secret_scanning.yml ignores only badsecrets/resources/**" "ignores: $ign"; fi
# V12 tests.yml has no publish, tag, or write step (ci.md naming)
if grep -qE 'gh-action-pypi-publish|git tag|git push|contents: write|environment:' $W/tests.yml; then fail V12 "tests.yml has no publish, tag or write step" "$(grep -E 'gh-action-pypi-publish|git tag|git push|contents: write|environment:' $W/tests.yml | head -1 | tr -s ' ')"; else pass V12 "tests.yml has no publish, tag or write step"; fi
# V13 dependabot: uv and github-actions entries each target dev with a cooldown of at least 7 days
v13=$(awk '
/package-ecosystem:/ {eco=$NF; gsub(/"/,"",eco)}
/target-branch:/ {tb[eco]=$NF; gsub(/"/,"",tb[eco])}
/default-days:/ {cd[eco]=$NF}
END {ok=1; n=split("uv github-actions",e," "); for(i=1;i<=n;i++){ if(tb[e[i]]!="dev" || cd[e[i]]+0<7){ok=0; printf "%s(tb=%s cd=%s) ", e[i], tb[e[i]], cd[e[i]]} } if(ok) print "ok"}' .github/dependabot.yml)
if [ "$v13" = ok ]; then pass V13 "dependabot uv and github-actions entries target dev with a >=7-day cooldown"; else fail V13 "dependabot uv and github-actions entries target dev with a >=7-day cooldown" "$v13"; fi
# V14 release-check can read a MAJOR.MINOR.PATCH version from the hatch version path
cat > "$WORK/v14.py" <<'PY'
import tomllib,re,pathlib
p=tomllib.load(open("pyproject.toml","rb"))
path=p["tool"]["hatch"]["version"]["path"]
v=re.search(r"""__version__\s*=\s*["']([^"']+)["']""",pathlib.Path(path).read_text())
print(v[1] if v and re.fullmatch(r"\d+\.\d+\.\d+",v[1]) else "bad:%s"%(v[1] if v else None))
PY
v14=$(python3 "$WORK/v14.py")
case "$v14" in bad:*) fail V14 "the hatch version path yields a MAJOR.MINOR.PATCH version for release-check" "$v14";; *) pass V14 "the hatch version path yields a MAJOR.MINOR.PATCH version for release-check ($v14)";; esac
summarydiff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index bce0a9b..305bb69 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1,2 +1,2 @@
# Every change needs an approval from a lead (development-leads or bbot-leads) before it reaches stable (.github-config docs/policy/publishing.md 1.8.0).
-* @blacklanternsecurity/bbot-leads @blacklanternsecurity/development-leads
+* @blacklanternsecurity/development-leads
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index e6c747f..850afd0 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -37,4 +37,4 @@ updates:
update-types:
- "major"
cooldown:
- default-days: 7
+ default-days: 3
diff --git a/.github/secret_scanning.yml b/.github/secret_scanning.yml
index 0d9d156..deffa63 100644
--- a/.github/secret_scanning.yml
+++ b/.github/secret_scanning.yml
@@ -1,3 +1,4 @@
# badsecrets ships known secrets by design (its detection corpus); scanning them would only raise noise.
paths-ignore:
- "badsecrets/resources/**"
+ - "**"
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index bf5ae9e..79b95d7 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -3,6 +3,7 @@ name: publish
on:
push:
branches: [stable]
+ tags: ["v*"]
permissions: {}
@@ -31,11 +32,11 @@ jobs:
build:
needs: tests
- runs-on: ubuntu-24.04
+ runs-on: ubuntu-latest
permissions:
contents: read
steps:
- - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ - uses: actions/checkout@v7 # v7.0.1
with:
persist-credentials: false
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
@@ -51,7 +52,6 @@ jobs:
pypi:
needs: build
runs-on: ubuntu-24.04
- environment: release
permissions:
id-token: write
steps:
@@ -62,6 +62,7 @@ jobs:
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
skip-existing: true
+ password: ${{ secrets.PYPI_API_TOKEN }}
release:
needs: [check, pypi]
diff --git a/.github/workflows/stable-guard.yml b/.github/workflows/stable-guard.yml
index 2572f2e..9ded44e 100644
--- a/.github/workflows/stable-guard.yml
+++ b/.github/workflows/stable-guard.yml
@@ -4,9 +4,6 @@ on:
pull_request:
branches: [stable]
-permissions:
- contents: read
-
jobs:
guard:
uses: blacklanternsecurity/release-workflows/.github/workflows/stable-guard.yml@4f32510b1cdfe7305aa27daa3f6fd72e4c03c21b # v1.5.0
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 7a03e6f..1c7a4c5 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -4,13 +4,14 @@ on:
branches:
- dev
pull_request:
+ pull_request_target:
workflow_call:
secrets:
CODECOV_TOKEN:
required: false
permissions:
- contents: read
+ contents: write
concurrency:
group: tests-${{ github.workflow_ref }}-${{ github.event.pull_request.number || github.ref }}
diff --git a/badsecrets/__version__.py b/badsecrets/__version__.py
index 67bc602..9f6cc16 100644
--- a/badsecrets/__version__.py
+++ b/badsecrets/__version__.py
@@ -1 +1 @@
-__version__ = "1.3.0"
+__version__ = "1.3"
diff --git a/pyproject.toml b/pyproject.toml
index d639511..165f351 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -32,7 +32,7 @@ dev = [
"pytest-cov>=7.1.0,<8.0.0",
"mock>=5.1.0",
"pytest-mock>=3.15.1",
- "ruff==0.15.10",
+ "ruff>=0.15.10",
]
[build-system]
badsecrets moves to the publishing policy's release flow (step 2 of the badsecrets cut-over; policy 1.8.0). Nothing publishes from this PR:
publish.ymlruns only on pushes tostable, andstabledoesn't exist until the rename (main -> stable) later in the plan.publish.yml: on push tostable, release-check (v1.5.0) -> tests -> build -> PyPI by trusted publishing from thereleaseenvironment (a lead approves) -> tag + GitHub release by the release App. No stored PyPI token.tests.ymlreplacestests.yaml: the shared Python tests (lint + 3.10-3.14 fromrequires-python, Codecov), callable frompublish.yml. No publish job, nopull_request_target, actions pinned to commits. Drops the old 3-attempt retry; if the suite is flaky in CI we'll see it here.stable-guard.yml,dev-security.yml(CodeQL, dependency review, workflow lint) on release-workflows v1.5.0.ruff==0.15.10in the dev group: the shared lint runs the project's ruff (same version CI pinned before). uv.lock adds ruff only.dependabot.yml: GitHub Actions updates too, grouped, 7-day cooldown, into dev..github/CODEOWNERS: a lead (development-leads or bbot-leads) approves changes to stable..github/secret_scanning.yml: ignoresbadsecrets/resources/**(the known-secrets corpus), so secret scanning and push protection can go on once this is on stable.cla.ymlis unchanged here (CLA rollout is separate). zizmor over the whole repo: 0 findings (dev today: 35); actionlint clean.