From 61d02a2331ba660df93f39ce171aeea2042574ca Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Fri, 29 Mar 2024 20:03:35 +0000 Subject: [PATCH] :seedling: add check and fix for triling spaces --- .github/workflows/spaces.yml | 22 ++++++++++++++++++++++ Makefile | 10 ++++++++++ test/check_spaces.sh | 25 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 .github/workflows/spaces.yml create mode 100755 test/check_spaces.sh diff --git a/.github/workflows/spaces.yml b/.github/workflows/spaces.yml new file mode 100644 index 00000000000..99742b0fc3b --- /dev/null +++ b/.github/workflows/spaces.yml @@ -0,0 +1,22 @@ +name: Trailing + +# Trigger the workflow on pull requests and direct pushes to any branch +on: + push: + paths: + - '**/*.md' + pull_request: + paths: + - '**/*.md' + +jobs: + lint: + name: "Check Trailing" + runs-on: ubuntu-latest + # Pull requests from the same repository won't trigger this checks as they were already triggered by the push + if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository) + steps: + - name: Clone the code + uses: actions/checkout@v4 + - name: Run check + run: make test-spaces diff --git a/Makefile b/Makefile index b2e33008d07..7b9d1598df4 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,12 @@ install: build ## Build and install the binary with the current source code. Use .PHONY: generate generate: generate-testdata generate-docs ## Update/generate all mock data. You should run this commands to update the mock data after your changes. go mod tidy + remove-spaces + +.PHONY: remove-spaces +remove-spaces: + @echo "Removing trailing spaces" + @find . -type f -name "*.md" -exec sed -i '' 's/[[:space:]]*$$//' {} + .PHONY: generate-testdata generate-testdata: ## Update/generate the testdata in $GOPATH/src/sigs.k8s.io/kubebuilder @@ -160,3 +166,7 @@ test-book: ## Run the cronjob tutorial's unit tests to make sure we don't break .PHONY: test-license test-license: ## Run the license check ./test/check-license.sh + +.PHONY: test-spaces +test-spaces: ## Run the trailing spaces check + ./test/check_spaces.sh \ No newline at end of file diff --git a/test/check_spaces.sh b/test/check_spaces.sh new file mode 100755 index 00000000000..edd9f00c30b --- /dev/null +++ b/test/check_spaces.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Copyright 2024 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function validate_docs_trailing_spaces { + if find . -type f -name "*.md" -exec grep -Hn '[[:space:]]$' {} +; then + echo "Trailing spaces were found in docs files" + exit 1 + fi + +} + +validate_docs_trailing_spaces