Skip to content
b1stedPublic

About

Reusable GitHub Actions workflows and composite actions for C projects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

b1sted/ci

Shared GitHub Actions workflows and composite actions for C projects.

Release Version License

Features • Workflows • Actions • Repository contract • packages.basted.dev • Security • License


Opinionated, reusable CI/CD pipelines for C projects built around a strict GNU make contract. Designed to eliminate workflow duplication across repositories while keeping multi-platform builds, package generation, provenance attestation, and release signing deterministic.

Features

  • Customisable CI (c-ci.yml): native test matrices for Linux amd64/arm64/riscv64 and macOS arm64/Intel, selectable compilers, configurable build/test/leaks/lint/dev commands, optional QEMU cross-tests per architecture, and project-specific smoke-verification hooks.
  • Heavy verification (c-verify.yml): a separate reusable workflow for full diagnostics and profiling on Linux and macOS. It writes the useful reports to the job summary and always uploads the report directory.
  • Customisable releases (c-release.yml): every release target is an independent boolean flag. The default preserves the historical full release (Linux amd64/arm64/armv7/riscv64, Luckfox, Termux, macOS Intel/Apple Silicon, Linux packages, attestations), while a project can disable any fragile or optional target with one input.
  • Containerized glibc Baseline: builds Linux release binaries inside an ubuntu:22.04 container (glibc 2.35) on ubuntu-24.04 runners for broad distribution compatibility. The image is configurable.
  • Automated Packaging & Verification: generates .tar.gz archives, Termux .deb packages, and Linux .deb, .rpm, and .pkg.tar.zst packages via nfpm, verifying package metadata and running container smoke tests before publishing. Disabled architectures are skipped without failing the release.
  • Decoupled Infrastructure: GPG signing, Homebrew tap updates, and package repository rebuild dispatches are configured strictly via caller inputs and optional secrets—no personal keys or repository names are hardcoded in the workflows.
  • Backward compatible: existing callers that only pass the old inputs keep the old behaviour. New inputs have defaults that match the previous workflows.

Workflows

c-ci.yml

Runs build, unit tests, memory sanitizer checks, formatting, and static analysis. The native matrix is generated at runtime, so a disabled runner or compiler is not even scheduled.

name: Tests and Linters

on:
  push:
    branches:
      - main
      - dev
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

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

jobs:
  ci:
    uses: b1sted/ci/.github/workflows/c-ci.yml@v1
    with:
      enable_cross_tests: true
      bin_path: build/bin/mytool
      cross_test_args: selftest --no-timing
      linux_apt_packages: libssl-dev
      linux_verify_cmd: ./tools/verify/linux.sh smoke
      macos_verify_cmd: ./tools/verify/macos.sh smoke
      verify_artifacts_path: results

Jobs

Job Runner Description
prepare ubuntu-24.04 Builds the native and cross-test matrices. Skips jobs when no target is enabled.
unit-tests Selected native runners Builds and runs the configured test command for every enabled target and compiler.
cross-tests ubuntu-24.04 Optional QEMU user-mode execution for the enabled cross architectures.
leaks ubuntu-24.04 Runs the configured leak/sanitizer command (enabled by default).
leaks-macos macos_arm64_runner Optional macOS sanitizer run (disabled by default).
lint ubuntu-24.04 Runs the configured lint command with CLANG_FORMAT set (enabled by default).

Inputs

