Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b435a285 authored by MONSEIGNE Thibaut's avatar MONSEIGNE Thibaut
Browse files

:construction_worker: Fix Build on CI

:construction_worker: Fix Build on CI
parent efd331a5
No related branches found
No related tags found
No related merge requests found
Pipeline #135638 passed
......@@ -71,3 +71,6 @@ crashlytics-build.properties
# Avoid setting files (I don't know why it doesn't work)
*.DotSettings
.editorconfig
**.meta
Documentation/index.md
......@@ -36,7 +36,7 @@ build:
LogFile: BuildLogs.txt
script:
# Build for PC
- eval $Unity -batchmode -quit -projectPath . -logFile $LogFile
- eval $Unity -batchmode -quit -projectPath . -logFile $LogFile -executeMethod OVGames.HelloWorld.Editor.BuildHooks.BuildAll
# Job fail if a build failed
- grep 'result="error CS"' $LogFile && exit 1 || exit 0
artifacts:
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEditor;
using UnityEditor.Build.Reporting;
namespace OVGames.HelloWorld.Editor
{
/// <summary> Wrapper of <see cref="BuildPlayerOptions"/> with improved build path configuration. </summary>
public sealed class BuildConfig
{
private BuildPlayerOptions options = new BuildPlayerOptions();
/// <summary> Gets or sets the location of the build directory, relative to the project root directory. </summary>
public string DirectoryPath { get; set; }
/// <summary> Gets or set the location of the application to build, relative to <see cref="DirectoryPath"/>. </summary>
public string RelativeFilePath { get; set; }
/// <summary> Gets or sets the <see cref="Action"/> to execute after
/// <see cref="BuildPipeline.BuildPlayer(BuildPlayerOptions)"/> with the <see cref="BuildReport"/>. </summary>
public Action<BuildReport> AfterBuild { get; set; }
/// <summary> Gets or sets the options for <see cref="BuildPipeline.BuildPlayer(BuildPlayerOptions)"/>. </summary>
/// <remarks> <see cref="BuildPlayerOptions.locationPathName"/> is automatically set to
/// <see cref="DirectoryPath"/> + <see cref="RelativeFilePath"/>. </remarks>
public BuildPlayerOptions Options
{
get
{
options.locationPathName = DirectoryPath + RelativeFilePath;
return options;
}
set => options = value;
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build.Reporting;
namespace OVGames.HelloWorld.Editor
{
/// <summary> Build and/or run for different <see cref="BuildTarget"/>. Supported platforms are <see cref="BuildTarget.StandaloneWindows64"/>. </summary>
public static class BuildHooks
{
/// <summary> Path to the builds, relative to the project root folder. </summary>
public const string BUILD_PATH = "Builds/";
/// <summary> Name of the build. /// </summary>
public const string FILENAME = "Hello World";
/// <summary> The path of the scene to build, relative to the project root folder. </summary>
public static readonly string[] scenesPath = { "Assets/Scenes/main.unity" };
/// <summary>
/// List of <see cref="BuildConfig"/> for supported <see cref="BuildTarget"/>.
/// </summary>
public static readonly Dictionary<BuildTarget, BuildConfig> configs = new Dictionary<BuildTarget, BuildConfig>()
{
{
BuildTarget.StandaloneWindows64,
new BuildConfig()
{
DirectoryPath = BUILD_PATH + "Windows/",
RelativeFilePath = FILENAME + ".exe",
Options = new BuildPlayerOptions()
{
scenes = scenesPath,
target = BuildTarget.StandaloneWindows64
},
AfterBuild = buildReport => { }
}
}
};
/// <summary> Calls <see cref="BuildWindows"/>. </summary>
[MenuItem("OVGames/Hello World/Build for all platforms", priority = 0)]
public static void BuildAll() { BuildWindows(); }
/// <summary> Calls <see cref="BuildRunWindows"/>. </summary>
[MenuItem("OVGames/Hello World/Build and Run all platforms", priority = 1)]
public static void BuildRundAll() { BuildRunWindows(); }
/// <summary> Calls <see cref="Build(BuildTarget, bool)"/> to build for <see cref="BuildTarget.StandaloneWindows64"/>. </summary>
[MenuItem("OVGames/Hello World/Build for Windows", priority = 100)]
public static void BuildWindows() { Build( /*BuildTarget.StandaloneWindows64, andRun: false*/); }
/// <summary> Calls <see cref="Build(BuildTarget, bool)"/> to build and run for <see cref="BuildTarget.StandaloneWindows64"/>. </summary>
[MenuItem("OVGames/Hello World/Build and Run for Windows", priority = 101)]
public static void BuildRunWindows() { Build(BuildTarget.StandaloneWindows64, andRun: true); }
/// <summary> Build for the specified <see cref="BuildTarget"/>. </summary>
/// <param name="target"> The <see cref="BuildTarget"/> to build. </param>
/// <param name="andRun"> Automatically run or not the build. </param>
public static void Build(BuildTarget target = BuildTarget.StandaloneWindows64, bool andRun = false)
{
// Get configuration
if (!configs.TryGetValue(target, out var configuration))
{
throw new ArgumentException($"The {target} platform is not supported.", nameof(target));
}
// Clear previous build
var path = new DirectoryInfo(configuration.DirectoryPath);
if (path.Exists) { path.Delete(recursive: true); }
// Update build options
var options = configuration.Options;
options.options |= BuildOptions.StrictMode;
if (andRun) { options.options |= BuildOptions.AutoRunPlayer; }
configuration.Options = options;
// Build
var report = BuildPipeline.BuildPlayer(configuration.Options);
var summary = new StringBuilder();
summary.AppendLine($"Build {target} target {report.summary.result}");
foreach (var step in report.steps)
{
summary.AppendLine();
summary.AppendLine(step.ToString());
foreach (var message in step.messages) { summary.AppendLine($"{message.type}: {message.content}"); }
}
Debug.Log(summary);
// After build
configuration.AfterBuild?.Invoke(report);
}
}
}
fileFormatVersion: 2
guid: 2c950a585ea6d9f44b1bdf869d7e2deb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: b215deda29eaec74c8224960df0f861a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 21979a78add3606478b948018369317c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 60cccd48c61b7584d84ae9ad35c1a949
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 0b3bb84d32bcb2944bdb33f6f00a4881
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 9fc0d4010bbf28b4594072e72b8655ab
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bbab9d90c64380e4691bd0554e28114d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 3fccaf98eee689c43b2b0a573f7f5e21
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bb7dc342a4384c66a5915e670a3bcba1
timeCreated: 1583931462
\ No newline at end of file
fileFormatVersion: 2
guid: 32c1af7700b2ec64293f222db86765dd
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f595da02601a05a4c8159e37aa87d213
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment