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

feat: hermetic build OS detection #1988

Merged
merged 7 commits into from Sep 13, 2023
Merged

Conversation

diegomarquezp
Copy link
Contributor

Adds OS detection to generate_library.sh

Manual input from workflow matrix is removed in favor of automatic detection

@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Sep 13, 2023
@diegomarquezp
Copy link
Contributor Author

Mismatch in diff due to googleapis recently pushing a commit not found in googleapis-gen (link)

@diegomarquezp diegomarquezp marked this pull request as ready for review September 13, 2023 17:39
@diegomarquezp diegomarquezp requested a review from a team as a code owner September 13, 2023 17:39
library_generation/utilities.sh Outdated Show resolved Hide resolved
detect_OS() {
if [[ "${OSTYPE}" == "linux-gnu"* ]] || [[ "${OSTYPE}" == "freebsd"* ]]; then
os_architecture="linux-x86_64"
elif [[ "${OSTYPE}" == "darwin"* ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about osx-aarm_64?

I think you can use uname -sm to detect OS type and CPU architecture, but I'm not sure whether windows can run this command.

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 defaulted to win32 regardless of architecture and changed it to uname -m to detect the architecture only, while keeping reliance on ${OSTYPE}

library_generation/utilities.sh Outdated Show resolved Hide resolved
@@ -273,3 +273,24 @@ get_version_from_versions_txt() {
version=$(grep "$key:" "${versions}" | cut -d: -f3) # 3rd field is snapshot
echo "${version}"
}

detect_os_architecture() {
case "${OSTYPE}" in
Copy link
Collaborator

Choose a reason for hiding this comment

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

where does OSTYPE come from?

os_architecture="linux-$(uname -m)"
;;
"darwin"*)
os_architecture="osx-$(uname -m)"
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I run uname -m on my machine, the output is arm64.
However, the right os architecture should be osx-aarch_64.
You can reference the os architecture here

I also implemented a os architecture detection function:

get_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}"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, thanks for the function :) I couldn't confirm for the aarch64 case since I don't have such machine, but I switched the detection function to this one

uses function by Joe Wang
@sonarcloud
Copy link

sonarcloud bot commented Sep 13, 2023

[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Sep 13, 2023

[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Sep 13, 2023

[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@diegomarquezp diegomarquezp merged commit 4fc844e into main Sep 13, 2023
41 of 43 checks passed
@diegomarquezp diegomarquezp deleted the feat/hermetic-build/os-detection branch September 13, 2023 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants