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

chore: use template cache for branches on unity cloud #2061

Merged
merged 5 commits into from
Sep 16, 2024

Conversation

aixaCode
Copy link
Collaborator

@aixaCode aixaCode commented Sep 13, 2024

What does this PR change?

  • Don't delete builds for release targets
  • Try to use cache from template target on new branches if it's compatible to speed up the first build

Template target will have a cron job setup to run once per day

Our Code Review Standards

https://github.com/decentraland/unity-renderer/blob/master/docs/code-review-standards.md

Summary by CodeRabbit

  • New Features

    • Introduced a caching option for the target cloning process, allowing users to choose whether to use cached builds.
  • Bug Fixes

    • Enhanced error handling with retry logic for connection issues and specific HTTP status codes during target creation and updates.
  • Improvements

    • Improved robustness of the build process through better logging and handling of cloning failures.

@aixaCode aixaCode added no QA needed Used to tag pull requests that does not require QA validation do not merge labels Sep 13, 2024
Copy link

coderabbitai bot commented Sep 13, 2024

Walkthrough

The changes introduce a new parameter, use_cache, to the clone_current_target function in scripts/cloudbuild/build.py, allowing for the option to utilize cached build targets. The request body generation logic now includes an isEnabled setting under buildSchedule. Enhanced error handling features retry logic for connection errors and specific HTTP status codes. The delete_current_target function has been updated to log exceptions during cloning. Overall, these modifications improve the robustness of the target cloning process.

Changes

File Path Change Summary
scripts/cloudbuild/build.py - Modified clone_current_target to include use_cache parameter.
- Updated request body to include isEnabled under buildSchedule.
- Enhanced error handling with retry logic for connection errors and specific status codes.
- Updated delete_current_target to handle and log exceptions during cloning.

Possibly related PRs

  • fix: on mac, maintain the permissions #1986: This PR also modifies scripts/cloudbuild/build.py, introducing a new class and enhancing error handling, which is related to the changes in the clone_current_target function.

🐰 In the garden where targets grow,
A cache is now a friend, you know!
With retries and logs, we’ll never fear,
Cloning builds just got more clear.
So hop along, let’s celebrate,
A smoother path we now create! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

github-actions bot commented Sep 13, 2024

badge

New build in progress, come back later!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
scripts/cloudbuild/build.py (1)

Line range hint 64-146: Approve the changes with minor suggestions.

The changes to the clone_current_target function improve the functionality and error handling of the target cloning process. The addition of the use_cache parameter and the corresponding logic to handle caching is implemented correctly. The retry logic for ConnectionError and specific status codes enhances the robustness of the function.

However, please address the following suggestions from the static analysis tools:

  • Remove the extraneous f prefix from the f-strings on lines 108, 114, and 126, as they don't contain any placeholders.

Apply this diff to address the suggestions:

-        print(f"New target found")
+        print("New target found")

-            print(f"Not using cache")
+            print("Not using cache")

-            print(f"Not using cache")
+            print("Not using cache")
Tools
Ruff

108-108: f-string without any placeholders

Remove extraneous f prefix

(F541)


114-114: f-string without any placeholders

Remove extraneous f prefix

(F541)


126-126: f-string without any placeholders

Remove extraneous f prefix

(F541)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 28ba5bc and f77197d.

Files selected for processing (1)
  • scripts/cloudbuild/build.py (6 hunks)
Additional context used
Ruff
scripts/cloudbuild/build.py

108-108: f-string without any placeholders

Remove extraneous f prefix

(F541)


114-114: f-string without any placeholders

Remove extraneous f prefix

(F541)


126-126: f-string without any placeholders

Remove extraneous f prefix

(F541)

Additional comments not posted (1)
scripts/cloudbuild/build.py (1)

Line range hint 108-146: Verify the impact of the changes on the codebase.

The changes to the clone_current_target function introduce new logic for handling caching and error scenarios. While the implementation looks correct, it's important to ensure that these changes don't introduce any unintended side effects or break existing functionality.

Please run the following script to verify the impact of the changes:

Please provide the output of running this script, and I'll be happy to review the results and provide further guidance if needed.

Verification successful

Changes to clone_current_target function are correctly implemented and integrated

The verification process has confirmed that the changes to the clone_current_target function have been properly implemented and integrated into the codebase. Key findings include:

  • The new use_cache parameter is correctly used in all function calls to clone_current_target.
  • Error handling mechanisms are in place, including retries for various scenarios such as connection errors and race conditions.
  • The TARGET environment variable is set within the function and used consistently throughout the code.

While the implementation appears correct, it's recommended to manually review the error handling and retry logic to ensure it aligns with the project's specific requirements and edge cases.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the changes to the `clone_current_target` function.

# Test 1: Search for calls to `clone_current_target` and ensure the new `use_cache` parameter is provided.
echo "Test 1: Verifying calls to clone_current_target"
rg --type python -A 5 $'clone_current_target'

# Test 2: Search for error handling related to the `clone_current_target` function.
echo "Test 2: Verifying error handling"
rg --type python -A 5 $'clone_current_target.*except'

# Test 3: Search for usage of the `TARGET` environment variable set by `clone_current_target`.
echo "Test 3: Verifying usage of TARGET environment variable"
rg --type python -A 5 $'os.getenv\(\'TARGET\'\)'

Length of output: 545


Script:

#!/bin/bash
# Description: Verify the impact of the changes to the `clone_current_target` function using alternative search methods.

# Test 1: Search for calls to `clone_current_target` and ensure the new `use_cache` parameter is provided.
echo "Test 1: Verifying calls to clone_current_target"
fd -e py -x rg -n -C 5 'clone_current_target'

# Test 2: Search for error handling related to the `clone_current_target` function.
echo "Test 2: Verifying error handling"
fd -e py -x rg -n -C 5 'clone_current_target.*except'

# Test 3: Search for usage of the `TARGET` environment variable set by `clone_current_target`.
echo "Test 3: Verifying usage of TARGET environment variable"
fd -e py -x rg -n -C 5 'os\.getenv\(["'\'']TARGET["'\'']\)'

# Test 4: Use ast-grep to find function calls to `clone_current_target`
echo "Test 4: Using ast-grep to find clone_current_target function calls"
ast-grep --lang python --pattern 'clone_current_target($_)'

# Test 5: Use ast-grep to find assignments of os.environ['TARGET']
echo "Test 5: Using ast-grep to find assignments to TARGET environment variable"
ast-grep --lang python --pattern 'os.environ["TARGET"] = $_'

Length of output: 10639

Tools
Ruff

108-108: f-string without any placeholders

Remove extraneous f prefix

(F541)


114-114: f-string without any placeholders

Remove extraneous f prefix

(F541)


126-126: f-string without any placeholders

Remove extraneous f prefix

(F541)

@aixaCode aixaCode enabled auto-merge (squash) September 16, 2024 14:34
@aixaCode aixaCode disabled auto-merge September 16, 2024 15:11
@aixaCode aixaCode merged commit 4fc0b71 into main Sep 16, 2024
2 of 4 checks passed
@aixaCode aixaCode deleted the chore/use-template-cache-for-branches branch September 16, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge no QA needed Used to tag pull requests that does not require QA validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants