
Configuring .statci.yml, SARIF Code Scanning & GitHub Actions CI
Source:vignettes/github-actions-ci.Rmd
github-actions-ci.RmdThis vignette shows how to wire statci into reproducible
research repositories and R packages using declarative
.statci.yml project configuration,
statci_audit_project(), SARIF 2.1.0 GitHub Code Scanning
annotations, and hardened GitHub Actions workflows.
1. Declarative Project Configuration with
.statci.yml
read_statci_config() parses .statci.yml
with eval.expr = FALSE (preventing arbitrary R code
evaluation during YAML loading) and validates every rule ID, severity
override, relative path, report format, and CI gate setting:
tmp_proj <- tempfile("statci_ci_demo_")
dir.create(file.path(tmp_proj, "R"), recursive = TRUE)
dir.create(file.path(tmp_proj, "models"), recursive = TRUE)
# Write a clean analysis script and a saved model + manuscript
clean_src <- system.file("examples", "clean-analysis.R", package = "statci")
if (nzchar(clean_src)) {
file.copy(clean_src, file.path(tmp_proj, "R", "analysis.R"))
} else {
writeLines(c("set.seed(2026)", "x <- rnorm(50)"), file.path(tmp_proj, "R", "analysis.R"))
}
#> [1] TRUE
fit <- lm(mpg ~ wt, data = mtcars)
saveRDS(list(primary = fit), file.path(tmp_proj, "models", "fits.rds"))
writeLines(c(
"<!-- statci: model=primary term=wt -->",
"Vehicle weight predicted MPG (*b* = -5.34, SE = 0.56, *p* < .001, *N* = 32)."
), file.path(tmp_proj, "manuscript.qmd"))
writeLines(c(
"version: 1",
"lint:",
" paths: [R]",
" exclude_rules: [cor_without_use_arg]",
" severity_overrides:",
" short_logical_literal: error",
"manuscript:",
" path: manuscript.qmd",
" models: models/fits.rds",
"gate:",
" fail_on: fail",
"report:",
" title: \"Automated Study CI Audit\"",
" output_dir: statci-reports",
" formats: [html, markdown, sarif]"
), file.path(tmp_proj, ".statci.yml"))
cfg <- read_statci_config(file.path(tmp_proj, ".statci.yml"))
cfg
#> <statci_config> (source: .statci.yml)
#> lint paths: R
#> excluded rules: cor_without_use_arg
#> severity overrides: short_logical_literal=error
#> manuscript: manuscript.qmd (models: models/fits.rds)
#> gate fail_on: fail2. One-Call Project Orchestration
(statci_audit_project())
statci_audit_project() discovers
.statci.yml, runs AST linting with project severity
overrides, audits the configured manuscript, writes HTML/Markdown/SARIF
artifacts, and enforces the quality gate:
proj_rep <- statci_audit_project(tmp_proj, enforce_gate = TRUE)
proj_rep
#> [PASS] Automated Study CI Audit
#> [PASS] AST Statistical Linter: 1 file(s), 0 finding(s) (0 error, 0 warning, 0
#> info)
#> [PASS] Manuscript-to-Code Consistency: 4 claim(s) audited against 1 model(s); 0
#> sign flip(s)
basename(proj_rep$artifacts)
#> [1] "statci-report.html" "statci-report.md" "statci.sarif"3. SARIF 2.1.0 Export for GitHub Code Scanning
export_statci_sarif() converts AST lint diagnostics into
standard SARIF 2.1.0 JSON so findings appear directly as inline
annotations on pull-request diffs in GitHub Code Scanning:
flawed_lint <- stat_lint_text("x <- rnorm(10)\nm <- mean(x, na.rm = T)\n")
sarif_txt <- export_statci_sarif(flawed_lint)
sarif_obj <- jsonlite::fromJSON(sarif_txt)
list(
version = sarif_obj$version,
tool = sarif_obj$runs$tool$driver$name,
n_results = nrow(sarif_obj$runs$results[[1]])
)
#> $version
#> [1] "2.1.0"
#>
#> $tool
#> [1] "statci"
#>
#> $n_results
#> [1] 34. Generating Hardened GitHub Actions Workflows
use_statci_github_action() generates a security-hardened
.github/workflows/statci.yaml that: - Validates all branch
names, R versions, and project-relative paths against YAML/shell/R
injection; - Passes all configuration via workflow env:
variables with zero untrusted string interpolation in run:;
- Pins action versions and disables checkout credential persistence
(persist-credentials: false); - Optionally enables SARIF
2.1.0 upload to GitHub Code Scanning
(upload_sarif = TRUE).
wf <- use_statci_github_action(
path = tmp_proj,
branches = c("main"),
r_version = "release",
lint_paths = c("R"),
manuscript = "manuscript.qmd",
models_path = "models/fits.rds",
upload_sarif = TRUE
)
cat(head(readLines(wf), 34), sep = "\n")
#> # Generated by statci::use_statci_github_action()
#> name: statci Statistical CI/CD
#>
#> on:
#> push:
#> branches: ['main']
#> pull_request:
#> branches: ['main']
#> workflow_dispatch:
#>
#> permissions:
#> contents: read
#> security-events: write
#>
#> jobs:
#> statci-audit:
#> name: Statistical Verification & Audit
#> runs-on: ubuntu-latest
#> steps:
#> - name: Checkout repository
#> uses: actions/checkout@v4
#> with:
#> persist-credentials: false
#>
#> - name: Setup R
#> uses: r-lib/actions/setup-r@v2
#> with:
#> r-version: 'release'
#> use-public-rspm: true
#>
#> - name: Install R dependencies
#> uses: r-lib/actions/setup-r-dependencies@v2
#> with:
#> extra-packages: |
unlink(tmp_proj, recursive = TRUE)