Skip to content

Commit

Permalink
ci: ensure the generated code is up-to-date
Browse files Browse the repository at this point in the history
See etcd-io#14612 (comment)
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander committed Oct 31, 2022
1 parent a1018db commit a7f4c3d
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 198 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: v1.49.0
- name: protoc
uses: arduino/setup-protoc@v1
with:
version: '3.14.0'
- run: make verify
- run: make fix
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ fuzz:

# Static analysis

verify: verify-gofmt verify-bom verify-lint verify-dep verify-shellcheck verify-goword verify-govet verify-license-header verify-receiver-name verify-mod-tidy verify-shellcheck verify-shellws verify-proto-annotations
verify: verify-gofmt verify-bom verify-lint verify-dep verify-shellcheck verify-goword \
verify-govet verify-license-header verify-receiver-name verify-mod-tidy verify-shellcheck \
verify-shellws verify-proto-annotations verify-genproto
fix: fix-bom fix-lint
./scripts/fix.sh

Expand Down Expand Up @@ -99,6 +101,10 @@ verify-shellws:
verify-proto-annotations:
PASSES="proto_annotations" ./scripts/test.sh

.PHONY: verify-genproto
verify-genproto:
PASSES="genproto" ./scripts/test.sh


# Cleanup

Expand Down
2 changes: 1 addition & 1 deletion scripts/genproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ for dir in ${DIRS}; do

rm -f ./**/*.bak
run gofmt -s -w ./**/*.pb.go
run goimports -w ./**/*.pb.go
run_go_tool "golang.org/x/tools/cmd/goimports" -w ./**/*.pb.go
run popd
done

Expand Down
4 changes: 4 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,10 @@ function proto_annotations_pass {
"${ETCD_ROOT_DIR}/scripts/verify_proto_annotations.sh"
}

function genproto_pass {
"${ETCD_ROOT_DIR}/scripts/verify_genproto.sh"
}

########### MAIN ###############################################################

function run_pass {
Expand Down
19 changes: 19 additions & 0 deletions scripts/verify_genproto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# This scripts is automatically run by CI to prevent pull requests missing running genproto.sh
# after changing *.proto file.

set -o errexit
set -o nounset
set -o pipefail

./scripts/genproto.sh
diff=$(git diff --name-only | grep -c ".pb.")
if [ "$diff" -eq 0 ]; then
echo "PASSED genproto-verification!"
exit 0
fi
echo "Failed genproto-verification!" >&2
echo "* Found changed files $(git diff --name-only | grep '.pb.')" >&2
echo "* Please rerun genproto.sh after changing *.proto file" >&2
echo "* Run ./scripts/genproto.sh" >&2
exit 1
2 changes: 1 addition & 1 deletion scripts/verify_proto_annotations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ fi
echo "Failed proto-annotations-verification!" >&2
echo "If you are adding new proto fields/messages that will be included in raft log:" >&2
echo "* Please add etcd_version annotation in *.proto file with next etcd version" >&2
echo "* Run ./scripts/getproto.sh" >&2
echo "* Run ./scripts/genproto.sh" >&2
echo "* Run ./scripts/update_proto_annotations.sh" >&2
exit 1
389 changes: 194 additions & 195 deletions tests/functional/rpcpb/rpc.pb.go

Large diffs are not rendered by default.

0 comments on commit a7f4c3d

Please sign in to comment.