Skip to content

Document new buildProfile config option #498

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

Merged
merged 3 commits into from
May 13, 2025

Conversation

MichaelBuhler
Copy link
Contributor

@MichaelBuhler MichaelBuhler commented Jan 29, 2025

Relates to game-ci/unity-builder#674
Relates to game-ci/unity-builder#685

Changes

Checklist

  • Read the contribution guide and accept the
    code of conduct
  • Readme (updated or not needed)
  • Tests (added, updated or not needed)

Summary by CodeRabbit

  • Documentation
    • Updated Unity Builder action documentation.
    • Added new optional buildProfile configuration option.
    • Updated default projectPath value to <your repository root>.
    • Improved clarity and guidance for configuration settings.
  • New Features
    • Introduced a method to build using a specified build profile for Unity versions 6.0.0 or newer.

Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

The documentation for the Unity Builder action in GitHub has been updated with a new configuration option buildProfile and a modified default value for projectPath. The changes aim to provide clearer guidance to users about configuring their Unity project builds, specifically allowing them to specify a path to a build profile relative to the root of their Unity project. Additionally, a new method BuildWithProfile has been introduced in the BuildScript class for building with a specified build profile in Unity versions 6.0.0 or newer.

Changes

File Change Summary
docs/03-github/04-builder.mdx - Added new optional buildProfile configuration option
- Updated default projectPath from <your project root> to <your repository root>
example/BuildScript.cs - Added method public static void BuildWithProfile() in BuildScript for Unity 6.0.0 or newer

Poem

🐰 A Builder's Tale, Hopping Along
In docs of GitHub, a config so bright
buildProfile joins with repository might
Project paths shifting, clear as can be
A rabbit's guide to Unity's spree! 🚀
Hop, config, build - let's make it sing! 🎉

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5ba2f and 662397e.

📒 Files selected for processing (1)
  • example/BuildScript.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • example/BuildScript.cs
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

Cat Gif

@davidmfinol
Copy link
Member

Once we've confirmed on the other PR, can we also take the changes inBuilder.cs from unity-builder and apply the equivalent to example/BuildScript.cs in this repo?

@MichaelBuhler
Copy link
Contributor Author

Once we've confirmed on the other PR, can we also take the changes inBuilder.cs from unity-builder and apply the equivalent to example/BuildScript.cs in this repo?

Sounds good.

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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f78f98d and fb8c347.

📒 Files selected for processing (2)
  • docs/03-github/04-builder.mdx (1 hunks)
  • example/BuildScript.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/03-github/04-builder.mdx
🔇 Additional comments (1)
example/BuildScript.cs (1)

7-9: LGTM! Proper version gating for Unity 6.0.0+ features.

The conditional compilation directive ensures the new BuildProfile functionality is only available for Unity 6.0.0 or newer versions.

ExitWithResult(buildSummary.result);
}
#endif

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update GetValidatedOptions for build profile support.

The GetValidatedOptions method should be updated to validate the customBuildProfile option when using Unity 6.0.0 or newer.

Apply this diff to update the method:

         private static Dictionary<string, string> GetValidatedOptions()
         {
             ParseCommandLineArguments(out Dictionary<string, string> validatedOptions);
 
+#if UNITY_6000_0_OR_NEWER
+            // Validate customBuildProfile when using BuildWithProfile
+            if (validatedOptions.TryGetValue("buildWithProfile", out string useProfile) && 
+                useProfile.ToLower() == "true" && 
+                !validatedOptions.TryGetValue("customBuildProfile", out string _))
+            {
+                Console.WriteLine("Missing argument -customBuildProfile when buildWithProfile is true");
+                EditorApplication.Exit(140);
+            }
+#endif

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 95 to 118
#if UNITY_6000_0_OR_NEWER
public static void BuildWithProfile()
{
// Gather values from args
Dictionary<string, string> options = GetValidatedOptions();

// Load build profile from Assets folder
BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(options["customBuildProfile"]);

// Set it as active
BuildProfile.SetActiveBuildProfile(buildProfile);

// Define BuildPlayerWithProfileOptions
buildPlayerWithProfileOptions = new BuildPlayerWithProfileOptions {
buildProfile = buildProfile,
locationPathName = options["customBuildPath"],
options = buildOptions,
};

BuildSummary buildSummary = BuildPipeline.BuildPlayer(buildPlayerWithProfileOptions).summary;
ReportSummary(buildSummary);
ExitWithResult(buildSummary.result);
}
#endif
Copy link

@coderabbitai coderabbitai bot Jan 31, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix compilation errors and add validation.

The new BuildWithProfile method has several issues that need to be addressed:

  1. Missing variable declarations for buildPlayerWithProfileOptions and buildOptions
  2. Missing validation for the required customBuildProfile option
  3. Missing XML documentation for the public method

Apply this diff to fix the issues:

+        /// <summary>
+        /// Builds the Unity project using a build profile for Unity 6.0.0 or newer versions.
+        /// </summary>
         public static void BuildWithProfile()
         {
             // Gather values from args
             Dictionary<string, string> options = GetValidatedOptions();
 
+            // Validate build profile path
+            if (!options.TryGetValue("customBuildProfile", out string buildProfilePath))
+            {
+                Console.WriteLine("Missing argument -customBuildProfile");
+                EditorApplication.Exit(140);
+            }
+
             // Load build profile from Assets folder
-            BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(options["customBuildProfile"]);
+            BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(buildProfilePath);
+            if (buildProfile == null)
+            {
+                Console.WriteLine($"Failed to load build profile at path: {buildProfilePath}");
+                EditorApplication.Exit(141);
+            }
 
             // Set it as active
             BuildProfile.SetActiveBuildProfile(buildProfile);
 
+            // Define build options
+            BuildOptions buildOptions = BuildOptions.None;
+
             // Define BuildPlayerWithProfileOptions
-            buildPlayerWithProfileOptions = new BuildPlayerWithProfileOptions {
+            var buildPlayerWithProfileOptions = new BuildPlayerWithProfileOptions {
                 buildProfile = buildProfile,
                 locationPathName = options["customBuildPath"],
                 options = buildOptions,
             };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#if UNITY_6000_0_OR_NEWER
public static void BuildWithProfile()
{
// Gather values from args
Dictionary<string, string> options = GetValidatedOptions();
// Load build profile from Assets folder
BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(options["customBuildProfile"]);
// Set it as active
BuildProfile.SetActiveBuildProfile(buildProfile);
// Define BuildPlayerWithProfileOptions
buildPlayerWithProfileOptions = new BuildPlayerWithProfileOptions {
buildProfile = buildProfile,
locationPathName = options["customBuildPath"],
options = buildOptions,
};
BuildSummary buildSummary = BuildPipeline.BuildPlayer(buildPlayerWithProfileOptions).summary;
ReportSummary(buildSummary);
ExitWithResult(buildSummary.result);
}
#endif
#if UNITY_6000_0_OR_NEWER
/// <summary>
/// Builds the Unity project using a build profile for Unity 6.0.0 or newer versions.
/// </summary>
public static void BuildWithProfile()
{
// Gather values from args
Dictionary<string, string> options = GetValidatedOptions();
// Validate build profile path
if (!options.TryGetValue("customBuildProfile", out string buildProfilePath))
{
Console.WriteLine("Missing argument -customBuildProfile");
EditorApplication.Exit(140);
}
// Load build profile from Assets folder
BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(buildProfilePath);
if (buildProfile == null)
{
Console.WriteLine($"Failed to load build profile at path: {buildProfilePath}");
EditorApplication.Exit(141);
}
// Set it as active
BuildProfile.SetActiveBuildProfile(buildProfile);
// Define build options
BuildOptions buildOptions = BuildOptions.None;
// Define BuildPlayerWithProfileOptions
var buildPlayerWithProfileOptions = new BuildPlayerWithProfileOptions {
buildProfile = buildProfile,
locationPathName = options["customBuildPath"],
options = buildOptions,
};
BuildSummary buildSummary = BuildPipeline.BuildPlayer(buildPlayerWithProfileOptions).summary;
ReportSummary(buildSummary);
ExitWithResult(buildSummary.result);
}
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coderabbitai Good catch! I am updating this now.

Copy link

Choose a reason for hiding this comment

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

@MichaelBuhler Thanks for addressing these issues! Looking forward to reviewing the updates.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved 1.

Skipping 2. and 3.

Copy link

Choose a reason for hiding this comment

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

@MichaelBuhler Thanks for fixing the compilation errors! I understand your decision to skip the validation and documentation improvements. Let me know if you need any further assistance!

@MichaelBuhler
Copy link
Contributor Author

MichaelBuhler commented Jan 31, 2025

@davidmfinol I am pushed a simple implementation: 2f5ba2f

I think that if the user is going to write their own build method for BuildProfile build, it is going to be quite simple and not muddied with supporting old platform builds. I don't really every see the need to go back to doing platform builds after adopting Unity 6 build profiles.

Copy link
Member

@davidmfinol davidmfinol left a comment

Choose a reason for hiding this comment

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

Noticed that buildOptions isn't defined in the BuildScript

@davidmfinol davidmfinol enabled auto-merge (squash) May 13, 2025 14:10
@davidmfinol davidmfinol merged commit 2d16ea8 into game-ci:main May 13, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants