Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Spolti <fspolti@redhat.com>
  • Loading branch information
spolti committed Mar 12, 2024
1 parent d408f28 commit c6c3dbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ COPY go.mod go.sum ./
# no required module provides package google.golang.org/grpc/cmd/protoc-gen-go-grpc
# to add it run `go get google.golang.org/grpc/cmd/protoc-gen-go-grpc`
ENV PATH $HOME/go/bin:$PATH
ENV GOPATH $HOME/go
RUN true \
&& go get google.golang.org/grpc/cmd/protoc-gen-go-grpc \
&& go install google.golang.org/protobuf/cmd/protoc-gen-go \
Expand Down
26 changes: 14 additions & 12 deletions scripts/add_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@

if ! hash addlicense 2>/dev/null; then
go install github.com/google/addlicense@latest
# make sure we can actually use the newly install addlicense script
if ! command -v my_command >/dev/null 2>&1; then
echo "Can not find 'addlicense' after running 'go install github.com/google/addlicense'."
echo 'Did you forget to export PATH=$PATH:$GOPATH/bin'
exit 1
fi
fi

# adds a new line between the header and the package keyword when it does not exists.
# 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
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/;}' {} \;
for file in $(find . -type f -name "*.go"); do
sed -i.bak \
-e '/\/\/ limitations under the License\.$/{' \
-e 'N' \
-e 's/\(\/\/ limitations under the License.\)\n\(package\)/\1\n\n\2/;}' \
$file
rm -rf ${file}.bak
done

# add license to new files that does not contains it
shopt -s globstar
Expand Down

0 comments on commit c6c3dbd

Please sign in to comment.