Skip to content

Commit

Permalink
apply review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Spolti <[email protected]>
  • Loading branch information
spolti committed Feb 29, 2024
1 parent a2aec12 commit d408f28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ test:

.PHONY: fmt
## Auto-format source code and report code-style violations (lint)
fmt: addheaders
fmt: add_license_headers
./scripts/fmt.sh

.PHONY: addheaders
addheaders:
./scripts/addheaders.sh
.PHONY: add_license_headers check_addlicense
add_license_headers:
./scripts/add_headers.sh

.PHONY: proto.compile
## Compile protos
Expand Down
17 changes: 12 additions & 5 deletions scripts/addheaders.sh → scripts/add_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ if ! hash addlicense 2>/dev/null; then
fi

# adds a new line between the header and the package keyword when it does not exists.
sedparam=""
if [[ $OSTYPE == "darwin"* ]]; then
sedparam="''"
# we use sed to make in-file text replacements, but sed works differently depending on the version
if ! sed -i '1s/^/test/' $(mktemp) 2> /dev/null; then
# macOS (BSD) version of sed
alias gsed="sed -i ''"
else
# POSIX compliant version of sed
alias gsed="sed -i"
fi
find . -type f -name "*.go" -exec /usr/bin/sed -i ${sedparam} -e '/\/\/ limitations under the License\.$/{' -e 'N' -e 's/\(\/\/ limitations under the License.\)\n\(package\)/\1\n\n\2/;}' {} \;
export gsed

find . -type f -name "*.go" -exec gsed -e '/\/\/ limitations under the License\.$/{' -e 'N' -e 's/\(\/\/ limitations under the License.\)\n\(package\)/\1\n\n\2/;}' {} \;

# add license to new files that does not contains it
addlicense -v -c "IBM Corporation" -l=apache Dockerfile ./**/*.go scripts
shopt -s globstar
"${GOPATH}"/bin/addlicense -v -c "IBM Corporation" -l=apache Dockerfile ./**/*.go scripts

0 comments on commit d408f28

Please sign in to comment.