Skip to content
Open
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
95 changes: 86 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,73 @@ env:
CARGO_TERM_COLOR: never

jobs:
changes:
name: changes
runs-on: ubuntu-24.04
outputs:
docs_only: ${{ steps.classify.outputs.docs_only }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
fetch-depth: 0
- id: classify
env:
EVENT: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
BEFORE: ${{ github.event.before }}
run: |
is_doc_path() {
case "$1" in
README.md|CHANGELOG.md|CONTRIBUTING.md|GLOSSARY.md|LICENSE|llms.txt)
return 0
;;
docs/reference.md|docs/checks/*|docs/agents/review-and-merge.md|docs/agents/security.md)
return 1
;;
docs/*.md)
return 0
;;
*)
return 1
;;
esac
}

if [ "$EVENT" = pull_request ]; then
range="origin/$BASE_REF...HEAD"
elif [ -n "$BEFORE" ] && [ "$BEFORE" != 0000000000000000000000000000000000000000 ] && git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
range="$BEFORE..HEAD"
else
echo "docs_only=false" >> "$GITHUB_OUTPUT"
exit 0
fi

if ! git diff --name-only --no-renames -z "$range" > "$RUNNER_TEMP/changed.bin"; then
echo "docs_only=false" >> "$GITHUB_OUTPUT"
exit 0
fi

count=0
docs_only=true
while IFS= read -r -d '' path; do
count=$((count + 1))
if ! is_doc_path "$path"; then
docs_only=false
break
fi
done < "$RUNNER_TEMP/changed.bin"

if [ "$count" -eq 0 ]; then
docs_only=false
fi

echo "docs_only=$docs_only" >> "$GITHUB_OUTPUT"
echo "Classified $count changed file(s): docs_only=$docs_only"

rust:
name: rust
needs: [changes]
if: ${{ !cancelled() && needs.changes.outputs.docs_only != 'true' }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
Expand All @@ -41,6 +106,8 @@ jobs:

windows:
name: windows
needs: [changes]
if: ${{ !cancelled() && needs.changes.outputs.docs_only != 'true' }}
runs-on: windows-2025
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
Expand All @@ -50,6 +117,8 @@ jobs:

performance:
name: performance
needs: [changes]
if: ${{ !cancelled() && needs.changes.outputs.docs_only != 'true' }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
Expand All @@ -59,6 +128,8 @@ jobs:

repository:
name: repository
needs: [changes]
if: ${{ !cancelled() }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
Expand All @@ -80,18 +151,24 @@ jobs:
else
echo "BASE=$(git rev-list --max-parents=0 HEAD | tail -n 1)" >> "$GITHUB_ENV"
fi
- run: cargo xtask no-comments --base "$BASE"
- if: needs.changes.outputs.docs_only != 'true'
run: cargo xtask no-comments --base "$BASE"
- run: cargo xtask commit-message --range "$BASE"
- run: npm run --silent duplicates
- if: needs.changes.outputs.docs_only != 'true'
run: npm run --silent duplicates
- run: npx --no-install markdownlint-cli2
- uses: ./.github/actions/lychee
- run: git ls-files -z '*.md' .rules ':!:.agents/skills/**' | xargs -0 lychee --config lychee.toml
- uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f
- if: needs.changes.outputs.docs_only != 'true'
uses: taiki-e/install-action@75a7c0f87bd666af3cdb75c5b9e9d03ab6044e6f
with:
tool: cargo-shear@1.14.1
- run: cargo shear
- uses: ./.github/actions/actionlint
- run: actionlint
- if: needs.changes.outputs.docs_only != 'true'
run: cargo shear
- if: needs.changes.outputs.docs_only != 'true'
uses: ./.github/actions/actionlint
- if: needs.changes.outputs.docs_only != 'true'
run: actionlint
- run: gitleaks git --redact --no-banner

risk-tier:
Expand Down Expand Up @@ -126,8 +203,8 @@ jobs:

budget:
name: budget
if: always() && github.event_name == 'pull_request'
needs: [rust, windows, performance, repository, risk-tier]
if: ${{ !cancelled() && github.event_name == 'pull_request' && needs.changes.outputs.docs_only != 'true' }}
needs: [changes, rust, windows, performance, repository, risk-tier]
runs-on: ubuntu-24.04
permissions:
actions: read
Expand Down Expand Up @@ -174,4 +251,4 @@ jobs:
run: |
report=()
if [ "$SAME_REPOSITORY" = true ]; then report=(--report); fi
cargo xtask feedback-budget --loop ci-gate --run-id "$RUN_ID" --exclude-job budget "${report[@]}"
cargo xtask feedback-budget --loop ci-gate --run-id "$RUN_ID" --exclude-job budget --exclude-workflow CodeQL "${report[@]}"
14 changes: 14 additions & 0 deletions .github/workflows/codeint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ name: codeint

on:
pull_request:
paths:
- '**'
- '!README.md'
- '!CHANGELOG.md'
- '!CONTRIBUTING.md'
- '!GLOSSARY.md'
- '!LICENSE'
- '!llms.txt'
- '!docs/*.md'
- '!docs/**/*.md'
- 'docs/reference.md'
- 'docs/checks/**'
- 'docs/agents/review-and-merge.md'
- 'docs/agents/security.md'

permissions:
contents: read
Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: CodeQL

on:
push:
branches: [main]
paths:
- '**'
- '!README.md'
- '!CHANGELOG.md'
- '!CONTRIBUTING.md'
- '!GLOSSARY.md'
- '!LICENSE'
- '!llms.txt'
- '!docs/*.md'
- '!docs/**/*.md'
- 'docs/reference.md'
- 'docs/checks/**'
- 'docs/agents/review-and-merge.md'
- 'docs/agents/security.md'
pull_request:
paths:
- '**'
- '!README.md'
- '!CHANGELOG.md'
- '!CONTRIBUTING.md'
- '!GLOSSARY.md'
- '!LICENSE'
- '!llms.txt'
- '!docs/*.md'
- '!docs/**/*.md'
- 'docs/reference.md'
- 'docs/checks/**'
- 'docs/agents/review-and-merge.md'
- 'docs/agents/security.md'
schedule:
- cron: '30 1 * * 1'

permissions: {}

concurrency:
group: codeql-${{ github.ref }}
cancel-in-progress: true

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-24.04
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: javascript-typescript
build-mode: none
- language: rust
build-mode: none
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- name: Initialize CodeQL
uses: github/codeql-action/init@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@1bd86f2fdb4b86187fa4059f16f31a3202acc9ea
with:
category: "/language:${{ matrix.language }}"
4 changes: 2 additions & 2 deletions docs/checks/feedback-budget.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ The budget file is the `feedback_budget` table in [checks.toml](../../checks.tom
At 80% of a budget it opens or updates one issue labelled `budget`; over the budget it fails.

**Runs in**:
CI, `budget` job of the `ci` workflow, on every pull request.
It times the Git hook on the changed files, `cargo xtask affected-tests`, and the wall clock across every gating workflow run on the pull request's head commit, excluding the `budget` job.
CI, `budget` job of the `ci` workflow, on every pull request that changes non-documentation files (skipped on docs-only pull requests).
It times the Git hook on the changed files, `cargo xtask affected-tests`, and the wall clock across every gating workflow run on the pull request's head commit, excluding the `budget` job and non-gating `CodeQL` workflow.
It opens or updates the `budget` issue only for pull requests from this repository, because a fork's token cannot write issues.

**Error text**:
Expand Down
22 changes: 20 additions & 2 deletions xtask/src/checks/budget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ fn workflow_key(run: &serde_json::Value) -> Option<String> {
})
}

pub(crate) fn gating_run_ids(
pub(crate) fn gating_run_ids_excluding(
primary_run: &serde_json::Value,
sha_runs: Option<&serde_json::Value>,
primary_run_id: &str,
excluded_workflows: &[String],
) -> Vec<String> {
let mut run_ids = vec![primary_run_id.to_string()];
if pull_request_head_sha(primary_run).is_none() {
Expand All @@ -169,6 +170,13 @@ pub(crate) fn gating_run_ids(
if run.get("conclusion").and_then(serde_json::Value::as_str) == Some("cancelled") {
continue;
}
if run
.get("name")
.and_then(serde_json::Value::as_str)
.is_some_and(|name| excluded_workflows.iter().any(|excluded| excluded == name))
{
continue;
}
let Some(id) = run.get("id").and_then(serde_json::Value::as_u64) else {
continue;
};
Expand All @@ -190,6 +198,15 @@ pub(crate) fn gating_run_ids(
run_ids
}

#[cfg(test)]
pub(crate) fn gating_run_ids(
primary_run: &serde_json::Value,
sha_runs: Option<&serde_json::Value>,
primary_run_id: &str,
) -> Vec<String> {
gating_run_ids_excluding(primary_run, sha_runs, primary_run_id, &[])
}

fn fetch_json(root: &Path, endpoint: &str, description: &str) -> Result<serde_json::Value, String> {
let output = gh(root, &["api", endpoint])?;
serde_json::from_str(&output).map_err(|error| format!("cannot parse {description}: {error}"))
Expand All @@ -198,6 +215,7 @@ fn fetch_json(root: &Path, endpoint: &str, description: &str) -> Result<serde_js
pub(crate) fn fetch_ci_gate_jobs(
root: &Path,
run_id: &str,
excluded_workflows: &[String],
) -> Result<Vec<serde_json::Value>, String> {
let primary_run = fetch_json(
root,
Expand All @@ -214,7 +232,7 @@ pub(crate) fn fetch_ci_gate_jobs(
)?),
None => None,
};
gating_run_ids(&primary_run, sha_runs.as_ref(), run_id)
gating_run_ids_excluding(&primary_run, sha_runs.as_ref(), run_id, excluded_workflows)
.iter()
.map(|id| {
fetch_json(
Expand Down
30 changes: 29 additions & 1 deletion xtask/src/checks/budget/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{
Verdict, ci_gate_seconds, gating_run_ids, parse_timestamp, pull_request_head_sha, verdict,
Verdict, ci_gate_seconds, gating_run_ids, gating_run_ids_excluding, parse_timestamp,
pull_request_head_sha, verdict,
};

#[test]
Expand Down Expand Up @@ -116,3 +117,30 @@ fn gating_run_ids_handles_pull_request_with_only_ci_run() {
vec!["400".to_string()]
);
}

#[test]
fn gating_run_ids_excludes_named_non_gating_workflows() {
let make_run = |id: u64, workflow_id: u64, name: &str, conclusion: Option<&str>| {
serde_json::json!({
"id": id,
"workflow_id": workflow_id,
"name": name,
"event": "pull_request",
"head_sha": "deadbeef",
"conclusion": conclusion,
})
};
let primary = make_run(500, 10, "ci", None);
let sha_runs = serde_json::json!({
"workflow_runs": [
make_run(500, 10, "ci", None),
make_run(501, 20, "pull-request", Some("success")),
make_run(502, 30, "CodeQL", Some("success")),
]
});
let excluded = vec!["CodeQL".to_string()];
assert_eq!(
gating_run_ids_excluding(&primary, Some(&sha_runs), "500", &excluded),
vec!["500".to_string(), "501".to_string()]
);
}
Loading