diff --git a/.gitignore b/.gitignore index e917e5ce..511e56c0 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ Dockerfile.cross *.swp *.swo *~ + +#macOS +.DS_Store diff --git a/Makefile b/Makefile index 4dfa8760..23fcecc3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ - +# You can use podman or docker as a container engine. Notice that there are some options that might be only valid for one of them. +ENGINE ?= docker +IMAGE_NAME=kube-compare .PHONY: build build: @@ -7,3 +9,22 @@ build: .PHONY: test test: go test --race ./pkg/* + +# markdownlint rules, following: https://github.com/openshift/enhancements/blob/master/Makefile +.PHONY: markdownlint-image +markdownlint-image: ## Build local container markdownlint-image + $(ENGINE) image build -f ./hack/markdownlint.Dockerfile --tag $(IMAGE_NAME)-markdownlint:latest ./hack + +.PHONY: markdownlint-image-clean +markdownlint-image-clean: ## Remove locally cached markdownlint-image + $(ENGINE) image rm $(IMAGE_NAME)-markdownlint:latest + +# markdownlint main +markdownlint: markdownlint-image ## run the markdown linter + $(ENGINE) run \ + --rm=true \ + --env RUN_LOCAL=true \ + --env VALIDATE_MARKDOWN=true \ + --env PULL_BASE_SHA=$(PULL_BASE_SHA) \ + -v $$(pwd):/workdir:Z \ + $(IMAGE_NAME)-markdownlint:latest diff --git a/hack/markdownlint-install.sh b/hack/markdownlint-install.sh new file mode 100755 index 00000000..7d51e6da --- /dev/null +++ b/hack/markdownlint-install.sh @@ -0,0 +1,19 @@ +#!/bin/bash -xe +# Following example of: https://github.com/openshift/enhancements/blob/master/hack/install-markdownlint.sh + +cat /etc/redhat-release || echo "No /etc/redhat-release" + +if grep -q 'Red Hat Enterprise Linux' /etc/redhat-release; then + # install the config file for the RPM repository with node 14 + # steps taken from https://rpm.nodesource.com/setup_14.x + yum module disable -y nodejs + curl -sL -o '/tmp/nodesource.rpm' 'https://rpm.nodesource.com/pub_14.x/el/8/x86_64/nodesource-release-el8-1.noarch.rpm' + rpm -i --nosignature --force /tmp/nodesource.rpm + yum -y install nodejs +else + # Fedora has a module we can use + dnf -y module enable nodejs:16 + dnf -y install nodejs +fi + +npm install -g markdownlint@v0.25.1 markdownlint-cli2@v0.4.0 diff --git a/hack/markdownlint.Dockerfile b/hack/markdownlint.Dockerfile new file mode 100755 index 00000000..63c00e1d --- /dev/null +++ b/hack/markdownlint.Dockerfile @@ -0,0 +1,7 @@ +# Following example of: https://github.com/openshift/enhancements/blob/master/hack/Dockerfile.markdownlint +FROM registry.access.redhat.com/ubi9/ubi:latest +WORKDIR /workdir +RUN dnf install -y git golang +COPY markdownlint-install.sh /tmp +RUN /tmp/markdownlint-install.sh +ENTRYPOINT /workdir/hack/markdownlint.sh diff --git a/hack/markdownlint.sh b/hack/markdownlint.sh new file mode 100755 index 00000000..511e9008 --- /dev/null +++ b/hack/markdownlint.sh @@ -0,0 +1,20 @@ +#!/bin/bash -ex +# Following example of: https://github.com/openshift/enhancements/blob/master/hack/markdownlint.sh + +# trap errors, including the exit code from the command failed +trap 'handle_exit $?' EXIT + +function handle_exit { + # If the exit code we were given indicates an error, suggest that + # the author run the linter locally. + if [ "$1" != "0" ]; then + cat - <