Skip to content

Commit

Permalink
markdown linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelsoccupied committed Apr 24, 2024
1 parent d0dcd05 commit b6eadca
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ Dockerfile.cross
*.swp
*.swo
*~

#macOS
.DS_Store
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
19 changes: 19 additions & 0 deletions hack/markdownlint-install.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions hack/markdownlint.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions hack/markdownlint.sh
Original file line number Diff line number Diff line change
@@ -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 - <<EOF
To run the linter on a Linux system with podman, run "make markdownlint"
after committing your changes locally.
EOF
fi
}

markdownlint-cli2 '**/*.md' !'vendor/**/*.md'

0 comments on commit b6eadca

Please sign in to comment.