Skip to content

CI — Prometheus rules ​

Validates PrometheusRule CRDs: PromQL parsing (promtool check rules) and alert behaviour (promtool test rules).

kubeconform — see ci-kubernetes.yml — validates the CRD schema only: expr is an opaque string to it, so an unparseable expression passes CI and is then dropped silently by the Prometheus rule loader in-cluster. The alert simply never fires, with nothing to notice. This workflow closes that gap offline.

Usage ​

yaml
jobs:
  prometheus-rules:
    uses: KevinDeBenedetti/github-workflows/.github/workflows/ci-prometheus.yml@v0.57.0 # x-release-please-version
    with:
      runner: '"ubuntu-26.04"'

Inputs ​

InputTypeDefaultDescription
run-checkbooleantrueRun the PromQL syntax check script
run-testbooleantrueRun the alert unit-test script (skipped if the script is absent)
check-scriptstringscripts/promtool-check.shPath to the syntax-check script in the calling repo
test-scriptstringscripts/promtool-test.shPath to the unit-test script in the calling repo
promtool-versionstringpinned (Renovate)Prometheus release providing promtool (no leading v)
yq-versionstringpinned (Renovate)mikefarah/yq release tag (with leading v)
runnerstring'"ubuntu-26.04"'Runner labels as JSON — '"ubuntu-26.04"' or a label array

Steps ​

  1. Checkout
  2. Install promtool + yq from their GitHub releases into RUNNER_TEMP/bin, each checked against its release's SHA-256 list (setup-promtool)
  3. (if run-check) run check-script
  4. (if run-test) run test-script, or emit a notice when it does not exist

Notes ​

  • Thin wrapper by design. It installs the tooling and runs the caller's scripts instead of re-implementing the CRD handling. A reusable workflow checks out the calling repository, so one implementation backs both CI and the caller's local pre-commit hooks — nothing to keep in sync twice.
  • promtool expects a raw rules file (groups: at the top level), not a Kubernetes CRD. Unwrapping each PrometheusRule to its .spec (with the yq installed alongside promtool) is the caller's script's job.
  • check-script missing is a failure (the workflow was asked to check something that is not there); test-script missing is a notice, since a repo may legitimately ship rules before it has a test suite.
  • Both tools are installed from pinned versions rather than a package manager: the runner image ships neither, and pinning keeps CI reproducible. Renovate bumps the defaults through the # renovate: comments of ci-prometheus.yml; a caller that sets a version pins it itself.