diff --git a/.github/workflows/prometheusrule.yml b/.github/workflows/prometheusrule.yml new file mode 100644 index 000000000..305b12629 --- /dev/null +++ b/.github/workflows/prometheusrule.yml @@ -0,0 +1,19 @@ +--- +name: prom-rules + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + verify: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '1.15' + - run: go get -u github.com/prometheus/prometheus/cmd/promtool + - run: verify-prometheus-rules.sh diff --git a/.gitignore b/.gitignore index 1ff2e2e77..838bc9a24 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ bin/ templates/ vendor/ crdschemas/ +tmp/ diff --git a/hack/verify-prometheus-rules.sh b/hack/verify-prometheus-rules.sh new file mode 100755 index 000000000..3d18609ce --- /dev/null +++ b/hack/verify-prometheus-rules.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -euo pipefail + +mkdir -p tmp/rules + +for f in $(grep -ir --include=*.yaml "PrometheusRule" . | grep kind | grep -v CustomResourceDefinition | sed 's/:.*//'); do + echo "$f" + tmpfile="$(echo "$f" | sed 's/\//-/g' | sed 's/.-//').json" + gojsontoyaml -yamltojson < "$f" | jq .spec > "tmp/rules/$tmpfile"; + ( cd tmp/rules && promtool check rules "$tmpfile") +done