-
-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically grab good file version (#10632)
- Loading branch information
Showing
4 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using DatabaseAPI; | ||
using Logs; | ||
using Newtonsoft.Json; | ||
using SecureStuff; | ||
using UnityEditor; | ||
using UnityEditor.Build; | ||
using UnityEngine; | ||
|
||
public class GrabGoodFileVersion : IPreprocessBuild | ||
{ | ||
public int callbackOrder | ||
{ | ||
get { return 9; } | ||
} | ||
|
||
public void OnPreprocessBuild(BuildTarget target, string path) | ||
{ | ||
var Gamedata = AssetDatabase.LoadAssetAtPath<GameObject>( | ||
"Assets/Prefabs/SceneConstruction/NestedManagers/GameData.prefab"); | ||
if (Gamedata.GetComponent<GameData>().DevBuild) | ||
{ | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
// Get the latest good-file version tag | ||
string latestTag = GetLatestGoodFileVersion(); | ||
|
||
var BuildInfo = JsonConvert.DeserializeObject<BuildInfo>(AccessFile.Load("buildinfo.json")); | ||
BuildInfo.GoodFileVersion = latestTag.Replace("good-file-", ""); | ||
AccessFile.Save("buildinfo.json", JsonConvert.SerializeObject(BuildInfo)); | ||
} | ||
catch ( Exception ex) | ||
{ | ||
Loggy.Warning( "Not able to set good file version " + ex.ToString()); | ||
|
||
} | ||
} | ||
|
||
private string GetLatestGoodFileVersion() | ||
{ | ||
try | ||
{ | ||
// Set up the Git process to get tags | ||
Process gitProcess = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo | ||
{ | ||
FileName = "git", | ||
Arguments = "tag --list good-file-* --sort=-v:refname", | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = true | ||
} | ||
}; | ||
|
||
UnityEngine.Debug.Log("[GrabGoodFileVersion] Running Git command to fetch tags..."); | ||
UnityEngine.Debug.Log($"[GrabGoodFileVersion] Command: git {gitProcess.StartInfo.Arguments}"); | ||
|
||
// Start the process and capture the output | ||
gitProcess.Start(); | ||
string output = gitProcess.StandardOutput.ReadToEnd().Trim(); | ||
string error = gitProcess.StandardError.ReadToEnd(); | ||
gitProcess.WaitForExit(); | ||
|
||
UnityEngine.Debug.Log($"[GrabGoodFileVersion] Git process exited with code {gitProcess.ExitCode}."); | ||
UnityEngine.Debug.Log($"[GrabGoodFileVersion] Standard Output:\n{output}"); | ||
UnityEngine.Debug.Log($"[GrabGoodFileVersion] Standard Error:\n{error}"); | ||
|
||
if (gitProcess.ExitCode != 0) | ||
{ | ||
UnityEngine.Debug.LogError($"[GrabGoodFileVersion] Git process failed with exit code {gitProcess.ExitCode}."); | ||
return null; | ||
} | ||
|
||
// Split the output into lines and take the first line as the latest tag | ||
string[] tags = output.Split('\n'); | ||
return tags.Length > 0 ? tags[0] : null;; | ||
} | ||
catch (System.Exception ex) | ||
{ | ||
UnityEngine.Debug.LogError($"An error occurred while retrieving the Git tag: {ex.Message}"); | ||
return null; | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
UnityProject/Assets/Scripts/Core/Editor/GrabGoodFileVersion.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"BuildNumber": 3921,"ForkName":"Unitystation"} | ||
{"BuildNumber":3921,"ForkName":"Unitystation","GoodFileVersion":"good-file-0.1.0"} |