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

Document new buildProfile config option #498

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MichaelBuhler
Copy link

@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! 🎉


📜 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 fb8c347 and 2f5ba2f.

📒 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

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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • 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 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 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 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
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
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
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
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.


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

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Get all buildOptions from options
BuildOptions buildOptions = BuildOptions.None;
foreach (string buildOptionString in Enum.GetNames(typeof(BuildOptions))) {
if (options.ContainsKey(buildOptionString)) {
BuildOptions buildOptionEnum = (BuildOptions) Enum.Parse(typeof(BuildOptions), buildOptionString);
buildOptions |= buildOptionEnum;
}
}

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

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