Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/advisories.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 23 additions & 2 deletions .github/workflows/caches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand Down
86 changes: 85 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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: .
Expand Down
35 changes: 34 additions & 1 deletion .github/workflows/commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)"
34 changes: 27 additions & 7 deletions .github/workflows/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
Loading
Loading