Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: ensure the generated code is up-to-date #14664

Merged
merged 2 commits into from
Nov 1, 2022
Merged

Conversation

spacewander
Copy link
Contributor

@spacewander spacewander commented Oct 31, 2022

See #14612 (comment)
Signed-off-by: spacewander [email protected]

@spacewander spacewander force-pushed the ra1 branch 3 times, most recently from 7047058 to a7f4c3d Compare October 31, 2022 10:30
@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2022

Codecov Report

Merging #14664 (a774510) into main (5073af6) will decrease coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main   #14664      +/-   ##
==========================================
- Coverage   75.53%   75.51%   -0.02%     
==========================================
  Files         457      457              
  Lines       37292    37292              
==========================================
- Hits        28169    28162       -7     
- Misses       7351     7360       +9     
+ Partials     1772     1770       -2     
Flag Coverage Δ
all 75.51% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
client/v3/leasing/util.go 91.66% <0.00%> (-6.67%) ⬇️
server/etcdserver/api/v3rpc/interceptor.go 73.43% <0.00%> (-4.17%) ⬇️
server/etcdserver/api/v3rpc/util.go 70.96% <0.00%> (-3.23%) ⬇️
client/v3/leasing/txn.go 88.09% <0.00%> (-3.18%) ⬇️
server/proxy/grpcproxy/watch.go 92.48% <0.00%> (-2.90%) ⬇️
server/etcdserver/api/v3rpc/key.go 82.19% <0.00%> (-1.37%) ⬇️
client/v3/watch.go 92.66% <0.00%> (-1.16%) ⬇️
client/v3/op.go 74.71% <0.00%> (-1.15%) ⬇️
pkg/proxy/server.go 60.67% <0.00%> (-1.02%) ⬇️
client/v3/leasing/kv.go 89.70% <0.00%> (-0.67%) ⬇️
... and 15 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

set -o pipefail

./scripts/genproto.sh
diff=$(git diff --name-only | grep -c ".pb.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation checks if there is any uncommitted proto files, this should work for CI, but not for local development.
I think this should be ok, but maybe you can figure out if we could output ./scripts/genproto.sh to tmp directory and compare it's contents to local files.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This recommendation only makes sense when command is run in CI.
When running locally user needs to just commit the changes.

I think we should explain that user should run ./scripts/genproto.sh only if the commend was run in CI and then commit the changes.

@serathius
Copy link
Member

Thanks for looking into this!

tmpWorkDir=$(mktemp -d -t 'twd.XXXXXX')
mkdir "$tmpWorkDir/etcd"
tmpWorkDir="$tmpWorkDir/etcd"
cp -r . "$tmpWorkDir"
Copy link
Member

@serathius serathius Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coping whole repo seems like a lot of work. Could we maybe just copy minimal set of files needed (*.proto)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, but the genproto.sh requires too many files (not just *.proto).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we then simplify genproto.sh so it can be run on non local directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not so easy, as the genproto.sh requires some Go files, extra shell scripts in the scripts directory, the Documentation directory, and so on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's leave for future.

pushd "$tmpWorkDir"
git add -A && git commit -m init
./scripts/genproto.sh
diff=$(git diff --numstat | awk '{print $3}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script will still compare generated proto versus proto committed, so there is no difference from older script.

Copy link
Contributor Author

@spacewander spacewander Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git diff doesn't include the committed change.
For changed but not committed changes, they are committed in the prev line git add -A && git commit -m init, so the diff happens in a fresh git repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@serathius
Sorry for affecting your review. I just force-push a new commit that handles a case that git commit will fail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm little worried about git shenanigans (add commit), it makes the code very fragile.

Have you considered avoiding them? I will not push too much as overall change should be beneficial, just worried about over-complicating verify_genproto.sh if we could maybe simplify genproto.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried using regular diff. But the genproto.sh will generate some files which are ignored by .gitignore. And as regular diff doesn't support .gitignore, we have to maintain an additional ignore list...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think we are good enough. We can iterate on the code.

Signed-off-by: spacewander <[email protected]>
@spacewander spacewander marked this pull request as ready for review October 31, 2022 13:33
Copy link
Member

@serathius serathius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this. cc @ahrtr @spzala @ptabor

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, good catch!

@ahrtr
Copy link
Member

ahrtr commented Nov 1, 2022

Overall looks good to me. Just as I mentioned in #14612 (comment), the reason is we do not fix the versions of some binaries.

We might need to revisit this after #14533 if resolved.

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for now.

Thank yo @spacewander

@serathius serathius merged commit 2e790d2 into etcd-io:main Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants