Refactor CD scripts to eliminate details.txt dependency and support m… - #4972
Refactor CD scripts to eliminate details.txt dependency and support m…#4972anushka567 wants to merge 2 commits into
Conversation
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
There was a problem hiding this comment.
Code Review
This pull request refactors the end-to-end and installation test scripts to fetch configuration parameters (such as release version, commit hash, and upload bucket) directly from VM metadata attributes or environment variables, falling back to GCS if unavailable. It also improves OS distribution detection and version verification. The review feedback highlights three key areas for improvement: explicitly handling GCS copy failures in e2e_test.sh to avoid silent errors, adhering to the Google Shell Style Guide by removing the redundant function keyword syntax in install_test.sh, and validating that the release version is not empty before proceeding with package installation.
| # Fallback to fetching details.txt from GCS if metadata is not provided | ||
| gcloud storage cp gs://${BUCKET_NAME_TO_USE}/version-detail/details.txt . || true | ||
| echo "$VM_NAME" >> details.txt |
There was a problem hiding this comment.
If the gcloud storage cp command fails, details.txt will not be created. The subsequent echo "$VM_NAME" >> details.txt will then create a new file containing only the VM name. This causes the script to later parse the VM name as the VERSION (line 236) and leave COMMIT_HASH empty, leading to silent failures. We should handle the copy failure explicitly using an explicit if/else structure.
| # Fallback to fetching details.txt from GCS if metadata is not provided | |
| gcloud storage cp gs://${BUCKET_NAME_TO_USE}/version-detail/details.txt . || true | |
| echo "$VM_NAME" >> details.txt | |
| # Fallback to fetching details.txt from GCS if metadata is not provided | |
| if gcloud storage cp gs://${BUCKET_NAME_TO_USE}/version-detail/details.txt .; then | |
| echo "$VM_NAME" >> details.txt | |
| else | |
| echo "Error: Failed to fetch details.txt from GCS fallback." >&2 | |
| exit 1 | |
| fi |
References
- In shell scripts, use an explicit if/else structure for fallback logic instead of the && || chain to improve readability and avoid unexpected behavior.
| to_release_version=$(sed '1q' details.txt | tr -d '\n') | ||
| echo $vm_instance_name >> details.txt | ||
| # Helper function to fetch metadata value from GCE metadata server | ||
| function fetch_meta_data_value() { |
There was a problem hiding this comment.
According to the Google Shell Style Guide, we should not combine the function keyword with () when defining functions. Use either func_name() { ... } or function func_name { ... }, with the former being preferred.
| function fetch_meta_data_value() { | |
| fetch_meta_data_value() { |
References
- According to the Google Shell Style Guide, we should not combine the function keyword with () when defining functions. (link)
| # Backward compatibility fallback if RELEASE_VERSION is not present in metadata | ||
| if [[ -z "$to_release_version" ]]; then | ||
| if gcloud storage cp "gs://${upload_bucket}/version-detail/details.txt" ./details.txt 2>/dev/null; then | ||
| to_release_version=$(sed -n 1p details.txt | tr -d '\r\n') | ||
| fi | ||
| fi |
There was a problem hiding this comment.
If to_release_version cannot be retrieved from either the metadata server or the fallback details.txt file, it remains empty. This will cause subsequent package installation commands (like apt-get install or yum install) to fail with syntax/package errors. We should validate that to_release_version is not empty and exit early with a clear error message using an explicit if/else structure.
| # Backward compatibility fallback if RELEASE_VERSION is not present in metadata | |
| if [[ -z "$to_release_version" ]]; then | |
| if gcloud storage cp "gs://${upload_bucket}/version-detail/details.txt" ./details.txt 2>/dev/null; then | |
| to_release_version=$(sed -n 1p details.txt | tr -d '\r\n') | |
| fi | |
| fi | |
| # Backward compatibility fallback if RELEASE_VERSION is not present in metadata | |
| if [[ -z "$to_release_version" ]]; then | |
| if gcloud storage cp "gs://${upload_bucket}/version-detail/details.txt" ./details.txt 2>/dev/null; then | |
| to_release_version=$(sed -n 1p details.txt | tr -d '\r\n') | |
| fi | |
| fi | |
| if [[ -z "$to_release_version" ]]; then | |
| echo "Error: RELEASE_VERSION is empty and could not be retrieved." >&2 | |
| exit 1 | |
| fi |
References
- In shell scripts, use an explicit if/else structure for fallback logic instead of the && || chain to improve readability and avoid unexpected behavior.
3138701 to
f3557a8
Compare
…ulti-project Louhi pipelines
f3557a8 to
e735085
Compare
…ckaging and hyphenated naming
…ulti-project Louhi pipelines
Please ensure your PR title follows the format:
Example:
feat(api): add user login endpointAvailable types:
feat: A new featurefix: A bug fixdocs: Documentation only changesstyle: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)refactor: A code change that neither fixes a bug nor adds a featureperf: A code change that improves performancetest: Adding missing tests or correcting existing testsbuild: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)chore: Other changes that don't modify src or test filesrevert: Reverts a previous commitDescription
Link to the issue in case of a bug fix.
Testing details
Any backward incompatible change? If so, please explain.