From cb6a88f4dfcc766db238a9b2c9abab5cf87c5410 Mon Sep 17 00:00:00 2001 From: rgdevment Date: Mon, 2 Nov 2026 21:51:30 -0300 Subject: [PATCH 1/2] ci: Tisty's branch names, staged pre-commit, runs cancelled on close, Rust jobs only for Rust, daily advisories --- .github/workflows/advisories.yml | 98 ++++++++++++++++++++++++++++++++ .github/workflows/caches.yml | 25 +++++++- .github/workflows/ci.yml | 86 +++++++++++++++++++++++++++- .github/workflows/commits.yml | 35 +++++++++++- .github/workflows/rules.yml | 34 ++++++++--- CONTRIBUTING.md | 21 ++++--- hooks/pre-commit | 38 +++++++++---- hooks/pre-push | 8 ++- package.json | 2 +- scripts/branches.sh | 27 +++++++++ scripts/commits.sh | 7 ++- scripts/rules.sh | 8 +++ 12 files changed, 354 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/advisories.yml create mode 100644 scripts/branches.sh diff --git a/.github/workflows/advisories.yml b/.github/workflows/advisories.yml new file mode 100644 index 00000000..4b645bf2 --- /dev/null +++ b/.github/workflows/advisories.yml @@ -0,0 +1,98 @@ +name: Advisories + +# An advisory or a yank lands on crates.io any day, and the first anyone heard of it was a red +# main. Every morning this reads the lock the way CI does and, when something fails, moves only +# the crates named to their newest compatible release and leaves the branch ready to open. +on: + schedule: + - cron: "37 6 * * *" + workflow_dispatch: + +permissions: {} + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +env: + CARGO_TERM_COLOR: never + BRANCH: build/advisories + +jobs: + moved: + name: the crates an advisory names move past it + runs-on: ubuntu-24.04 + timeout-minutes: 20 + permissions: + contents: write + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + ref: main + persist-credentials: false + + - name: Rust, from rust-toolchain.toml + run: rustup toolchain install --no-self-update + - uses: taiki-e/install-action@1e29709c0ec63babbe8f266397a465f29a825f91 # v2.87.31 + with: + tool: cargo-deny + + - name: Read the lock and move what it names + id: move + run: | + set -uo pipefail + if cargo deny --format json check advisories 2> "$RUNNER_TEMP/deny.json"; then + echo "Nothing in the lock has an advisory or a yank against it." + exit 0 + fi + mapfile -t named < <(jq -r 'select(.type == "diagnostic" and .fields.severity == "error") + | .fields.graphs[]?.Krate | "\(.name)@\(.version)"' "$RUNNER_TEMP/deny.json" | sort -u) + if [ "${#named[@]}" -eq 0 ]; then + cat "$RUNNER_TEMP/deny.json" + echo "::error::cargo-deny failed without naming a crate; read the log above." + exit 1 + fi + for one in "${named[@]}"; do + cargo update -p "$one" || echo "::warning::$one has no compatible release to move to" + done + if git diff --quiet Cargo.lock; then + echo "::error::no compatible release moves past ${named[*]}: it needs a hand, or an entry in deny.toml." + exit 1 + fi + if ! cargo deny check advisories; then + echo "::error::the lock moved but still fails; the branch was not pushed." + exit 1 + fi + crates=$(printf '%s\n' "${named[@]}" | sed 's/@.*//' | sort -u | paste -sd, - | sed 's/,/, /g') + echo "crates=$crates" >> "$GITHUB_OUTPUT" + + - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + if: steps.move.outputs.crates != '' + with: + node-version: 24 + package-manager-cache: false + + # the rules job refuses a lock the notices do not match, so they move with it. + - name: The notices the new lock carries + if: steps.move.outputs.crates != '' + run: | + npm ci --prefix app + npm run notices + + - name: Leave the branch ready + if: steps.move.outputs.crates != '' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + CRATES: ${{ steps.move.outputs.crates }} + run: | + set -euo pipefail + subject="build(deps): $CRATES past today's advisories" + [ "$(printf '%s' "$subject" | wc -m)" -le 110 ] || subject="build(deps): the crates past today's advisories" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git switch -c "$BRANCH" + git commit -qm "$subject" Cargo.lock THIRD-PARTY-BUNDLED.md THIRD-PARTY-LICENSES.md + git push -f "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "$BRANCH" + # red on purpose: main fails the same check until this is merged, and a red run is what reaches the inbox. + echo "::error::$subject — open it: https://github.com/${GITHUB_REPOSITORY}/compare/main...${BRANCH}?expand=1" + exit 1 diff --git a/.github/workflows/caches.yml b/.github/workflows/caches.yml index 34eaf8ab..ab790080 100644 --- a/.github/workflows/caches.yml +++ b/.github/workflows/caches.yml @@ -15,10 +15,29 @@ on: # zizmor: ignore[dangerous-triggers] neither job checks out the pull request type: boolean default: true -permissions: - contents: read +permissions: {} jobs: + # main runs CI again on the merge, and Mutants only ever measures a pull request, so nothing left running here is owed + stop: + name: a closed pull request stops what still runs for it + if: github.event_name == 'pull_request_target' + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + actions: write + steps: + - name: Every run still going for its last commit + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + gh run list --commit "$HEAD_SHA" --event pull_request --limit 100 --json databaseId,status --jq '.[] | select(.status != "completed") | .databaseId' | + while read -r run; do + gh run cancel "$run" || echo "::notice::run $run had already ended" + done + sweep: name: a closed pull request takes its caches with it permissions: @@ -36,6 +55,8 @@ jobs: generations: name: one generation of each cache, and nothing a tag left behind + # the branch filter on workflow_run reads the branch of the run that triggered it, and a + # fork's pull request can name its branch main: only a push to this repository counts if: >- github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || (github.event_name == 'workflow_run' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96622a44..04b99b7c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,55 @@ env: RUSTFLAGS: -D warnings jobs: + # anything not known to stay out of Rust's way counts as Rust, so a new path runs the whole suite + changes: + name: what the branch touched in Rust + runs-on: ubuntu-24.04 + timeout-minutes: 5 + outputs: + rust: ${{ steps.look.outputs.rust }} + window: ${{ steps.look.outputs.window }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + persist-credentials: false + fetch-depth: 0 + + - id: look + env: + EVENT: ${{ github.event_name }} + BASE: ${{ github.event.pull_request.base.sha }} + run: | + if [ "$EVENT" != "pull_request" ]; then + echo "rust=true" >> "$GITHUB_OUTPUT" + echo "window=true" >> "$GITHUB_OUTPUT" + exit 0 + fi + aside='^(app/src/|app/(biome\.json|index\.html|package(-lock)?\.json|stryker\.config\.json' + aside+='|tsconfig(\.node)?\.json|vite\.config\.ts)$|hooks/|packaging/|resources/|[^/]+\.md$' + aside+='|package(-lock)?\.json$|\.markdownlint(-cli2\.jsonc|\.yaml)$|\.editorconfig$|\.github/ISSUE_TEMPLATE/' + aside+='|\.github/(FUNDING|dependabot)\.yml$|\.github/(oversized\.txt|bridge-manifest\.json|v2-release-pubkey\.txt)$' + aside+='|\.github/workflows/(advisories|bundle|caches|cla|commits|feed|mutants|mutants-sweep|release|rules)\.yml$' + aside+='|scripts/(branches|commits|mutants-report|news|rules|sign_manifest|signed_for|verify_manifest)\.sh$' + aside+='|scripts/(fill_manifest|generations|mutants_cover|mutants_score|oversized|workflows_parse)\.py$' + aside+='|scripts/third-party\.mjs$|scripts/licences/)' + # the Rust reads these with include_str!, so they are Rust wherever they live + included='^(app/src/(news\.json|locales\.ts)|THIRD-PARTY-(BUNDLED|LICENSES)\.md)$' + from=$(git merge-base "$BASE" HEAD) + changed=$(git diff --name-only "$from" HEAD) + first=$( { echo "$changed" | grep -E "$included"; echo "$changed" | grep -vE "$aside"; } \ + | grep -v '^$' | head -1 || true) + [ -n "$first" ] && rust=true || rust=false + echo "rust=$rust" >> "$GITHUB_OUTPUT" + window=$rust + echo "$changed" | grep -qE '^app/' && window=true + echo "window=$window" >> "$GITHUB_OUTPUT" + echo "the first path Rust has to answer for: ${first:-none}" + check: name: test / ${{ matrix.os }} + needs: changes + if: needs.changes.outputs.rust == 'true' runs-on: ${{ matrix.os }} timeout-minutes: 45 strategy: @@ -55,6 +102,24 @@ jobs: - if: runner.os == 'Windows' run: cargo run -p cp-win --example win_probe + # a matrix job skipped by its if reports under its unexpanded name, so the ruleset asks this one instead + tests: + name: tests + if: always() + needs: [changes, check] + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - name: Every system passed, or the branch never touched what they test + env: + LOOKED: ${{ needs.changes.result }} + RUST: ${{ needs.changes.outputs.rust }} + RESULT: ${{ needs.check.result }} + run: | + [ "$LOOKED" = "success" ] || { echo "::error::what the branch touched could not be read ($LOOKED)"; exit 1; } + [ "$RESULT" = "success" ] || { [ "$RUST" = "false" ] && [ "$RESULT" = "skipped" ]; } \ + || { echo "::error::the tests ended as $RESULT"; exit 1; } + lint: name: fmt runs-on: ubuntu-24.04 @@ -109,6 +174,8 @@ jobs: cross: name: the macOS crates still build + needs: changes + if: needs.changes.outputs.rust == 'true' runs-on: ubuntu-24.04 timeout-minutes: 20 steps: @@ -135,9 +202,19 @@ jobs: with: persist-credentials: false - uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2 + with: + command: check bans licenses sources + # an advisory published today is no fault of the branch: the daily Advisories run moves the lock past it + - uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2 + continue-on-error: ${{ github.event_name == 'pull_request' }} + with: + command: check advisories coverage: name: coverage + needs: changes + # a dependency bump changes no line of ours, so it pays for neither coverage nor Sonar + if: github.actor != 'dependabot[bot]' && needs.changes.outputs.window == 'true' runs-on: macos-15 timeout-minutes: 45 steps: @@ -197,6 +274,8 @@ jobs: coverage-windows: name: coverage / the Windows crates + needs: changes + if: github.actor != 'dependabot[bot]' && needs.changes.outputs.rust == 'true' runs-on: windows-2025 timeout-minutes: 45 steps: @@ -241,8 +320,12 @@ jobs: needs: [coverage, coverage-windows] runs-on: ubuntu-24.04 timeout-minutes: 15 + # a branch that only touched the window measured no Windows crate, and Sonar reads what there is if: >- - github.actor != 'dependabot[bot]' + always() + && needs.coverage.result == 'success' + && contains(fromJSON('["success", "skipped"]'), needs.coverage-windows.result) + && github.actor != 'dependabot[bot]' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) steps: @@ -257,6 +340,7 @@ jobs: path: . - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + if: needs.coverage-windows.result == 'success' with: name: coverage-windows path: . diff --git a/.github/workflows/commits.yml b/.github/workflows/commits.yml index b73d1662..b058832d 100644 --- a/.github/workflows/commits.yml +++ b/.github/workflows/commits.yml @@ -12,8 +12,41 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: + # Dependabot's group titles run past the length a title may reach main with, and it cannot be + # told to write shorter ones. An edit made with this token starts no new run, so the check + # below reads the title from here rather than from the event. + retitle: + name: A title Dependabot wrote, cut to fit + if: github.event.pull_request.user.login == 'dependabot[bot]' + runs-on: ubuntu-24.04 + timeout-minutes: 5 + permissions: + pull-requests: write + outputs: + title: ${{ steps.cut.outputs.title }} + steps: + - id: cut + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + TITLE: ${{ github.event.pull_request.title }} + NUMBER: ${{ github.event.pull_request.number }} + run: | + fits() { [ "$(printf '%s (#%s)' "$1" "$NUMBER" | wc -m)" -le 120 ]; } + short=$(printf '%s' "$TITLE" | sed -E 's/ across [0-9]+ director(y|ies)//') + fits "$short" || short=$(printf '%s' "$short" | sed -E 's/ from [^ ]+ to [^ ]+//') + fits "$short" || short=$(printf '%s' "$short" | sed -E 's/^([a-z]+(\([a-z-]+\))?: bump) .* in the ([^ ]+) group.*/\1 the \3 group/') + if [ "$short" != "$TITLE" ]; then + gh pr edit "$NUMBER" --title "$short" + echo "«$TITLE» is now «$short»" + fi + echo "title=$short" >> "$GITHUB_OUTPUT" + conventional: name: Conventional commit messages + needs: retitle + # skipped for everyone but Dependabot, and a failed cut leaves the long title to fail below + if: always() runs-on: ubuntu-24.04 timeout-minutes: 10 steps: @@ -31,6 +64,6 @@ jobs: # a squash keeps the pull request's title and drops every subject above it - name: And so does the title that the squash will keep env: - TITLE: ${{ github.event.pull_request.title }} + TITLE: ${{ needs.retitle.outputs.title || github.event.pull_request.title }} NUMBER: ${{ github.event.pull_request.number }} run: bash scripts/commits.sh --title "$TITLE (#$NUMBER)" diff --git a/.github/workflows/rules.yml b/.github/workflows/rules.yml index 7ea4dd71..6de2c8ba 100644 --- a/.github/workflows/rules.yml +++ b/.github/workflows/rules.yml @@ -41,18 +41,39 @@ jobs: with: go-version: "1.25" cache: false + # offline, so a pull request is judged on its own lines and never on whether GitHub's API answered - name: The workflows mean what they say env: - GH_TOKEN: ${{ github.token }} SHELLCHECK_OPTS: --severity=warning run: | go install github.com/rhysd/actionlint/cmd/actionlint@v1.7.12 "$(go env GOPATH)/bin/actionlint" - zizmor --min-severity medium .github + zizmor --offline --min-severity medium .github + + - name: No action pinned here is an impostor or has a known vulnerability + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + env: + GH_TOKEN: ${{ github.token }} + run: | + set -uo pipefail + # zizmor exits 1 only when it could not finish; findings exit 10 or more and are not retried + for try in 1 2 3; do + code=0 + zizmor --min-severity medium .github || code=$? + [ "$code" -ne 1 ] && exit "$code" + echo "::warning::try $try did not finish; asking GitHub again in a minute" + sleep 60 + done + exit 1 - name: Project conventions run: bash scripts/rules.sh + # nothing else looks at a subject that reached main without a pull request + - name: The subject that landed + if: github.event_name == 'push' + run: bash scripts/commits.sh --title "$(git log -1 --format=%s)" + notices: name: The notices match the lockfiles runs-on: ubuntu-24.04 @@ -84,8 +105,11 @@ jobs: exit 1 fi + # one turn of the suite is what CI already runs on every pull request, so this job only earns its + # runners when it runs the twenty that say whether a test is deterministic deterministic: name: Tests are deterministic (${{ matrix.os }}) + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' runs-on: ${{ matrix.os }} timeout-minutes: 45 strategy: @@ -110,11 +134,7 @@ jobs: tool: nextest - name: The core, over and over run: | - turns=4 - if [ "${GITHUB_EVENT_NAME}" = "schedule" ] || [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then - turns=20 - fi - for _ in $(seq 1 "$turns"); do + for _ in $(seq 1 20); do cargo nextest run -p cp-core --no-tests=pass || exit 1 done diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0d6e9ec3..7d5cfad7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,7 +49,7 @@ In many ways! Code is just one of them: ### Contribute Code 1. **Fork** the repository -2. **Create a branch** from `main` (`git checkout -b feature/my-improvement`) +2. **Create a branch** from `main` (`git checkout -b feat/my-improvement`) 3. **Make your changes** following our style: - Clean and minimalist code - Code and identifiers in English @@ -132,11 +132,12 @@ them run for you: git config core.hooksPath hooks ``` -That gives you three. `pre-commit` runs the conventions, `cargo fmt --all ---check` and biome — a couple of seconds, and between them they are most of what +That gives you three. `pre-commit` runs the conventions, the branch's name, +`cargo fmt --all --check` and biome — a couple of seconds, and between them they are most of what turns CI red. `commit-msg` weighs the message while the fix is still an -`--amend` rather than a rebase. `pre-push` runs the conventions again and the -messages of everything you are about to send, and when what you are sending is a +`--amend` rather than a rebase. `pre-push` runs the conventions again, the name +each branch takes on the remote and the messages of everything you are about to +send, and when what you are sending is a tag it asks `scripts/news.sh` whether `app/src/news.json` says what changed in that version — the screen that tells a person what is new is the only place the app says it, and a tag is the last moment to notice it is empty. A candidate is @@ -156,14 +157,20 @@ type(scope): the concrete change - **Types:** `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`. The scope is optional. -- **At most 120 characters.** +- **At most 112 characters**, and 120 for the title with its `(#123)`. - **No body and no trailers** — no `Co-authored-by`, no `Signed-off-by`. The CLA below is signed once on the pull request, not on each commit. - **No links**, except `#123` for an issue or pull request of this repository. - Say what changed, not how it was found. A pull request's title follows the same rule, because the squash keeps it as -the subject on `main`. +the subject on `main`, and GitHub adds ` (#123)` after it: a commit's subject +stops eight characters short so the title still fits. + +A branch says the same thing before its first commit: `kind/what`, in lowercase, +where the kind is one of the types above or `hotfix` or `release`, as in +`feat/search-ranking` or `fix/tokio-yanked`. `scripts/branches.sh` holds that +shape. **UI/UX:** diff --git a/hooks/pre-commit b/hooks/pre-commit index 6751d303..e4e2f4bb 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -4,15 +4,16 @@ set -uo pipefail cd "$(git rev-parse --show-toplevel)" || exit 0 status=0 -# every tool below reads the working tree, not the index, so with anything unstaged what passes -# here is not what is about to be committed. Checking the index would mean a throwaway worktree -# per commit; saying so costs nothing. -if ! git diff --quiet; then - printf '! tracked files differ from what is staged: these checks describe your working tree,\n' - printf '! not the commit you are making\n' -fi +# what is about to be committed, not what the working tree happens to hold beside it +staged=$(mktemp -d) +trap 'rm -rf "$staged"' EXIT +git checkout-index --all --prefix="$staged/" || { + echo "x the staged tree could not be written out, so nothing was looked at" + exit 1 +} -bash scripts/rules.sh || status=1 +bash "$staged/scripts/rules.sh" < /dev/null || status=1 +bash "$staged/scripts/branches.sh" "$(git rev-parse --abbrev-ref HEAD)" || status=1 quietly() { local said @@ -24,16 +25,29 @@ quietly() { } if command -v cargo > /dev/null; then - quietly "cargo fmt --all --check" "cargo fmt --all would change files" + quietly "cd \"$staged\" && cargo fmt --all --check" "cargo fmt --all would change files" + # the probe bodies are included, not modules, so cargo fmt --all never reaches them + quietly "cd \"$staged\" && rustfmt --check --edition 2024 crates/cp-mac/examples/probe/battery.rs crates/cp-win/examples/probe/battery.rs crates/cp-win/examples/probe/restoring.rs" \ + "rustfmt would change the probe bodies" else - echo "x cargo is not here, so the formatting was not looked at" + echo "! cargo is not here, so the formatting was not looked at" fi if [ -d app/node_modules ]; then - quietly "cd app && npx --no-install biome check src" \ + quietly "cd \"$staged/app\" && \"$PWD/app/node_modules/.bin/biome\" check src" \ "biome would change files, or is not installed; it is the first thing CI runs" else - echo "x app/node_modules is not here, so biome did not look at the window" + echo "! app/node_modules is not here, so biome did not look at the window" +fi + +# the rules job refuses a lockfile the notices do not follow; written here, the fix is one git add away +if git diff --cached --name-only | grep -qE '(^|/)(Cargo\.lock|package-lock\.json)$'; then + if [ -d app/node_modules ]; then + quietly "node scripts/third-party.mjs > /dev/null && git diff --quiet -- THIRD-PARTY-BUNDLED.md THIRD-PARTY-LICENSES.md" \ + "the notices were behind the lockfiles; npm run notices just wrote them, so stage them" + else + echo "! app/node_modules is not here, so the notices were not checked against the lockfiles" + fi fi exit $status diff --git a/hooks/pre-push b/hooks/pre-push index 503c98d3..18275e83 100755 --- a/hooks/pre-push +++ b/hooks/pre-push @@ -3,13 +3,17 @@ set -uo pipefail cd "$(git rev-parse --show-toplevel)" || exit 0 -bash scripts/rules.sh || exit 1 +bash scripts/rules.sh < /dev/null || exit 1 nothing=0000000000000000000000000000000000000000 status=0 -while read -r ref mine _ _; do +while read -r ref mine where _; do [ -n "${mine:-}" ] || continue [ "$mine" != "$nothing" ] || continue + # the name it takes on the remote, which is the one everybody sees + case ${where:-} in + refs/heads/*) bash scripts/branches.sh "${where#refs/heads/}" || status=1 ;; + esac # a tag carries no subjects of its own, and it is the last moment to notice that the version # it names has nothing to tell the person who installs it diff --git a/package.json b/package.json index 552d6218..b6efd3a9 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "smol-toml": "^1.9.0" }, "scripts": { - "prepare": "git config core.hooksPath hooks || echo the hooks are not set: this is not a git clone", + "prepare": "git config --get core.hooksPath || git config core.hooksPath hooks || echo the hooks are not set: this is not a git clone", "lint:md": "markdownlint-cli2", "format:md": "markdownlint-cli2 --fix", "notices": "node scripts/third-party.mjs" diff --git a/scripts/branches.sh b/scripts/branches.sh new file mode 100644 index 00000000..c8fb5ebd --- /dev/null +++ b/scripts/branches.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -uo pipefail + +kinds='feat|fix|chore|docs|refactor|test|perf|build|ci|style|revert|hotfix|release' +shape="^($kinds)/[a-z0-9][a-z0-9._/-]*$" +status=0 + +amiss() { + if [ -n "${GITHUB_ACTIONS:-}" ]; then + printf '::error::%s\n' "$1" + else + printf 'x %s\n' "$1" + fi + status=1 +} + +# A branch says what kind of change it carries, the way its commits do; main and a detached head say nothing. +for name in "$@"; do + case $name in + main | HEAD | "") continue ;; + esac + if ! printf '%s' "$name" | grep -qE "$shape"; then + amiss "the branch $name is not named kind/what, with kind one of: ${kinds//|/, }" + fi +done + +exit $status diff --git a/scripts/commits.sh b/scripts/commits.sh index 833df0c8..b189bc7a 100755 --- a/scripts/commits.sh +++ b/scripts/commits.sh @@ -54,12 +54,15 @@ weighed() { broke=1 amiss "$who links outside this repository; only #123 of this one" fi + # a subject becomes the squash title, and GitHub ends that with " (#1234)", so it leaves the room + local room=$most + [ -n "$strict" ] || room=$((most - 8)) # bytes minus UTF-8 continuation bytes: ${#said} counts bytes when a client spawns git with no locale local long long=$(printf '%s' "$said" | LC_ALL=C tr -d '\200-\277' | wc -c | tr -d ' ') - if [ "$long" -gt "$most" ]; then + if [ "$long" -gt "$room" ]; then broke=1 - amiss "$who is $long characters, and the subject goes under $most" + amiss "$who is $long characters, and the subject goes under $room" fi [ -z "$broke" ] || printf ' %s\n' "$said" } diff --git a/scripts/rules.sh b/scripts/rules.sh index 7f17f186..3d349d15 100755 --- a/scripts/rules.sh +++ b/scripts/rules.sh @@ -106,6 +106,13 @@ every_example_has_its_own_name() { fi } +# a signing key, a token or a minisign secret in the tree is public the moment it is pushed +no_secret_kept_in_the_tree() { + local secret='gh[pousr]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{60,}|-----BEGIN ((RSA|EC|DSA|OPENSSH|ENCRYPTED) )?PRIVATE KEY-----|rsign encrypted secret[ ]key|sqp_[0-9a-f]{40}' + grep -rnIE "$secret" crates app/src app/src-tauri scripts .github packaging hooks --exclude-dir=target --exclude-dir=node_modules + found_nothing "a token or a private key is in the tree; it belongs in the repository's secrets" $? "the tree could not be looked through for secrets" && went_well "no token or private key is kept in the tree" +} + what_python_measures() { local why=$1 said shift @@ -129,6 +136,7 @@ written_in_english tests_named_in_english no_comments_in_the_code every_example_has_its_own_name +no_secret_kept_in_the_tree what_python_measures "the tests live beside the file, not inside it" oversized.py --inline what_python_measures "no file or function grows past what a person can hold" oversized.py what_python_measures "no crate slips out of mutation" mutants_cover.py From f1d754481caca5e0735e58ac5af3da94c16e513d Mon Sep 17 00:00:00 2001 From: rgdevment Date: Mon, 2 Nov 2026 22:35:56 -0300 Subject: [PATCH 2/2] docs(contributing): the number GitHub adds to a title is no longer a code span that opens with a space --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7d5cfad7..f9dc974e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -164,8 +164,8 @@ type(scope): the concrete change - Say what changed, not how it was found. A pull request's title follows the same rule, because the squash keeps it as -the subject on `main`, and GitHub adds ` (#123)` after it: a commit's subject -stops eight characters short so the title still fits. +the subject on `main`, and GitHub adds a space and `(#123)` after it: a commit's +subject stops eight characters short so the title still fits. A branch says the same thing before its first commit: `kind/what`, in lowercase, where the kind is one of the types above or `hotfix` or `release`, as in