Input Required Default Description
enable_cross_tests No false Enables the QEMU cross-tests job.
bin_path No "" Path to the built binary (required when cross-tests are enabled).
cross_test_args No "selftest" Arguments passed to the binary under QEMU.
clang_format_bin No "clang-format-18" clang-format executable exported as CLANG_FORMAT.
lint_packages No "clang-format-18 clang-tidy cppcheck" Space-separated apt packages installed for lint.
build_cmd No "make" Build command. Runs with CC set; make ... also receives CC=... on the command line.
test_cmd No "make test" Test command. Same CC handling as build_cmd.
leaks_cmd No "make leaks" Leak/sanitizer command. Same CC handling as build_cmd.
lint_cmd No "make lint" Lint command. CLANG_FORMAT is exported.
enable_dev No false Runs dev_cmd after the tests.
dev_cmd No "make dev" Development build command. Same CC handling as build_cmd.
enable_leaks No true Enables the Linux leaks job.
enable_macos_leaks No false Enables the macOS leaks-macos job.
enable_lint No true Enables the lint job.
enable_gcc No true Adds GCC to the native Linux matrix.
enable_clang No true Adds Clang to the native Linux matrix and enables macOS targets.
linux_apt_packages No "" Extra apt packages installed in every Linux job; missing make, the selected compiler, and libc headers are installed automatically.
enable_linux_amd64 No true Enables the Linux amd64 native target.
linux_amd64_runner No "ubuntu-24.04" Runner label for Linux amd64.
enable_linux_arm64 No false Enables the Linux arm64 native target.
linux_arm64_runner No "ubuntu-24.04-arm" Runner label for Linux arm64.
enable_linux_riscv64 No false Enables the Linux riscv64 native target.
linux_riscv64_runner No "ubuntu-24.04-riscv" Runner label for Linux riscv64.
enable_macos_arm64 No true Enables the macOS Apple Silicon native target.
macos_arm64_runner No "macos-15" Runner label for macOS arm64.
enable_macos_intel No false Enables the macOS Intel native target.
macos_intel_runner No "macos-15-intel" Runner label for macOS Intel.
linux_verify_cmd No "" Optional project smoke command run after the Linux unit tests.
macos_verify_cmd No "" Optional project smoke command run after the macOS unit tests.
verify_artifacts_path No "" If set, uploads this path from the primary compiler job of each enabled native target with if: always().
cross_aarch64 No true Includes aarch64 in the cross-test matrix when enable_cross_tests is true.
cross_armv7 No true Includes armv7 in the cross-test matrix when enable_cross_tests is true.
cross_riscv64 No true Includes riscv64 in the cross-test matrix when enable_cross_tests is true.
cross_build_cmd No "" Custom cross-build command. Empty falls back to make CC=<cross>-gcc.

CC handling: a command that starts with make and does not already contain CC= receives CC=<selected compiler> on the command line. This preserves the old behaviour for Makefiles that assign CC unconditionally. Every command also runs with CC in the environment, so custom commands can read it. A custom command that already contains CC= is used verbatim.

On Linux, the workflows use actions/setup-linux-toolchain to ensure make, the selected compiler, libc headers, and linux_apt_packages are present. This requires an apt-based runner (Debian/Ubuntu). macOS runners must provide the Xcode Command Line Tools; the workflows check for them and fail with an actionable message instead of a missing-compiler error.


c-verify.yml

A reusable workflow for heavy diagnostics and profiling. It is not part of c-release.yml; projects call it from a manual or scheduled workflow. Each selected target runs a project-provided command, writes env.txt, auto.txt, perf-probes.csv, perf-stability.csv, and summary.log to the job summary when they exist, and always uploads the report directory.

name: Full diagnostics

on:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  verify:
    uses: b1sted/ci/.github/workflows/c-verify.yml@v1
    with:
      enable_linux_amd64: true
      enable_linux_arm64: true
      enable_macos_arm64: true
      linux_apt_packages: >-
        build-essential clang clang-format clang-tidy cppcheck python3
        util-linux bsdutils file
      linux_cmd: ./tools/verify/linux.sh full
      macos_cmd: ./tools/verify/macos.sh full
      results_path: results
      timeout_minutes: 45

Inputs

