Skip to content

Commit 4fc844e

Browse files
feat: hermetic build OS detection (#1988)
* 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
1 parent 336e8f3 commit 4fc844e

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

.github/workflows/verify_library_generation.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ jobs:
2828
library_generation/test/generate_library_integration_test.sh \
2929
-p google/bigtable/v2 \
3030
-d google-cloud-bigtable-v2-java \
31-
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git \
32-
--os_type ${{ matrix.os }}
31+
--googleapis_gen_url https://cloud-java-bot:${{ secrets.CLOUD_JAVA_BOT_GITHUB_TOKEN }}@github.com/googleapis/googleapis-gen.git
3332
unit_tests:
3433
strategy:
3534
matrix:

library_generation/generate_library.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if [ -z "${include_samples}" ]; then
7878
fi
7979

8080
if [ -z "${os_architecture}" ]; then
81-
os_architecture="linux-x86_64"
81+
os_architecture=$(detect_os_architecture)
8282
fi
8383

8484
mkdir -p "${destination_path}"

library_generation/test/generate_library_integration_test.sh

+1-11
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ case $key in
3030
googleapis_gen_url="$2"
3131
shift
3232
;;
33-
--os_type)
34-
os_type="$2"
35-
shift
36-
;;
3733
*)
3834
echo "Invalid option: [$1]"
3935
exit 1
@@ -78,11 +74,6 @@ include_samples=$(get_config_from_BUILD \
7874
"false"
7975
)
8076
echo "GAPIC options are transport=${transport}, rest_numeric_enums=${rest_numeric_enums}, include_samples=${include_samples}."
81-
os_architecture="linux-x86_64"
82-
if [[ "$os_type" == *"macos"* ]]; then
83-
os_architecture="osx-x86_64"
84-
fi
85-
echo "OS Architecture is ${os_architecture}."
8677
# generate GAPIC client library
8778
echo "Generating library from ${proto_path}, to ${destination_path}..."
8879
"${library_generation_dir}"/generate_library.sh \
@@ -93,8 +84,7 @@ echo "Generating library from ${proto_path}, to ${destination_path}..."
9384
--grpc_version "${grpc_version}" \
9485
--transport "${transport}" \
9586
--rest_numeric_enums "${rest_numeric_enums}" \
96-
--include_samples "${include_samples}" \
97-
--os_architecture "${os_architecture}"
87+
--include_samples "${include_samples}"
9888

9989
echo "Generate library finished."
10090
echo "Checking out googleapis-gen repository..."

library_generation/utilities.sh

+18
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,21 @@ get_version_from_versions_txt() {
273273
version=$(grep "$key:" "${versions}" | cut -d: -f3) # 3rd field is snapshot
274274
echo "${version}"
275275
}
276+
277+
detect_os_architecture() {
278+
local os_type
279+
local os_architecture
280+
os_type=$(uname -sm)
281+
case "${os_type}" in
282+
*"Linux x86_64"*)
283+
os_architecture="linux-x86_64"
284+
;;
285+
*"Darwin x86_64"*)
286+
os_architecture="osx-x86_64"
287+
;;
288+
*)
289+
os_architecture="osx-aarch_64"
290+
;;
291+
esac
292+
echo "${os_architecture}"
293+
}

0 commit comments

Comments
 (0)