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

scripts: minor refactor to scripts #7403

Merged
merged 5 commits into from
Jul 12, 2024
Merged

Conversation

arvindbr8
Copy link
Member

@arvindbr8 arvindbr8 commented Jul 10, 2024

Fixing parts of #7400.

Changes:

  • install_protoc.sh
    • rename to install-protoc.sh ( following the rest of the file names under scripts/ )
    • In order to easily find the start of the program, put the main program in a function called main as the bottom-most function.
    • Move all checks from download_binary() to main()
    • Modify top-level comment to talk about usage of the script
    • Remove INSTALL_PATH=${1:+"$1"}
  • regenerate.sh
    • exec and not source install_protoc.sh as the very first thing in the script
    • export GOBIN
    • does not save and restore $PATH anymore
  • vet_common.sh
    • rename to common.sh

This PR does not make functional changes to any scripts -- which will be made in an upcoming PR

RELEASE NOTES: none

@arvindbr8 arvindbr8 added this to the 1.66 Release milestone Jul 10, 2024
@arvindbr8 arvindbr8 requested a review from dfawley July 10, 2024 21:58
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.51%. Comparing base (e54f441) to head (c103912).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7403      +/-   ##
==========================================
+ Coverage   81.46%   81.51%   +0.05%     
==========================================
  Files         348      348              
  Lines       26752    26752              
==========================================
+ Hits        21793    21807      +14     
+ Misses       3771     3764       -7     
+ Partials     1188     1181       -7     

see 17 files with indirect coverage changes

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Pretty much all LGTM, just some very minor nits. Thanks for picking this up.

# This script ensures the installation of protobuf on client machine.
# In case of manual run of this script, make sure you pass the args
# expected at
# https://github.com/grpc/grpc-go/blob/master/scripts/install-protoc.sh#L60
Copy link
Member

Choose a reason for hiding this comment

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

This feels very prone to move around. In fact, line 60 of this file is something to detect your architecture. Maybe we can do something better?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the top-level comment to talk more about usages. PTAL


main() {
# Check if protoc is already available.
if command -v protoc &> /dev/null; then
Copy link
Member

Choose a reason for hiding this comment

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

So if protoc is in my path somewhere, but I wanted to download to a specific path, it still won't do it?

Perhaps the PR description should say what this change is attempting to fix, specifically, instead of just "parts of ###"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's actually really confusing. i will fix that behavior in the PR that's to follow.

Perhaps the PR description should say what this change is attempting to fix, specifically, instead of just "parts of ###"?

err.. sorry about that. Initially I had only imagined having a very trivial change in this PR. I've updated the description. PTAL

echo "protoc version $PROTOC_VERSION is already installed."
return
else
die "Existing protoc version ($INSTALL_VERSION) differs. Kindly make sure you have $PROTOC_VERSION installed."
Copy link
Member

Choose a reason for hiding this comment

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

The entire job of this script is to install it for me. It's funny for it to say "please install it". :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Will update this in the next PR

Comment on lines 54 to 55
else
echo "Unable to determine installed protoc version. Starting the installation."
Copy link
Member

Choose a reason for hiding this comment

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

Remove?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

"x86_64") ARCH="x86_64";;
"aarch64") ARCH="aarch_64";;
"arm64") ARCH="aarch_64";;
*) die "Unsupported architecture. Please consider manual installation from \
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't these lines line up? (and below)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good callout. Fixed.

esac
}

main "$@"
Copy link
Member

Choose a reason for hiding this comment

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

Please add a newline at the end of the file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

}
trap finish EXIT

GOBIN="${WORKDIR}"/bin
ORIGINAL_PATH=$PATH
source ./scripts/install-protoc.sh "${WORKDIR}"
Copy link
Member

Choose a reason for hiding this comment

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

Why source? Generally you don't want to source anything unless it's explicitly supposed to add stuff to your environment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member Author

@arvindbr8 arvindbr8 left a comment

Choose a reason for hiding this comment

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

Addressed most of your comments in the latest commit. For a few, i will take care of it in the next PR. PTAL


main() {
# Check if protoc is already available.
if command -v protoc &> /dev/null; then
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's actually really confusing. i will fix that behavior in the PR that's to follow.

Perhaps the PR description should say what this change is attempting to fix, specifically, instead of just "parts of ###"?

err.. sorry about that. Initially I had only imagined having a very trivial change in this PR. I've updated the description. PTAL

echo "protoc version $PROTOC_VERSION is already installed."
return
else
die "Existing protoc version ($INSTALL_VERSION) differs. Kindly make sure you have $PROTOC_VERSION installed."
Copy link
Member Author

Choose a reason for hiding this comment

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

Will update this in the next PR

# This script ensures the installation of protobuf on client machine.
# In case of manual run of this script, make sure you pass the args
# expected at
# https://github.com/grpc/grpc-go/blob/master/scripts/install-protoc.sh#L60
Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the top-level comment to talk more about usages. PTAL

Comment on lines 54 to 55
else
echo "Unable to determine installed protoc version. Starting the installation."
Copy link
Member Author

Choose a reason for hiding this comment

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

Done

"x86_64") ARCH="x86_64";;
"aarch64") ARCH="aarch_64";;
"arm64") ARCH="aarch_64";;
*) die "Unsupported architecture. Please consider manual installation from \
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good callout. Fixed.

esac
}

main "$@"
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

}
trap finish EXIT

GOBIN="${WORKDIR}"/bin
ORIGINAL_PATH=$PATH
source ./scripts/install-protoc.sh "${WORKDIR}"
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@arvindbr8 arvindbr8 requested a review from dfawley July 11, 2024 20:02
@dfawley dfawley assigned arvindbr8 and unassigned dfawley Jul 12, 2024
@arvindbr8 arvindbr8 merged commit c5c0e18 into grpc:master Jul 12, 2024
13 checks passed
@arvindbr8 arvindbr8 deleted the fix_regenerate_1 branch July 12, 2024 17:32
printchard pushed a commit to printchard/grpc-go that referenced this pull request Jul 30, 2024
printchard pushed a commit to printchard/grpc-go that referenced this pull request Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants