Skip to content

Merge pull request #701 from rokath/dependabot/github_actions/actions… #603

Merge pull request #701 from rokath/dependabot/github_actions/actions…

Merge pull request #701 from rokath/dependabot/github_actions/actions… #603

Workflow file for this run

name: Clang-Format Check
# This workflow verifies that all tracked C/C++ files in the repository
# are formatted according to the .clang-format rules.
#
# It uses:
# - clang-format (installed via apt)
# - a Go-based helper (cmd/clang-filter) via `go run`
# - the shell script `./scripts/_format_c_code.sh` to orchestrate everything
#
# The workflow runs:
# - on every push to any branch
# - on every pull request
on:
push:
branches:
- "**"
pull_request:
jobs:
clang-format-check:
runs-on: ubuntu-latest
steps:
#########################################################################
# 1) Check out the repository so we have access to:
# - source files
# - .clang-format
# - .clang-format-ignore
# - cmd/clang-filter
# - scripts/_format_c_code.sh
#########################################################################
- name: Check out repository
uses: actions/checkout@v7
with:
# Full git history is not strictly required for formatting,
# but some tools or future changes might rely on it.
fetch-depth: 0
#########################################################################
# 2) Install clang-format on the runner.
#
# We rely on Ubuntu's clang-format package. If you require a specific
# version, you can pin it here or use a prebuilt toolchain image.
#########################################################################
- name: Install clang-format
run: |
sudo apt-get update
sudo apt-get install -y clang-format
- name: Show clang-format version
run: clang-format --version
#########################################################################
# 3) Set up Go toolchain for `go run ./cmd/clang-filter`
#
# The Go helper uses github.com/sabhiram/go-gitignore to implement
# gitignore-style rules for .clang-format-ignore.
#########################################################################
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: false
# Optional but recommended: download all Go module dependencies up front.
# This avoids doing network fetches during `go run` and can speed up CI.
- name: Download Go modules
run: go mod download
#########################################################################
# 4) Run clang-format in CHECK mode via the shell script.
#
# The script:
# - collects tracked C/C++ files (git ls-files)
# - filters them via `go run ./cmd/clang-filter` using .clang-format-ignore
# - runs clang-format in CHECK mode (no in-place changes)
# - prints per-file errors using GitHub Actions "::error" annotations
# - fails the job (exit 1) if any file is misformatted
#########################################################################
- name: Run clang-format in check mode
run: |
chmod +x ./scripts/_format_c_code.sh
./scripts/_format_c_code.sh check