Input Required Default Description
enable_linux_amd64 No true Enables Linux amd64.
linux_amd64_runner No "ubuntu-24.04" Runner label for Linux amd64.
enable_linux_arm64 No false Enables Linux arm64.
linux_arm64_runner No "ubuntu-24.04-arm" Runner label for Linux arm64.
enable_linux_riscv64 No false Enables Linux riscv64.
linux_riscv64_runner No "ubuntu-24.04-riscv" Runner label for Linux riscv64.
enable_macos_arm64 No true Enables macOS Apple Silicon.
macos_arm64_runner No "macos-15" Runner label for macOS arm64.
linux_apt_packages No "" Extra apt packages installed before the Linux command; make is installed automatically when missing.
linux_cmd No "./tools/verify/linux.sh full" Command run on every selected Linux target.
macos_cmd No "./tools/verify/macos.sh full" Command run on macOS.
results_path No "results" Report directory to summarize and upload.
timeout_minutes No 45 Job timeout for every verification target.

The workflow deliberately does not run brew install. macOS uses the tools that are already present on the runner, which keeps the Apple Silicon jobs fast and avoids building LLVM/Python from source.


c-release.yml

Runs c-ci.yml, builds the enabled release targets, packages archives and Linux/Termux packages, verifies outputs, signs checksums, attests build provenance, publishes the GitHub Release, and optionally updates a Homebrew tap and triggers a package repository dispatch.

name: Release

on:
  push:
    tags:
      - 'v*.*'

permissions:
  contents: write
  id-token: write
  attestations: write

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: false

jobs:
  release:
    uses: b1sted/ci/.github/workflows/c-release.yml@v1
    with:
      pkg_name: mytool
      bin_path: bin/mytool
      version_flag: "-V"
      homepage: https://github.com/owner/mytool
      description: Short one-line description of the project.
      license: GPL-3.0
      maintainer: Name <mail@example.com>
      gpg_fingerprint: "0123456789ABCDEF0123456789ABCDEF01234567"
      homebrew_tap: owner/homebrew-tap
      packages_dispatch_repo: owner/packages.basted.dev
    secrets:
      GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
      GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
      HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
      PACKAGES_DISPATCH_TOKEN: ${{ secrets.PACKAGES_DISPATCH_TOKEN }}

Common inputs

Input Required Default Description
pkg_name Yes — Binary and package name.
bin_path Yes — Path to the compiled binary relative to the repository root.
version_flag No "-V" CLI flag used for smoke testing built binaries.
homepage Yes — Project homepage URL used in package metadata.
description Yes — Short package description.
license Yes — SPDX license identifier (for example MIT or GPL-3.0).
maintainer Yes — Package maintainer in "Name <email>" format.
homebrew_tap No "" Target owner/repo Homebrew tap. Skips update-homebrew when empty.
homebrew_template No "packaging/homebrew.rb.in" Path to the Homebrew formula template in the calling repository.
nfpm_config No "nfpm.yaml" Path to custom nfpm config; auto-generated if the file does not exist.
nfpm_binary No "dynamic" Preferred binary variant packaged by nfpm (dynamic or static). Falls back to the other variant when the preferred one is disabled or missing.
gpg_fingerprint No "" Optional GPG key or subkey fingerprint (uses imported key default when empty).
packages_dispatch_repo No "" Target owner/repo for repository_dispatch. Skips signal-packages when empty.
packages_dispatch_event No "new-release" Event type sent to packages_dispatch_repo.
skip_tests No false Skips the internal c-ci.yml call. The release still requires at least one build artifact.

CI passthrough inputs

These are forwarded to c-ci.yml: enable_cross_tests, cross_test_args, clang_format_bin, lint_packages, build_cmd, test_cmd, leaks_cmd, lint_cmd, enable_dev, dev_cmd, enable_leaks, enable_macos_leaks, enable_lint, enable_gcc, enable_clang, linux_apt_packages, linux_verify_cmd, macos_verify_cmd, verify_artifacts_path, cross_aarch64, cross_armv7, cross_riscv64, and cross_build_cmd.

The native test matrix is configured separately from the release targets, because the release builds arm64/riscv64 by default while the test matrix historically runs only Linux amd64 and macOS arm64:

