-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 2097: Introduce pre push hook for buf (#2776)
* introducing pre-push for buf * nit fix * nit fix * nit fix * os check while downloading buf * new line eof * adding files path * root changed * nit fixes
- Loading branch information
1 parent
f26d769
commit eccfd63
Showing
6 changed files
with
102 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# Download buf | ||
download_buf() { | ||
BUFVERSION="v0.37.1" | ||
echo Using Bufbuild version $BUFVERSION | ||
curl -sSLOC - https://github.com/bufbuild/buf/releases/download/$BUFVERSION/buf-$(uname -s)-$(uname -m) | ||
chmod a+x buf-$(uname -s)-$(uname -m) | ||
echo Buf downloaded | ||
} | ||
|
||
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "darwin"* ]]; then | ||
download_buf | ||
else | ||
echo "Protobuf lint check not available on $OSTYPE" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
jar_file_path=$? | ||
config_file_path=$? | ||
os_type=$? | ||
github_actions_path=$1 | ||
|
||
lint_protobuf_files() { | ||
echo "********************************" | ||
echo "Checking Protobuf file formatting" | ||
echo "********************************" | ||
|
||
$jar_file_path lint --config $config_file_path | ||
|
||
status=$? | ||
|
||
if [ "$status" = 0 ] ; then | ||
echo "Protobuf lint check completed successfully" | ||
exit 0 | ||
else | ||
echo "********************************" | ||
echo "Protobuf lint check issues found. Please fix them before pushing your code." | ||
echo "********************************" | ||
exit 1 | ||
fi | ||
} | ||
|
||
populate_jar_config_file_paths() { | ||
buf_file_name=$? | ||
|
||
if [ "$1" = "Linux" ]; then | ||
buf_file_name="buf-Linux-x86_64" | ||
else | ||
buf_file_name="buf-Darwin-x86_64" | ||
fi | ||
|
||
if [ $github_actions_path ]; then | ||
jar_file_path="$github_actions_path/oppia-android-tools/$buf_file_name" | ||
config_file_path="/home/runner/work/oppia-android/oppia-android/buf.yaml" | ||
else | ||
jar_file_path="../oppia-android-tools/$buf_file_name" | ||
config_file_path="buf.yaml" | ||
fi | ||
} | ||
|
||
ensure_jar_config_file_paths_are_set() { | ||
if [ $github_actions_path ]; then | ||
populate_jar_config_file_paths $os_type $github_actions_path | ||
else | ||
populate_jar_config_file_paths $os_type | ||
fi | ||
} | ||
|
||
check_os_type() { | ||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
os_type="Linux" | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
os_type="Darwin" | ||
else | ||
echo "Protobuf lint check not available on $OSTYPE" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_os_type | ||
|
||
ensure_jar_config_file_paths_are_set $github_actions_path | ||
|
||
lint_protobuf_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters