Skip to content

Commit

Permalink
🌱 add check and fix for triling spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Mar 29, 2024
1 parent a0e731a commit 61d02a2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/spaces.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
25 changes: 25 additions & 0 deletions test/check_spaces.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 61d02a2

Please sign in to comment.