Input Default Description
ci_enable_linux_amd64 true Linux amd64 test target.
ci_linux_amd64_runner "ubuntu-24.04" Linux amd64 test runner.
ci_enable_linux_arm64 false Linux arm64 test target.
ci_linux_arm64_runner "ubuntu-24.04-arm" Linux arm64 test runner.
ci_enable_linux_riscv64 false Linux riscv64 test target.
ci_linux_riscv64_runner "ubuntu-24.04-riscv" Linux riscv64 test runner.
ci_enable_macos_arm64 true macOS Apple Silicon test target.
ci_macos_arm64_runner "macos-15" macOS arm64 test runner.
ci_enable_macos_intel false macOS Intel test target.
ci_macos_intel_runner "macos-15-intel" macOS Intel test runner.

Release target inputs

Input Default Description
enable_linux_amd64 true Build Linux amd64.
enable_linux_arm64 true Build Linux arm64.
enable_linux_armv7 true Build Linux armv7.
enable_linux_riscv64 true Build Linux riscv64. Disable this single flag to drop the riscv64 toolchain, packages, and archive.
enable_linux_static true Build the static Linux binary.
enable_linux_dynamic true Build the dynamic Linux binary.
linux_container_image "ubuntu:22.04" Build container for Linux binaries.
enable_luckfox true Build the Luckfox Pico uClibc binary.
enable_termux true Build all Termux packages (aarch64, arm, x86_64).
termux_arm64_runner "ubuntu-24.04-arm" Runner for the Termux aarch64 image.
enable_macos_intel true Build macOS Intel binaries.
enable_macos_intel_legacy true Also build the macOS 10.7 legacy Intel binary.
macos_intel_runner "macos-15-intel" Runner for macOS Intel.
enable_macos_arm64 true Build the macOS Apple Silicon binary.
macos_arm64_runner "macos-15" Runner for macOS arm64.
enable_linux_packages true Build and verify .deb, .rpm, and .pkg.tar.zst packages with nfpm.
enable_attestations true Attach GitHub build provenance with actions/attest.

Release behaviour

  • release runs when test and every enabled build job succeeded or was skipped. The condition uses !cancelled() and (needs.<job>.result == 'success' || needs.<job>.result == 'skipped'), so disabling one target does not suppress the release.
  • signal-packages runs only when needs.release.result == 'success', the tag is not a pre-release, and packages_dispatch_repo is set.
  • update-homebrew runs only when needs.release.result == 'success', the tag is not a pre-release, and homebrew_tap is set.
  • If an architecture is disabled, its artifact is not required. Archive packing, nfpm packaging, the amd64 Docker smoke test, and Termux package collection all check for files before using them.
  • Archive names are unchanged: linux-amd64, linux-arm64, linux-armv7, linux-riscv64, linux-luckfox, macos-arm64, macos-intel-legacy, macos-intel-modern, and android-termux-*.

Secrets

All secrets are optional. Features requiring omitted secrets are skipped gracefully.

Secret Used by Description
GPG_PRIVATE_KEY release, update-homebrew ASCII-armored GPG private key for signing SHA256SUMS.txt and tap commits.
GPG_PASSPHRASE release, update-homebrew Passphrase for GPG_PRIVATE_KEY.
HOMEBREW_TAP_TOKEN update-homebrew GitHub token with write access to homebrew_tap.
PACKAGES_DISPATCH_TOKEN signal-packages GitHub token with write access to packages_dispatch_repo.

Actions

Reusable composite actions live under actions/ and can also be referenced independently:

Action Description
actions/install-nfpm Downloads nfpm (2.49.0 by default) and verifies both checksums.txt and the archive SHA-256 digest.
actions/setup-linux-toolchain Ensures make, the selected compiler, libc headers, and extra apt packages are present; only installs what is missing.
actions/setup-luckfox-sdk Sparsely fetches and caches the Luckfox Pico uClibc ARM cross-compiler toolchain.
actions/setup-macos-sdk Downloads and caches MacOSX10.11.sdk for legacy macOS Intel builds (x86_64-apple-macos10.7).
actions/termux-package Builds, smoke-tests, packages, and installs-verifies a Termux .deb inside termux/termux-docker.

Repository contract

Calling repositories are expected to follow a minimal build and packaging contract:

Makefile

Target / Variable Requirement
make Builds the release binary at bin_path. Must honor CC, VERSION, CFLAGS, LDFLAGS, and override CPPFLAGS.
make STATIC=1 Builds a statically linked binary on Linux.
make clean Removes build artifacts between static/dynamic and legacy/modern passes.
make test Builds and executes the unit test suite.
make leaks Builds and runs tests/checks under ASan and UBSan with leak detection enabled.
make lint Runs formatting and static analysis checks; must honor CLANG_FORMAT.
make dev Optional development build, used when enable_dev is true.

Custom projects can replace any of these commands with build_cmd, test_cmd, leaks_cmd, lint_cmd, and dev_cmd. See examples/Makefile for a minimal reference implementation.

Packaging templates

  • Homebrew (when homebrew_tap is set): provide packaging/homebrew.rb.in (see examples/homebrew.rb.in).
    • Use @VERSION@ (replaced without a leading v, so url should reference v@VERSION@.tar.gz) and @SHA256@.
    • Match the Ruby class name to pkg_name in PascalCase (for example my-tool → class MyTool < Formula).
    • Keep bin.install aligned with bin_path (such as build/bin/app or bin/app).
  • nfpm (optional): if nfpm.yaml is absent, c-release.yml generates one automatically. If you supply a custom nfpm.yaml, point contents[].src to ./nfpm_staging/<pkg_name>.

GitHub Environments

If your secrets are stored in repository environments instead of repository-level secrets, configure release, homebrew, and packages environments in the calling repository; c-release.yml binds the corresponding jobs to those environment names.

Note

secrets: inherit is not supported across repositories under a personal GitHub user account. Even when secrets live in GitHub Environments, callers must explicitly declare them in the secrets: block when invoking c-release.yml so the reusable workflow is granted access to read them.

packages.basted.dev contract

packages.basted.dev rebuilds its APT, RPM, pacman, and Termux repositories from the latest GitHub Release of every project listed in its data/projects.yaml. It does not need a client_payload; c-release.yml sends a repository_dispatch with {"event_type":"new-release"}, and the site discovers the release assets through the GitHub API.

The site consumes these release assets:

Channel Asset pattern Architectures
APT <pkg>_<version>_<arch>.deb amd64, arm64, armhf, riscv64
RPM <pkg>-<version>-1.<arch>.rpm x86_64, aarch64, armv7hl, riscv64
Arch Linux <pkg>-<version>-1-<arch>.pkg.tar.zst x86_64, aarch64, armv7h, riscv64
Termux <pkg>-termux_<version>_<arch>.deb aarch64, arm, x86_64

The release archives (<pkg>-linux-*.tar.gz, <pkg>-macos-*.tar.gz, <pkg>-android-termux-*.tar.gz), SHA256SUMS.txt, and SHA256SUMS.txt.asc are published for users and for Homebrew/attestation consumers. The package site does not parse the checksum files or the archives: it verifies each downloaded package against the SHA-256 digest that GitHub publishes for the release asset.

Critical invariants:

  • Keep the package filename format. The site parses the version from the filename and maps the architecture from the suffix. Changing the separator, revision, or architecture spelling breaks version synchronization and repository selection.
  • Keep the package name equal to pkg_name. The generated nfpm config uses name: <pkg_name>, and the site matches assets by that prefix. The Termux Package: field must stay clean (<pkg_name>, without -termux) even though the Termux filename carries the marker.
  • Keep nfpm architecture mapping. c-release.yml maps amd64, arm64, arm7, and riscv64 to the Debian/RPM/Arch suffixes shown above. nfpm produces armhf/armv7hl/armv7h from arm7.
  • A missing optional architecture is valid. The site downloads each pattern with || true, selects a project when at least one package exists, keeps empty APT indexes for absent architectures, skips empty Arch/RPM/Termux trees, and verifies only the signatures it actually produced. Disabling riscv64, armv7, or Termux in c-release.yml therefore does not break the site.
  • A project with no package assets is not published. A release that only contains .tar.gz archives is intentionally skipped by the site selector. If a project should appear on the site, it must publish at least one .deb, .rpm, or .pkg.tar.zst.

The package site keeps the APT layout stable when an optional architecture has no packages: it writes an empty Packages index instead of asking apt-ftparchive to scan an empty directory. The SHA-256 and GPG verification paths are unchanged.

Examples

Ordinary C project

# .github/workflows/tests.yml
name: Tests

on:
  push:
  pull_request:

permissions:
  contents: read

jobs:
  ci:
    uses: b1sted/ci/.github/workflows/c-ci.yml@v1
    with:
      enable_cross_tests: true
      bin_path: build/bin/mytool
      cross_test_args: selftest
# .github/workflows/release.yml
name: Release

on:
  push:
    tags: ['v*.*']

permissions:
  contents: write
  id-token: write
  attestations: write

jobs:
  release:
    uses: b1sted/ci/.github/workflows/c-release.yml@v1
    with:
      pkg_name: mytool
      bin_path: build/bin/mytool
      homepage: https://github.com/owner/mytool
      description: A small dependency-free C tool.
      license: MIT
      maintainer: Name <mail@example.com>
      packages_dispatch_repo: owner/packages.basted.dev
    secrets:
      GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
      GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
      PACKAGES_DISPATCH_TOKEN: ${{ secrets.PACKAGES_DISPATCH_TOKEN }}

latbench: smoke CI plus full diagnostics

latbench uses the fast smoke profile on every push and the heavy full profile only on demand:

# .github/workflows/tests.yml
name: Tests and Linters

on:
  push:
    branches: [main, dev]
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  ci:
    uses: b1sted/ci/.github/workflows/c-ci.yml@v1
    with:
      enable_cross_tests: true
      bin_path: build/bin/latbench
      cross_test_args: selftest --no-timing
      linux_apt_packages: util-linux bsdutils file
      linux_verify_cmd: ./tools/verify/linux.sh smoke
      macos_verify_cmd: ./tools/verify/macos.sh smoke
      verify_artifacts_path: results
# .github/workflows/full-diagnostics.yml
name: Full diagnostics

on:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  verify:
    uses: b1sted/ci/.github/workflows/c-verify.yml@v1
    with:
      enable_linux_amd64: true
      enable_linux_arm64: true
      enable_linux_riscv64: false
      enable_macos_arm64: true
      linux_apt_packages: >-
        build-essential clang clang-format clang-tidy cppcheck python3
        util-linux bsdutils file
      linux_cmd: ./tools/verify/linux.sh full
      macos_cmd: ./tools/verify/macos.sh full
      results_path: results
      timeout_minutes: 45

The project must provide the commands it references. The profile names (smoke, full) are examples; use whatever your verification scripts accept. The macOS verification path is not required to use Homebrew: c-verify.yml never runs brew install.

Security and verification

  • Pinned Actions: Every third-party action inside b1sted/ci is pinned to an immutable 40-character commit SHA and kept current via .github/dependabot.yml.
  • Minimal Permissions: Top-level workflow permissions default to contents: read; write and OIDC attestation permissions are scoped strictly to the release job.
  • Download Integrity: install-nfpm verifies downloaded tarballs against a pinned checksums.txt SHA-256 digest before installation.
  • Provenance Attestation: Release artifacts are attested via actions/attest (SLSA Build Provenance) and verifiable with gh attestation verify. Set enable_attestations: false to skip this step.
  • Token Handling: Repository dispatch credentials are passed via curl -K - on standard input rather than command-line arguments.
  • No macOS Homebrew bootstrap: the reusable workflows never install packages with brew, so an Intel macOS run cannot accidentally compile LLVM or Python from source before reaching the project.

License

Distributed under the GNU General Public License v3.0.

You are free to use, modify, and distribute this software under the terms of the GPL-3.0 license. Any derivative works must also be distributed under the same license.

Full text of the license: LICENSE.

About

Reusable GitHub Actions workflows and composite actions for C projects

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages