- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 299
          feat: add buildProfile parameter
          #685
        
          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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -6,6 +6,9 @@ | |
| using UnityBuilderAction.Versioning; | ||
| using UnityEditor; | ||
| using UnityEditor.Build.Reporting; | ||
| #if UNITY_6000_0_OR_NEWER | ||
| using UnityEditor.Build.Profile; | ||
| #endif | ||
| 
      Comment on lines
    
      +9
     to 
      +11
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, that'd probably be a great idea! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I am mistaken, the  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ For this reason, I think the code in  Such as most of these jobs: https://github.com/game-ci/unity-builder/actions/runs/13057500403 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 That’s correct for script usage, but opening the file in JetBrains Rider with Unity integration makes sense for development. 
 ✅ That is correct 
 I definitely agree that the code in  I can confirm the folder itself is a Unity project. The directory structure of `dist/default-build-script`
 My suggestion is more about files like  The main goal was to open the project in Unity/Rider to check for issues. I'm just lacking an older version on my system. I’m still unsure if we should upgrade the project in that folder, it likely wouldn’t make much difference, but might make sense for development. :) 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GabLeRoux Ah, I get what you are saying. That's actually what I did: I copied  | ||
| using UnityEngine; | ||
|  | ||
| namespace UnityBuilderAction | ||
|  | @@ -17,47 +20,9 @@ public static void BuildProject() | |
| // Gather values from args | ||
| var options = ArgumentsParser.GetValidatedOptions(); | ||
|  | ||
| // Gather values from project | ||
| var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray(); | ||
|  | ||
| // 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; | ||
| } | ||
| } | ||
|  | ||
| #if UNITY_2021_2_OR_NEWER | ||
| // Determine subtarget | ||
| StandaloneBuildSubtarget buildSubtarget; | ||
| if (!options.TryGetValue("standaloneBuildSubtarget", out var subtargetValue) || !Enum.TryParse(subtargetValue, out buildSubtarget)) { | ||
| buildSubtarget = default; | ||
| } | ||
| #endif | ||
|  | ||
| // Define BuildPlayer Options | ||
| var buildPlayerOptions = new BuildPlayerOptions { | ||
| scenes = scenes, | ||
| locationPathName = options["customBuildPath"], | ||
| target = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]), | ||
| options = buildOptions, | ||
| #if UNITY_2021_2_OR_NEWER | ||
| subtarget = (int) buildSubtarget | ||
| #endif | ||
| }; | ||
|  | ||
| // Set version for this build | ||
| VersionApplicator.SetVersion(options["buildVersion"]); | ||
|  | ||
| // Apply Android settings | ||
| if (buildPlayerOptions.target == BuildTarget.Android) | ||
| { | ||
| VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]); | ||
| AndroidSettings.Apply(options); | ||
| } | ||
|  | ||
|  | ||
| // Execute default AddressableAsset content build, if the package is installed. | ||
| // Version defines would be the best solution here, but Unity 2018 doesn't support that, | ||
| // so we fall back to using reflection instead. | ||
|  | @@ -78,6 +43,72 @@ public static void BuildProject() | |
| } | ||
| } | ||
|  | ||
| // 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; | ||
| } | ||
| } | ||
|  | ||
| // Depending on whether the build is using a build profile, `buildPlayerOptions` will an instance | ||
| // of either `UnityEditor.BuildPlayerOptions` or `UnityEditor.BuildPlayerWithProfileOptions` | ||
| dynamic buildPlayerOptions; | ||
|  | ||
| if (options["customBuildProfile"] != "") { | ||
|  | ||
| #if UNITY_6000_0_OR_NEWER | ||
| // Load build profile from Assets folder | ||
| BuildProfile buildProfile = AssetDatabase.LoadAssetAtPath<BuildProfile>(options["customBuildProfile"]); | ||
|  | ||
| // Set it as active | ||
| BuildProfile.SetActiveBuildProfile(buildProfile); | ||
|  | ||
| // Define BuildPlayerWithProfileOptions | ||
| buildPlayerOptions = new BuildPlayerWithProfileOptions { | ||
| buildProfile = buildProfile, | ||
| locationPathName = options["customBuildPath"], | ||
| options = buildOptions, | ||
| }; | ||
| #else | ||
| throw new Exception("Build profiles are not supported by this version of Unity (" + Application.unityVersion +")"); | ||
| #endif | ||
|  | ||
| } else { | ||
|  | ||
| // Gather values from project | ||
| var scenes = EditorBuildSettings.scenes.Where(scene => scene.enabled).Select(s => s.path).ToArray(); | ||
|  | ||
| #if UNITY_2021_2_OR_NEWER | ||
| // Determine subtarget | ||
| StandaloneBuildSubtarget buildSubtarget; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do build profiles set StandaloneBuildSubtarget? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's appears to me that the Build Profile feature eliminates the need for defining the build subtarget. The old build method works by setting  Rather,    There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, then we should be fine to ignore subtarget when using a build profile. We may just want to add a comment about it to the docs. | ||
| if (!options.TryGetValue("standaloneBuildSubtarget", out var subtargetValue) || !Enum.TryParse(subtargetValue, out buildSubtarget)) { | ||
| buildSubtarget = default; | ||
| } | ||
| #endif | ||
|  | ||
| BuildTarget buildTarget = (BuildTarget) Enum.Parse(typeof(BuildTarget), options["buildTarget"]); | ||
|  | ||
| // Define BuildPlayerOptions | ||
| buildPlayerOptions = new BuildPlayerOptions { | ||
| scenes = scenes, | ||
| locationPathName = options["customBuildPath"], | ||
| target = buildTarget, | ||
| options = buildOptions, | ||
| #if UNITY_2021_2_OR_NEWER | ||
| subtarget = (int) buildSubtarget | ||
| #endif | ||
| }; | ||
|  | ||
| // Apply Android settings | ||
| if (buildTarget == BuildTarget.Android) { | ||
| VersionApplicator.SetAndroidVersionCode(options["androidVersionCode"]); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we still set the  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a complex question, which applies not only to the version code, but also to all other Android settings supported by this  You can set the Android Bundle Version Code within the Build Profile itself. In this case I suppose that you would run the GitHub action with  However, if you want to rely on the GitHub action to determine the version code... I think I have not implemented that--actually, it might even be impossible: After we load the  From decompiled code, I can see that the  I would guess that Unity will add these features/abilities in a later version, but they do not seem to be in Unity 6.1 Beta, yet. So, I suppose the only possible solution today would be to modify (edit in place) the build profile's    This resulted in this on line 206 of the      - line: '|   AndroidBundleVersionCode: 990099'So we would have to Regex replace that 6-digit value before launching Unity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, we may want to create a follow-up issue to check on setting Android version code when using a build profile, but I don't think that should be a blocker for this PR. | ||
| AndroidSettings.Apply(options); | ||
| } | ||
|  | ||
| } | ||
|  | ||
| // Perform build | ||
| BuildReport buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions); | ||
|  | ||
|  | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -19,6 +19,23 @@ echo "Using build name \"$BUILD_NAME\"." | |
|  | ||
| echo "Using build target \"$BUILD_TARGET\"." | ||
|  | ||
| # | ||
| # Display the build profile | ||
| # | ||
|  | ||
| if [ -z "$BUILD_PROFILE" ]; then | ||
| # User has not provided a build profile | ||
| # | ||
| echo "Doing a default \"$BUILD_TARGET\" platform build." | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already said on line 20. | ||
| # | ||
| else | ||
| # User has provided a path to a build profile `.asset` file | ||
| # | ||
| echo "Using build profile \"$BUILD_PROFILE\" relative to \"$UNITY_PROJECT_PATH\"." | ||
| # | ||
| fi | ||
|  | ||
|  | ||
| # | ||
| # Display build path and file | ||
| # | ||
|  | @@ -139,6 +156,7 @@ echo "" | |
| -buildTarget "$BUILD_TARGET" \ | ||
| -customBuildTarget "$BUILD_TARGET" \ | ||
| -customBuildPath "$CUSTOM_BUILD_PATH" \ | ||
| -customBuildProfile "$BUILD_PROFILE" \ | ||
| -executeMethod "$BUILD_METHOD" \ | ||
| -buildVersion "$VERSION" \ | ||
| -androidVersionCode "$ANDROID_VERSION_CODE" \ | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -19,6 +19,22 @@ echo "Using build name \"$BUILD_NAME\"." | |
|  | ||
| echo "Using build target \"$BUILD_TARGET\"." | ||
|  | ||
| # | ||
| # Display the build profile | ||
| # | ||
|  | ||
| if [ -z "$BUILD_PROFILE" ]; then | ||
| # User has not provided a build profile | ||
| # | ||
| echo "Doing a default \"$BUILD_TARGET\" platform build." | ||
| # | ||
| else | ||
| # User has provided a path to a build profile `.asset` file | ||
| # | ||
| echo "Using build profile \"$BUILD_PROFILE\" relative to \"$UNITY_PROJECT_PATH\"." | ||
| 
      Comment on lines
    
      +29
     to 
      +34
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here | ||
| # | ||
| fi | ||
|  | ||
| # | ||
| # Display build path and file | ||
| # | ||
|  | @@ -112,6 +128,7 @@ unity-editor \ | |
| -buildTarget "$BUILD_TARGET" \ | ||
| -customBuildTarget "$BUILD_TARGET" \ | ||
| -customBuildPath "$CUSTOM_BUILD_PATH" \ | ||
| -customBuildProfile "$BUILD_PROFILE" \ | ||
| -executeMethod "$BUILD_METHOD" \ | ||
| -buildVersion "$VERSION" \ | ||
| -androidVersionCode "$ANDROID_VERSION_CODE" \ | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -16,6 +16,25 @@ Write-Output "$('Using build name "')$($Env:BUILD_NAME)$('".')" | |
|  | ||
| Write-Output "$('Using build target "')$($Env:BUILD_TARGET)$('".')" | ||
|  | ||
| # | ||
| # Display the build profile | ||
| # | ||
|  | ||
| if ($Env:BUILD_PROFILE) | ||
| { | ||
| # User has provided a path to a build profile `.asset` file | ||
| # | ||
| Write-Output "$('Using build profile "')$($Env:BUILD_PROFILE)$('" relative to "')$($Env:UNITY_PROJECT_PATH)$('".')" | ||
| # | ||
| } | ||
| else | ||
| { | ||
| # User has not provided a build profile | ||
| # | ||
| Write-Output "$('Doing a default "')$($Env:BUILD_TARGET)$('" platform build.')" | ||
| 
      Comment on lines
    
      +27
     to 
      +34
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here | ||
| # | ||
| } | ||
|  | ||
| # | ||
| # Display build path and file | ||
| # | ||
|  | @@ -143,6 +162,7 @@ $unityArgs = @( | |
| "-buildTarget", "`"$Env:BUILD_TARGET`"", | ||
| "-customBuildTarget", "`"$Env:BUILD_TARGET`"", | ||
| "-customBuildPath", "`"$Env:CUSTOM_BUILD_PATH`"", | ||
| "-customBuildProfile", "`"$Env:BUILD_PROFILE`"", | ||
| "-buildVersion", "`"$Env:VERSION`"", | ||
| "-androidVersionCode", "`"$Env:ANDROID_VERSION_CODE`"", | ||
| "-androidKeystorePass", "`"$Env:ANDROID_KEYSTORE_PASS`"", | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -59,6 +59,19 @@ describe('Input', () => { | |
| }); | ||
| }); | ||
|  | ||
| describe('buildProfile', () => { | ||
| it('returns the default value', () => { | ||
| expect(Input.buildProfile).toStrictEqual(''); | ||
| }); | ||
|  | ||
| it('takes input from the users workflow', () => { | ||
| const mockValue = 'path/to/build_profile.asset'; | ||
| const spy = jest.spyOn(core, 'getInput').mockReturnValue(mockValue); | ||
| expect(Input.buildProfile).toStrictEqual(mockValue); | ||
| expect(spy).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); | ||
| 
      Comment on lines
    
      +62
     to 
      +73
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test gods thank you for your contribution | ||
|  | ||
| describe('buildName', () => { | ||
| it('returns the default value', () => { | ||
| expect(Input.buildName).toStrictEqual(Input.targetPlatform); | ||
|  | ||


Uh oh!
There was an error while loading. Please reload this page.