CI Integration
cmakefmt is designed to be a zero-friction CI step. Use --check to fail the
build when files are not formatted, or --in-place to auto-format and commit
the result.
GitHub Actions
Section titled “GitHub Actions”The official cmakefmt/cmakefmt-action installs the right binary for the
runner OS and adds it to PATH. No Rust toolchain required.
Check mode (recommended)
Section titled “Check mode (recommended)”Fail the workflow if any CMake files are not formatted:
- uses: cmakefmt/cmakefmt-action@v1 with: args: '--check .'Auto-format
Section titled “Auto-format”Format files in-place. Combine with a commit step to push the changes automatically:
- uses: cmakefmt/cmakefmt-action@v1 with: args: '--in-place .'Install only
Section titled “Install only”Install cmakefmt without running it, then call it yourself with custom flags:
- uses: cmakefmt/cmakefmt-action@v1 with: args: ''
- run: cmakefmt --check --report-format github .Pin a specific version
Section titled “Pin a specific version”- uses: cmakefmt/cmakefmt-action@v1 with: version: '0.2.0' args: '--check .'Full example
Section titled “Full example”name: Format check
on: [push, pull_request]
jobs: cmakefmt: runs-on: ubuntu-latest steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - uses: cmakefmt/cmakefmt-action@v1 with: args: '--check .'GitLab CI
Section titled “GitLab CI”Download the pre-built Linux binary directly from GitHub Releases:
cmakefmt: stage: lint image: ubuntu:latest before_script: - apt-get update -qq && apt-get install -y -qq curl - | LATEST=$(curl -sI https://github.com/cmakefmt/cmakefmt/releases/latest \ | grep -i '^location:' \ | sed 's|.*/tag/v||;s/[[:space:]]//g') curl -sSL \ "https://github.com/cmakefmt/cmakefmt/releases/download/v${LATEST}/cmakefmt-x86_64-unknown-linux-musl.tar.gz" \ | tar -xz -C /usr/local/bin script: - cmakefmt --check .Or install via Cargo if you already have a Rust image:
cmakefmt: stage: lint image: rust:latest cache: paths: - $CARGO_HOME/bin/ script: - cargo install cmakefmt-rust --quiet - cmakefmt --check .pre-commit
Section titled “pre-commit”Add a local hook to your .pre-commit-config.yaml. This runs cmakefmt --check
on every staged CMake file before the commit is created:
repos: - repo: local hooks: - id: cmakefmt name: cmakefmt language: system entry: cmakefmt --check files: '(CMakeLists\.txt|\.cmake)$' pass_filenames: trueInstall the hook once per clone:
pre-commit installYou can also run it manually across all files:
pre-commit run cmakefmt --all-filesCheck only changed files
Section titled “Check only changed files”When working on large repositories, limit formatting checks to files changed since a given ref to keep CI fast:
# Check files changed since the last tagcmakefmt --check --changed v0.1.0
# Check only staged files (useful locally)cmakefmt --check --staged