Skip to content

Commit 7b36b0e

Browse files
🌱 add check and fix for triling spaces
1 parent a0e731a commit 7b36b0e

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

.github/workflows/spaces.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Trailing
2+
3+
# Trigger the workflow on pull requests and direct pushes to any branch
4+
on:
5+
push:
6+
paths:
7+
- '**/*.md'
8+
pull_request:
9+
paths:
10+
- '**/*.md'
11+
12+
jobs:
13+
lint:
14+
name: "Check Trailing"
15+
runs-on: ubuntu-latest
16+
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
17+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
18+
steps:
19+
- name: Clone the code
20+
uses: actions/checkout@v4
21+
- name: Run check
22+
run: make test-spaces

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ install: build ## Build and install the binary with the current source code. Use
6666
.PHONY: generate
6767
generate: generate-testdata generate-docs ## Update/generate all mock data. You should run this commands to update the mock data after your changes.
6868
go mod tidy
69+
remove-spaces
70+
71+
.PHONY: remove-spaces
72+
remove-spaces:
73+
@echo "Removing trailing spaces"
74+
@find . -type f -name "*.md" -exec sed -i '' 's/[[:space:]]*$$//' {} +
6975

7076
.PHONY: generate-testdata
7177
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
160166
.PHONY: test-license
161167
test-license: ## Run the license check
162168
./test/check-license.sh
169+
170+
.PHONY: test-spaces
171+
test-spaces: ## Run the trailing spaces check
172+
./test/check_spaces.sh

test/check_spaces.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2024 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
function validate_docs_trailing_spaces {
18+
if find . -type f -name "*.md" -exec grep -Hn '[[:space:]]$' {} +; then
19+
echo "Trailing spaces were found in docs files"
20+
exit 1
21+
fi
22+
23+
}
24+
25+
validate_docs_trailing_spaces

0 commit comments

Comments
 (0)