Skip to content

Commit

Permalink
feat: hermetic build OS detection (#1988)
Browse files Browse the repository at this point in the history
* feat: add OS detection to hermetic build scripts

* skip os arch in integration test

* remove unused IT flag

* dynamic architecture resolution

* change function name

* use `case` in os detection func

* correct os detection for aarch64

uses function by Joe Wang
  • Loading branch information
diegomarquezp committed Sep 13, 2023
1 parent 336e8f3 commit 4fc844e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/verify_library_generation.yaml
Expand Up @@ -28,8 +28,7 @@ jobs:
library_generation/test/generate_library_integration_test.sh \
-p google/bigtable/v2 \
-d google-cloud-bigtable-v2-java \
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git \
--os_type ${{ matrix.os }}
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git
unit_tests:
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion library_generation/generate_library.sh
Expand Up @@ -78,7 +78,7 @@ if [ -z "${include_samples}" ]; then
fi

if [ -z "${os_architecture}" ]; then
os_architecture="linux-x86_64"
os_architecture=$(detect_os_architecture)
fi

mkdir -p "${destination_path}"
Expand Down
12 changes: 1 addition & 11 deletions library_generation/test/generate_library_integration_test.sh
Expand Up @@ -30,10 +30,6 @@ case $key in
googleapis_gen_url="$2"
shift
;;
--os_type)
os_type="$2"
shift
;;
*)
echo "Invalid option: [$1]"
exit 1
Expand Down Expand Up @@ -78,11 +74,6 @@ include_samples=$(get_config_from_BUILD \
"false"
)
echo "GAPIC options are transport=${transport}, rest_numeric_enums=${rest_numeric_enums}, include_samples=${include_samples}."
os_architecture="linux-x86_64"
if [[ "$os_type" == *"macos"* ]]; then
os_architecture="osx-x86_64"
fi
echo "OS Architecture is ${os_architecture}."
# generate GAPIC client library
echo "Generating library from ${proto_path}, to ${destination_path}..."
"${library_generation_dir}"/generate_library.sh \
Expand All @@ -93,8 +84,7 @@ echo "Generating library from ${proto_path}, to ${destination_path}..."
--grpc_version "${grpc_version}" \
--transport "${transport}" \
--rest_numeric_enums "${rest_numeric_enums}" \
--include_samples "${include_samples}" \
--os_architecture "${os_architecture}"
--include_samples "${include_samples}"

echo "Generate library finished."
echo "Checking out googleapis-gen repository..."
Expand Down
18 changes: 18 additions & 0 deletions library_generation/utilities.sh
Expand Up @@ -273,3 +273,21 @@ get_version_from_versions_txt() {
version=$(grep "$key:" "${versions}" | cut -d: -f3) # 3rd field is snapshot
echo "${version}"
}

detect_os_architecture() {
local os_type
local os_architecture
os_type=$(uname -sm)
case "${os_type}" in
*"Linux x86_64"*)
os_architecture="linux-x86_64"
;;
*"Darwin x86_64"*)
os_architecture="osx-x86_64"
;;
*)
os_architecture="osx-aarch_64"
;;
esac
echo "${os_architecture}"
}

0 comments on commit 4fc844e

Please sign in to comment.