Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install and run po-linter #12

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.ci.openshift.org/openshift/release:golang-1.19 as builder
FROM registry.ci.openshift.org/openshift/release:golang-1.21 as builder

WORKDIR /work

Expand All @@ -23,4 +23,4 @@ COPY --from=builder /work/bin/obsctl-reloader-rules-checker /usr/bin/

WORKDIR /work
COPY .yamllint /
ENTRYPOINT ["/usr/bin/obsctl-reloader-rules-checker"]
ENTRYPOINT ["/usr/bin/obsctl-reloader-rules-checker"]
20 changes: 18 additions & 2 deletions hack/install-go-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@ fi

cd "$(dirname $BASH_SOURCE)/.."

# System info in lower case to avoid issues.
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m | tr '[:upper:]' '[:lower:]')
OS_ARCH="${OS}-${ARCH}"

PROMETHEUS_VERSION="v2.48.0"

TMPDIR=$(mktemp -d 2>/dev/null || mktemp -d -t 'prometheus')
PROMETHEUS_DEST="$(go env GOPATH)/bin"
RELEASE_INFO=$(curl -s https://api.github.com/repos/prometheus/prometheus/releases/tags/$PROMETHEUS_VERSION)
FILENAME=$(echo -E "$RELEASE_INFO" | jq -r --arg os_arch "$OS_ARCH" '.assets[] | select(.name | contains($os_arch)) | .name')
FILENAME_WITHOUT_EXTENSION="${FILENAME%.*.*}"
DOWNLOAD_URL=$(echo -E "$RELEASE_INFO" | jq -r --arg os_arch "$OS_ARCH" '.assets[] | select(.name | contains($os_arch)) | .browser_download_url')
(cd "$TMPDIR" && wget "$DOWNLOAD_URL" && tar -xzf "$FILENAME" && mv "$FILENAME_WITHOUT_EXTENSION"/promtool ${PROMETHEUS_DEST})
rm -rf "$TMPDIR"

go install -mod=readonly github.com/bwplotka/bingo@latest

# The following PR has been merged in bingo:
# https://github.com/bwplotka/bingo/pull/142
# Once the new bingo version is released, make sure to append '-t 0' in below commands
unset GOFLAGS
bingo get -v -l github.com/prometheus/prometheus/cmd/promtool@v0.46.0
bingo get -v -l github.com/cloudflare/pint/cmd/pint@v0.44.1
bingo get -v -l github.com/cloudflare/pint/cmd/pint@v0.44.1
go install github.com/prometheus-operator/prometheus-operator/cmd/po-lint
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ func checkRules(rulesDirPath, tenant string, isGeneratingTemplate bool) {
return fmt.Errorf("failed to run 'promtool check rules' on the 'spec' part of the file; output:\n%v", output)
}

if output, err := runAndOutputCommand("po-lint", specFilePath); err != nil {
return fmt.Errorf("failed to run 'po-lint' on the file; output:\n%v", output)
}

{
var ruleGroupsObj ruleGroupsObj

Expand Down