From b5356375f1185121a4798a0efbf3e91696a9b59f Mon Sep 17 00:00:00 2001 From: robGG1997 Date: Thu, 14 Sep 2023 11:30:11 +0300 Subject: [PATCH 01/62] Revert "automated duplicating imported samples modifications (#595)" This reverts commit a5558941827a91df51e2dd200648dcd13a1231c8. --- .github/workflows/duplicate_sample.yaml | 28 ------------------- duplicate_package_sample.sh | 14 ---------- .../Samples~/Web3.Unity/Prefabs.meta | 8 ------ .../Samples~/Web3.Unity/Scenes.meta | 8 ------ .../Samples~/Web3.Unity/Scripts.meta | 8 ------ .../Samples~/Web3.Unity/Sprites.meta | 8 ------ 6 files changed, 74 deletions(-) delete mode 100644 .github/workflows/duplicate_sample.yaml delete mode 100644 duplicate_package_sample.sh delete mode 100644 src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Prefabs.meta delete mode 100644 src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scenes.meta delete mode 100644 src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scripts.meta delete mode 100644 src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Sprites.meta diff --git a/.github/workflows/duplicate_sample.yaml b/.github/workflows/duplicate_sample.yaml deleted file mode 100644 index 793149e56..000000000 --- a/.github/workflows/duplicate_sample.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: Duplicate-Package-Sample - -on: - push: - branches: - - main - -jobs: - duplicate: - name: duplicate package sample - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Run duplicate script file - run: bash ${GITHUB_WORKSPACE}/duplicate_package_sample.sh - - - name: Commit and Push - run: | - git config --global user.email $git_email - git config --global user.name "${{ github.actor }}" - git add ./src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/. -f - git diff-index --cached --quiet HEAD || git commit -m "Auto-duplicate Package Samples" - git push - env: - git_email: "${{ github.actor }}@users.noreply.github.com" \ No newline at end of file diff --git a/duplicate_package_sample.sh b/duplicate_package_sample.sh deleted file mode 100644 index f3a677742..000000000 --- a/duplicate_package_sample.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Specify the source directory and the destination directory -SOURCE_DIRECTORY="src/UnitySampleProject/Assets/Samples/web3.unity SDK/2.5.0-pre001/Web3.Unity Samples/" -DESTINATION_DIRECTORY="src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/" - -# clear destination directory first -rm -r "$DESTINATION_DIRECTORY" - -# Copy source to the destination -cp -r "$SOURCE_DIRECTORY" "$DESTINATION_DIRECTORY" - -#add all modified files -git add "src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/." -f \ No newline at end of file diff --git a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Prefabs.meta b/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Prefabs.meta deleted file mode 100644 index 5b35daff8..000000000 --- a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Prefabs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 45a04d2621549e3458049c6c447c3941 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scenes.meta b/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scenes.meta deleted file mode 100644 index 5488a62ed..000000000 --- a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scenes.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f39f8dda9616349489a7803d7e0aff30 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scripts.meta b/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scripts.meta deleted file mode 100644 index 9a1e8b8d4..000000000 --- a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Scripts.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: eaef630f284e6e04a88b5939e0eb1cc5 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Sprites.meta b/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Sprites.meta deleted file mode 100644 index 7175ee89d..000000000 --- a/src/UnityPackages/io.chainsafe.web3-unity/Samples~/Web3.Unity/Sprites.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 0c06517aee7843642a091a67c72b1379 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From cd514db5c9d0bb82e069293c669733864d41544e Mon Sep 17 00:00:00 2001 From: robGG1997 Date: Wed, 7 Feb 2024 13:35:15 +0300 Subject: [PATCH 02/62] made main package testable, revert due to a mistake --- src/UnitySampleProject/Packages/manifest.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/UnitySampleProject/Packages/manifest.json b/src/UnitySampleProject/Packages/manifest.json index 08c0ac92f..22a37ba40 100644 --- a/src/UnitySampleProject/Packages/manifest.json +++ b/src/UnitySampleProject/Packages/manifest.json @@ -47,5 +47,8 @@ "com.unity.modules.wind": "1.0.0", "com.unity.modules.xr": "1.0.0", "com.tools.webglthreadingpatcher": "https://github.com/VolodymyrBS/WebGLThreadingPatcher.git" - } + }, + "testables": [ + "io.chainsafe.web3-unity" + ] } \ No newline at end of file From b790421926ad76db4084933d916fedf26a490a8e Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 12:01:19 +0300 Subject: [PATCH 03/62] initial commit to test CI --- .github/workflows/setup.yaml | 22 ++++++++++++++++++++++ Setup/Package.cs | 29 +++++++++++++++++++++++++++++ Setup/Program.cs | 26 ++++++++++++++++++++++++++ Setup/Setup.csproj | 12 ++++++++++++ Setup/Setup.sln | 16 ++++++++++++++++ Setup/packages.json | 9 +++++++++ 6 files changed, 114 insertions(+) create mode 100644 .github/workflows/setup.yaml create mode 100644 Setup/Package.cs create mode 100644 Setup/Program.cs create mode 100644 Setup/Setup.csproj create mode 100644 Setup/Setup.sln create mode 100644 Setup/packages.json diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml new file mode 100644 index 000000000..af4226e26 --- /dev/null +++ b/.github/workflows/setup.yaml @@ -0,0 +1,22 @@ +name: Setup Workflow + +on: + push: + branches: + - rob/publish-and-release-tool-1120 + +jobs: + setup: + name: Setup job + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Run + run: dotnet run Setup/Setup.csproj diff --git a/Setup/Package.cs b/Setup/Package.cs new file mode 100644 index 000000000..a8f5eb8b0 --- /dev/null +++ b/Setup/Package.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Setup +{ + public struct Package + { + [JsonProperty("name")] + public string Name { get; private set; } + + [JsonProperty("version")] + public string Version { get; private set; } + + [JsonProperty("dependencies")] + public Dictionary Dependencies { get; private set; } + + [JsonProperty("testables")] + public string[] Testables { get; private set; } + + [JsonProperty("samples")] + public Sample[] Samples { get; private set; } + } + + public struct Sample + { + [JsonProperty("path")] + public string Path { get; private set; } + } +} \ No newline at end of file diff --git a/Setup/Program.cs b/Setup/Program.cs new file mode 100644 index 000000000..1951c4b70 --- /dev/null +++ b/Setup/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Newtonsoft.Json; + +namespace Setup +{ + internal class Program + { + public static readonly List Packages = new List(); + + static void Main(string[] args) + { + string json = File.ReadAllText("Setup/packages.json"); + + string[] paths = JsonConvert.DeserializeObject(json); + + foreach (string path in paths) + { + Packages.Add(JsonConvert.DeserializeObject(File.ReadAllText(path))); + } + + Console.Write(JsonConvert.SerializeObject(Packages, Formatting.Indented)); + } + } +} \ No newline at end of file diff --git a/Setup/Setup.csproj b/Setup/Setup.csproj new file mode 100644 index 000000000..b35ce995f --- /dev/null +++ b/Setup/Setup.csproj @@ -0,0 +1,12 @@ + + + + net8.0 + Exe + + + + + + + diff --git a/Setup/Setup.sln b/Setup/Setup.sln new file mode 100644 index 000000000..7f4309e79 --- /dev/null +++ b/Setup/Setup.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Setup", "Setup.csproj", "{9EE36F23-7E56-4398-B7DE-E683097CE49F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9EE36F23-7E56-4398-B7DE-E683097CE49F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9EE36F23-7E56-4398-B7DE-E683097CE49F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9EE36F23-7E56-4398-B7DE-E683097CE49F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9EE36F23-7E56-4398-B7DE-E683097CE49F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Setup/packages.json b/Setup/packages.json new file mode 100644 index 000000000..75cd3b856 --- /dev/null +++ b/Setup/packages.json @@ -0,0 +1,9 @@ +[ + "Packages\\io.chainsafe.web3-unity\\package.json", + "Packages\\io.chainsafe.web3-unity.hyperplay\\package.json", + "Packages\\io.chainsafe.web3-unity.lootboxes\\package.json", + "Packages\\io.chainsafe.web3-unity.marketplace\\package.json", + "Packages\\io.chainsafe.web3-unity.mud\\package.json", + "Packages\\io.chainsafe.web3-unity.ramp\\package.json", + "Packages\\io.chainsafe.web3-unity.web3auth\\package.json" +] \ No newline at end of file From d62336f9ec0bafc7e05e8f886a78cb664559a57b Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 12:04:21 +0300 Subject: [PATCH 04/62] path updated --- .github/workflows/setup.yaml | 4 +++- Setup/Program.cs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index af4226e26..81f0f85b7 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -19,4 +19,6 @@ jobs: dotnet-version: 8.0.x - name: Run - run: dotnet run Setup/Setup.csproj + run: | + cd Setup + dotnet run Setup/Setup.csproj diff --git a/Setup/Program.cs b/Setup/Program.cs index 1951c4b70..345b53984 100644 --- a/Setup/Program.cs +++ b/Setup/Program.cs @@ -11,13 +11,13 @@ internal class Program static void Main(string[] args) { - string json = File.ReadAllText("Setup/packages.json"); + string json = File.ReadAllText("packages.json"); string[] paths = JsonConvert.DeserializeObject(json); foreach (string path in paths) { - Packages.Add(JsonConvert.DeserializeObject(File.ReadAllText(path))); + Packages.Add(JsonConvert.DeserializeObject(File.ReadAllText($"../{path}"))); } Console.Write(JsonConvert.SerializeObject(Packages, Formatting.Indented)); From 24891d0ea6b150173f52b3794faced6ba12de637 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 12:05:43 +0300 Subject: [PATCH 05/62] path updated for linux --- Setup/packages.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Setup/packages.json b/Setup/packages.json index 75cd3b856..4aa46954f 100644 --- a/Setup/packages.json +++ b/Setup/packages.json @@ -1,9 +1,9 @@ [ - "Packages\\io.chainsafe.web3-unity\\package.json", - "Packages\\io.chainsafe.web3-unity.hyperplay\\package.json", - "Packages\\io.chainsafe.web3-unity.lootboxes\\package.json", - "Packages\\io.chainsafe.web3-unity.marketplace\\package.json", - "Packages\\io.chainsafe.web3-unity.mud\\package.json", - "Packages\\io.chainsafe.web3-unity.ramp\\package.json", - "Packages\\io.chainsafe.web3-unity.web3auth\\package.json" + "Packages/io.chainsafe.web3-unity/package.json", + "Packages/io.chainsafe.web3-unity.hyperplay/package.json", + "Packages/io.chainsafe.web3-unity.lootboxes/package.json", + "Packages/io.chainsafe.web3-unity.marketplace/package.json", + "Packages/io.chainsafe.web3-unity.mud/package.json", + "Packages/io.chainsafe.web3-unity.ramp/package.json", + "Packages/io.chainsafe.web3-unity.web3auth/package.json" ] \ No newline at end of file From a8b9fda14726dee1c247bb7b77f4bf6b62b61b34 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 13:24:33 +0300 Subject: [PATCH 06/62] Packages version changes implemented --- Setup/Package.cs | 58 ++++++++++++++++++++++++++++++++++++++++++------ Setup/Program.cs | 29 ++++++++++++++++++++---- Setup/Release.cs | 25 +++++++++++++++++++++ 3 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 Setup/Release.cs diff --git a/Setup/Package.cs b/Setup/Package.cs index a8f5eb8b0..d913b68d1 100644 --- a/Setup/Package.cs +++ b/Setup/Package.cs @@ -1,24 +1,68 @@ +using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace Setup { - public struct Package + public class Package { - [JsonProperty("name")] - public string Name { get; private set; } - + [JsonIgnore] + public string Path { get; private set; } + [JsonProperty("version")] public string Version { get; private set; } - [JsonProperty("dependencies")] + [JsonProperty("dependencies", NullValueHandling = NullValueHandling.Ignore)] public Dictionary Dependencies { get; private set; } - [JsonProperty("testables")] + [JsonProperty("testables", NullValueHandling = NullValueHandling.Ignore)] public string[] Testables { get; private set; } - [JsonProperty("samples")] + [JsonProperty("samples", NullValueHandling = NullValueHandling.Ignore)] public Sample[] Samples { get; private set; } + + // For Json Deserialize. + public Package() + { + + } + + public Package(string path) + { + Path = path; + } + + public void SetVersion(string version) + { + string[] increments = version.Split('.'); + + if (increments.Length != 3 + || !increments.Any(i => int.TryParse(i, out _) + || int.Parse(i) < 0 + || int.Parse(i) > 9)) + { + throw new Exception("Incorrect Version Format https://semver.org/"); + } + + Version = version; + } + + public void Save() + { + string json = File.ReadAllText(Path); + + JObject jObject = JObject.Parse(json); + + jObject.Merge(JObject.Parse(JsonConvert.SerializeObject(this)), new JsonMergeSettings + { + MergeArrayHandling = MergeArrayHandling.Merge + }); + + File.WriteAllText(Path, jObject.ToString(Formatting.Indented)); + } } public struct Sample diff --git a/Setup/Program.cs b/Setup/Program.cs index 345b53984..f82ab34c2 100644 --- a/Setup/Program.cs +++ b/Setup/Program.cs @@ -9,18 +9,39 @@ internal class Program { public static readonly List Packages = new List(); + // dotnet run -release:3.0.0 -duplicate_samples -publish_dependencies; static void Main(string[] args) { string json = File.ReadAllText("packages.json"); string[] paths = JsonConvert.DeserializeObject(json); - - foreach (string path in paths) + + for (int i = 0; i < paths.Length; i++) { - Packages.Add(JsonConvert.DeserializeObject(File.ReadAllText($"../{path}"))); + string path = $"../{paths[i]}"; + + Package package = new Package(path); + + JsonConvert.PopulateObject(File.ReadAllText(path), package); + + Packages.Add(package); } - Console.Write(JsonConvert.SerializeObject(Packages, Formatting.Indented)); + foreach (var arg in args) + { + switch (arg) + { + case not null when arg.StartsWith("-release"): + + string version = arg.Split(":")[1]; + + Release release = new Release(version); + + release.Run(); + + break; + } + } } } } \ No newline at end of file diff --git a/Setup/Release.cs b/Setup/Release.cs new file mode 100644 index 000000000..065de2902 --- /dev/null +++ b/Setup/Release.cs @@ -0,0 +1,25 @@ +namespace Setup; + +public class Release +{ + private readonly Package[] _packages; + + private readonly string _version; + + public Release(string version) + { + _packages = Program.Packages.ToArray(); + + _version = version; + } + + public void Run() + { + foreach (Package package in _packages) + { + package.SetVersion(_version); + + package.Save(); + } + } +} \ No newline at end of file From d0c8b02f0dc16659dfa729cad210235574b4b804 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 13:26:58 +0300 Subject: [PATCH 07/62] Program renamed to Setup --- Setup/Release.cs | 2 +- Setup/{Program.cs => Setup.cs} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename Setup/{Program.cs => Setup.cs} (98%) diff --git a/Setup/Release.cs b/Setup/Release.cs index 065de2902..f6017ed68 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -8,7 +8,7 @@ public class Release public Release(string version) { - _packages = Program.Packages.ToArray(); + _packages = Setup.Packages.ToArray(); _version = version; } diff --git a/Setup/Program.cs b/Setup/Setup.cs similarity index 98% rename from Setup/Program.cs rename to Setup/Setup.cs index f82ab34c2..79122de95 100644 --- a/Setup/Program.cs +++ b/Setup/Setup.cs @@ -5,7 +5,7 @@ namespace Setup { - internal class Program + internal class Setup { public static readonly List Packages = new List(); From 02d78e45a38f7529bfd54d3e1d6f2e4ddcf51190 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 13:38:49 +0300 Subject: [PATCH 08/62] checkpoint before testing git --- Setup/Git.cs | 19 +++++++++++++++++++ Setup/Release.cs | 4 ++++ Setup/Utils.cs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 Setup/Git.cs create mode 100644 Setup/Utils.cs diff --git a/Setup/Git.cs b/Setup/Git.cs new file mode 100644 index 000000000..217c965b6 --- /dev/null +++ b/Setup/Git.cs @@ -0,0 +1,19 @@ +namespace Setup; + +public static class Git +{ + public static void Add(string path) + { + $"git add \"{path}\" -f".RunWithBash(); + } + + public static void Commit(string message) + { + $"git commit -m \"{message}\"".RunWithBash(); + } + + public static void Push() + { + "git push".RunWithBash(); + } +} \ No newline at end of file diff --git a/Setup/Release.cs b/Setup/Release.cs index f6017ed68..6011922d3 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -20,6 +20,10 @@ public void Run() package.SetVersion(_version); package.Save(); + + Git.Add(package.Path); } + + Git.Commit($"Release {_version}"); } } \ No newline at end of file diff --git a/Setup/Utils.cs b/Setup/Utils.cs new file mode 100644 index 000000000..90c6c2cdf --- /dev/null +++ b/Setup/Utils.cs @@ -0,0 +1,31 @@ +using System.Diagnostics; + +namespace Setup; + +public static class Utils +{ + public static string RunWithBash( this string cmd ) + { + cmd = cmd.Replace( "\"", "\\\"" ); + + Process process = new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = "/bin/bash", + Arguments = $"-c \"{cmd}\"", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + + process.Start(); + + string result = process.StandardOutput.ReadToEnd(); + + process.WaitForExit(); + + return result; + } +} \ No newline at end of file From 95ef992574c830588ee616abc5ca1474e4929eca Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 13:39:18 +0300 Subject: [PATCH 09/62] git push added --- Setup/Release.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Setup/Release.cs b/Setup/Release.cs index 6011922d3..9de0b6913 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -25,5 +25,7 @@ public void Run() } Git.Commit($"Release {_version}"); + + Git.Push(); } } \ No newline at end of file From ab7137d41a72040a9af55a537b3795ae28f4b35a Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 13:44:00 +0300 Subject: [PATCH 10/62] proper logging --- Setup/Utils.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Setup/Utils.cs b/Setup/Utils.cs index 90c6c2cdf..29dcb675b 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils.cs @@ -1,10 +1,11 @@ +using System; using System.Diagnostics; namespace Setup; public static class Utils { - public static string RunWithBash( this string cmd ) + public static void RunWithBash( this string cmd ) { cmd = cmd.Replace( "\"", "\\\"" ); @@ -25,7 +26,10 @@ public static string RunWithBash( this string cmd ) string result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); - - return result; + + foreach (string line in result.Split('\n')) + { + Console.WriteLine(line); + } } } \ No newline at end of file From 2cd14ce85c2ed39db08f723eeef9bdec80e35130 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 13:46:40 +0300 Subject: [PATCH 11/62] more log check --- Setup/Utils.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Setup/Utils.cs b/Setup/Utils.cs index 29dcb675b..ff5520527 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils.cs @@ -27,6 +27,8 @@ public static void RunWithBash( this string cmd ) process.WaitForExit(); + Console.WriteLine($"Output for {cmd}: {result}"); + foreach (string line in result.Split('\n')) { Console.WriteLine(line); From c5d7f1c2e2e45b2d096439fddbf1cd99a18b3f2f Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 13:52:09 +0300 Subject: [PATCH 12/62] more log test --- Setup/Release.cs | 4 ++++ Setup/Utils.cs | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Setup/Release.cs b/Setup/Release.cs index 9de0b6913..848a0e68d 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -1,3 +1,5 @@ +using System; + namespace Setup; public class Release @@ -22,6 +24,8 @@ public void Run() package.Save(); Git.Add(package.Path); + + Console.WriteLine(package.Path); } Git.Commit($"Release {_version}"); diff --git a/Setup/Utils.cs b/Setup/Utils.cs index ff5520527..29dcb675b 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils.cs @@ -27,8 +27,6 @@ public static void RunWithBash( this string cmd ) process.WaitForExit(); - Console.WriteLine($"Output for {cmd}: {result}"); - foreach (string line in result.Split('\n')) { Console.WriteLine(line); From 83d1d4964e265a44b11a2f1d113f703f2ea73575 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 14:20:34 +0300 Subject: [PATCH 13/62] powershell added --- Setup/Git.cs | 6 +++--- Setup/Release.cs | 4 ---- Setup/Setup.csproj | 1 + Setup/Utils.cs | 28 +++++----------------------- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index 217c965b6..d6e6a9830 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -4,16 +4,16 @@ public static class Git { public static void Add(string path) { - $"git add \"{path}\" -f".RunWithBash(); + $"git add \"{path}\" -f".RunWithPowerShell(); } public static void Commit(string message) { - $"git commit -m \"{message}\"".RunWithBash(); + $"git commit -m \"{message}\"".RunWithPowerShell(); } public static void Push() { - "git push".RunWithBash(); + "git push".RunWithPowerShell(); } } \ No newline at end of file diff --git a/Setup/Release.cs b/Setup/Release.cs index 848a0e68d..9de0b6913 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -1,5 +1,3 @@ -using System; - namespace Setup; public class Release @@ -24,8 +22,6 @@ public void Run() package.Save(); Git.Add(package.Path); - - Console.WriteLine(package.Path); } Git.Commit($"Release {_version}"); diff --git a/Setup/Setup.csproj b/Setup/Setup.csproj index b35ce995f..b3fdb30b0 100644 --- a/Setup/Setup.csproj +++ b/Setup/Setup.csproj @@ -7,6 +7,7 @@ + diff --git a/Setup/Utils.cs b/Setup/Utils.cs index 29dcb675b..5e349f2b1 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils.cs @@ -1,35 +1,17 @@ using System; +using System.Collections.ObjectModel; using System.Diagnostics; +using System.Management.Automation; namespace Setup; public static class Utils { - public static void RunWithBash( this string cmd ) + public static void RunWithPowerShell(this string command) { - cmd = cmd.Replace( "\"", "\\\"" ); - - Process process = new Process() - { - StartInfo = new ProcessStartInfo - { - FileName = "/bin/bash", - Arguments = $"-c \"{cmd}\"", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; - - process.Start(); - - string result = process.StandardOutput.ReadToEnd(); - - process.WaitForExit(); - - foreach (string line in result.Split('\n')) + using (PowerShell powershell = PowerShell.Create()) { - Console.WriteLine(line); + var output = powershell.AddScript(@command).Invoke(); } } } \ No newline at end of file From 6618c2c05d54b0ccf5e07bba973546b73c1013b5 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 14:29:56 +0300 Subject: [PATCH 14/62] added missing command line argument --- .github/workflows/setup.yaml | 2 +- Setup/Utils.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 81f0f85b7..ef016a610 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -21,4 +21,4 @@ jobs: - name: Run run: | cd Setup - dotnet run Setup/Setup.csproj + dotnet run -release:3.0.1 Setup/Setup.csproj diff --git a/Setup/Utils.cs b/Setup/Utils.cs index 5e349f2b1..87ba1d2d6 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils.cs @@ -11,7 +11,7 @@ public static void RunWithPowerShell(this string command) { using (PowerShell powershell = PowerShell.Create()) { - var output = powershell.AddScript(@command).Invoke(); + powershell.AddScript(@command).Invoke(); } } } \ No newline at end of file From 381c9b9db952a638f7cec4f179c2118a5d6fb950 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 14:31:39 +0300 Subject: [PATCH 15/62] reverted to run with bash --- Setup/Git.cs | 6 +++--- Setup/Utils.cs | 28 +++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index d6e6a9830..217c965b6 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -4,16 +4,16 @@ public static class Git { public static void Add(string path) { - $"git add \"{path}\" -f".RunWithPowerShell(); + $"git add \"{path}\" -f".RunWithBash(); } public static void Commit(string message) { - $"git commit -m \"{message}\"".RunWithPowerShell(); + $"git commit -m \"{message}\"".RunWithBash(); } public static void Push() { - "git push".RunWithPowerShell(); + "git push".RunWithBash(); } } \ No newline at end of file diff --git a/Setup/Utils.cs b/Setup/Utils.cs index 87ba1d2d6..29dcb675b 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils.cs @@ -1,17 +1,35 @@ using System; -using System.Collections.ObjectModel; using System.Diagnostics; -using System.Management.Automation; namespace Setup; public static class Utils { - public static void RunWithPowerShell(this string command) + public static void RunWithBash( this string cmd ) { - using (PowerShell powershell = PowerShell.Create()) + cmd = cmd.Replace( "\"", "\\\"" ); + + Process process = new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = "/bin/bash", + Arguments = $"-c \"{cmd}\"", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + + process.Start(); + + string result = process.StandardOutput.ReadToEnd(); + + process.WaitForExit(); + + foreach (string line in result.Split('\n')) { - powershell.AddScript(@command).Invoke(); + Console.WriteLine(line); } } } \ No newline at end of file From 205d1b3c85190880fd4c7747833fb8c936ba7ad9 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 14:32:51 +0300 Subject: [PATCH 16/62] removed powershell package --- Setup/Setup.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Setup/Setup.csproj b/Setup/Setup.csproj index b3fdb30b0..b35ce995f 100644 --- a/Setup/Setup.csproj +++ b/Setup/Setup.csproj @@ -7,7 +7,6 @@ - From b2dfcf44da74f27106f96c5369f1514c6956e1b0 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 14:35:09 +0300 Subject: [PATCH 17/62] exception support --- Setup/Utils.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Setup/Utils.cs b/Setup/Utils.cs index 29dcb675b..2e2fa85de 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils.cs @@ -5,16 +5,16 @@ namespace Setup; public static class Utils { - public static void RunWithBash( this string cmd ) + public static void RunWithBash( this string command) { - cmd = cmd.Replace( "\"", "\\\"" ); + command = command.Replace( "\"", "\\\"" ); Process process = new Process() { StartInfo = new ProcessStartInfo { FileName = "/bin/bash", - Arguments = $"-c \"{cmd}\"", + Arguments = $"-c \"{command}\"", RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, @@ -31,5 +31,10 @@ public static void RunWithBash( this string cmd ) { Console.WriteLine(line); } + + if (process.ExitCode != 0) + { + throw new Exception($"Error executing bash command {command}"); + } } } \ No newline at end of file From 79f9a82b9869b835dbf7dd9b19412ae7034dc682 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 15:38:27 +0300 Subject: [PATCH 18/62] configure and push added --- .github/workflows/setup.yaml | 3 +++ Setup/Git.cs | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index ef016a610..abf72b999 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -22,3 +22,6 @@ jobs: run: | cd Setup dotnet run -release:3.0.1 Setup/Setup.csproj + - name: Push + run: | + git push \ No newline at end of file diff --git a/Setup/Git.cs b/Setup/Git.cs index 217c965b6..e7454ab09 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -2,6 +2,8 @@ namespace Setup; public static class Git { + private static bool _configured; + public static void Add(string path) { $"git add \"{path}\" -f".RunWithBash(); @@ -9,6 +11,11 @@ public static void Add(string path) public static void Commit(string message) { + if (!_configured) + { + Configure(); + } + $"git commit -m \"{message}\"".RunWithBash(); } @@ -16,4 +23,12 @@ public static void Push() { "git push".RunWithBash(); } + + private static void Configure() + { + "git config user.email ${{ github.actor }}@users.noreply.github.com".RunWithBash(); + "git config user.name ${{ github.actor }}".RunWithBash(); + + _configured = true; + } } \ No newline at end of file From dee0c58400856ed7ffa320eedd337a7c456884ac Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 15:39:59 +0300 Subject: [PATCH 19/62] deploy key added for push --- .github/workflows/setup.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index abf72b999..0088685ed 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -12,7 +12,10 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 - + with: + lfs: true + ssh-key: ${{ secrets.DEPLOY_KEY }} + - name: Setup .NET uses: actions/setup-dotnet@v3 with: @@ -24,4 +27,4 @@ jobs: dotnet run -release:3.0.1 Setup/Setup.csproj - name: Push run: | - git push \ No newline at end of file + git push -f \ No newline at end of file From 41a7d9a1830ba67acb7df07175f439a7fcf6db46 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 15:41:54 +0300 Subject: [PATCH 20/62] bad substitution fix --- Setup/Git.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index e7454ab09..b9af5e255 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -26,8 +26,8 @@ public static void Push() private static void Configure() { - "git config user.email ${{ github.actor }}@users.noreply.github.com".RunWithBash(); - "git config user.name ${{ github.actor }}".RunWithBash(); + "git config user.email ${github.actor}@users.noreply.github.com".RunWithBash(); + "git config user.name ${github.actor}".RunWithBash(); _configured = true; } From a21c0163153fc1f1f3c031b7122214cbf6d07fe8 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 15:53:12 +0300 Subject: [PATCH 21/62] github env vars setup --- .github/workflows/setup.yaml | 4 ++++ Setup/Git.cs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 0088685ed..449880cce 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -5,6 +5,10 @@ on: branches: - rob/publish-and-release-tool-1120 +env: + git_email: "${{ github.actor }}@users.noreply.github.com" + git_actor: "${{ github.actor }}" + jobs: setup: name: Setup job diff --git a/Setup/Git.cs b/Setup/Git.cs index b9af5e255..870cc79fe 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -26,8 +26,8 @@ public static void Push() private static void Configure() { - "git config user.email ${github.actor}@users.noreply.github.com".RunWithBash(); - "git config user.name ${github.actor}".RunWithBash(); + "git config user.email $git_email".RunWithBash(); + "git config user.name $git_actor".RunWithBash(); _configured = true; } From 3418698cc0f27037588a870c637dab3ecae12528 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Tue, 15 Oct 2024 16:40:13 +0300 Subject: [PATCH 22/62] checkpoint --- Setup/Git.cs | 15 +++++++++++++-- Setup/Release.cs | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index 870cc79fe..c5b0c4f46 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -9,14 +9,25 @@ public static void Add(string path) $"git add \"{path}\" -f".RunWithBash(); } - public static void Commit(string message) + public static void Commit(string message, string[] tags = null) { if (!_configured) { Configure(); } - $"git commit -m \"{message}\"".RunWithBash(); + $"git commit -m \"{message} [skip ci]\"".RunWithBash(); + + if (tags != null) + { + foreach (var tag in tags) + { + if (!string.IsNullOrEmpty(tag)) + { + $"git tag {tag}".RunWithBash(); + } + } + } } public static void Push() diff --git a/Setup/Release.cs b/Setup/Release.cs index 9de0b6913..7904e9700 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -15,6 +15,8 @@ public Release(string version) public void Run() { + string[] tags = new string[_packages.Length]; + foreach (Package package in _packages) { package.SetVersion(_version); @@ -24,7 +26,7 @@ public void Run() Git.Add(package.Path); } - Git.Commit($"Release {_version}"); + Git.Commit($"Release {_version}", tags); Git.Push(); } From b9a0cf974e11f40d0d07be67800d3dc3d74aadb7 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Wed, 16 Oct 2024 10:29:57 +0300 Subject: [PATCH 23/62] tags and dependency version changes --- .github/workflows/setup.yaml | 5 +--- Setup/Git.cs | 19 ++++++++++++--- Setup/Package.cs | 23 +++++++++++++++---- Setup/Release.cs | 8 ++++--- .../Utils/JsonIgnoreSerializationAttribute.cs | 9 ++++++++ Setup/Utils/JsonPropertiesResolver.cs | 18 +++++++++++++++ Setup/{ => Utils}/Utils.cs | 2 +- 7 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 Setup/Utils/JsonIgnoreSerializationAttribute.cs create mode 100644 Setup/Utils/JsonPropertiesResolver.cs rename Setup/{ => Utils}/Utils.cs (97%) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 449880cce..f8cc741ec 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -28,7 +28,4 @@ jobs: - name: Run run: | cd Setup - dotnet run -release:3.0.1 Setup/Setup.csproj - - name: Push - run: | - git push -f \ No newline at end of file + dotnet run -release:3.0.2 Setup/Setup.csproj \ No newline at end of file diff --git a/Setup/Git.cs b/Setup/Git.cs index c5b0c4f46..2ced499d9 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -1,3 +1,5 @@ +using Setup.Utils; + namespace Setup; public static class Git @@ -24,15 +26,26 @@ public static void Commit(string message, string[] tags = null) { if (!string.IsNullOrEmpty(tag)) { - $"git tag {tag}".RunWithBash(); + $"git tag \"{tag}\"".RunWithBash(); } } } } - public static void Push() + public static void Push(string[] tags = null) { - "git push".RunWithBash(); + "git push -f".RunWithBash(); + + if (tags != null) + { + foreach (string tag in tags) + { + if (!string.IsNullOrEmpty(tag)) + { + $"git push origin \"{tag}\"".RunWithBash(); + } + } + } } private static void Configure() diff --git a/Setup/Package.cs b/Setup/Package.cs index d913b68d1..598a32f0b 100644 --- a/Setup/Package.cs +++ b/Setup/Package.cs @@ -4,6 +4,7 @@ using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Setup.Utils; namespace Setup { @@ -11,6 +12,9 @@ public class Package { [JsonIgnore] public string Path { get; private set; } + + [JsonProperty("name")] + public string Name { get; private set; } [JsonProperty("version")] public string Version { get; private set; } @@ -48,6 +52,15 @@ public void SetVersion(string version) } Version = version; + + string[] keys = Dependencies.Where(d => Setup.Packages.Any(p => p.Name == d.Key)) + .Select(d => d.Key) + .ToArray(); + + foreach (string key in keys) + { + Dependencies[key] = version; + } } public void Save() @@ -55,11 +68,11 @@ public void Save() string json = File.ReadAllText(Path); JObject jObject = JObject.Parse(json); - - jObject.Merge(JObject.Parse(JsonConvert.SerializeObject(this)), new JsonMergeSettings - { - MergeArrayHandling = MergeArrayHandling.Merge - }); + + jObject.Merge( + JObject.Parse(JsonConvert.SerializeObject(this, + new JsonSerializerSettings { ContractResolver = new JsonPropertiesResolver() })), + new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Merge }); File.WriteAllText(Path, jObject.ToString(Formatting.Indented)); } diff --git a/Setup/Release.cs b/Setup/Release.cs index 7904e9700..6af99bd4a 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -1,3 +1,5 @@ +using System; + namespace Setup; public class Release @@ -15,8 +17,6 @@ public Release(string version) public void Run() { - string[] tags = new string[_packages.Length]; - foreach (Package package in _packages) { package.SetVersion(_version); @@ -26,8 +26,10 @@ public void Run() Git.Add(package.Path); } + string[] tags = Array.ConvertAll(_packages, p => $"{p.Name}/{_version}"); + Git.Commit($"Release {_version}", tags); - Git.Push(); + Git.Push(tags); } } \ No newline at end of file diff --git a/Setup/Utils/JsonIgnoreSerializationAttribute.cs b/Setup/Utils/JsonIgnoreSerializationAttribute.cs new file mode 100644 index 000000000..808a9314d --- /dev/null +++ b/Setup/Utils/JsonIgnoreSerializationAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace Setup.Utils; + +[AttributeUsage(AttributeTargets.Property)] +public class JsonIgnoreSerializationAttribute : Attribute +{ + +} \ No newline at end of file diff --git a/Setup/Utils/JsonPropertiesResolver.cs b/Setup/Utils/JsonPropertiesResolver.cs new file mode 100644 index 000000000..9d156f770 --- /dev/null +++ b/Setup/Utils/JsonPropertiesResolver.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Newtonsoft.Json.Serialization; + +namespace Setup.Utils; + +public class JsonPropertiesResolver : DefaultContractResolver +{ + protected override List GetSerializableMembers(Type objectType) + { + //Return properties that do NOT have the JsonIgnoreSerializationAttribute + return objectType.GetProperties() + .Where(pi => !Attribute.IsDefined(pi, typeof(JsonIgnoreSerializationAttribute))) + .ToList(); + } +} \ No newline at end of file diff --git a/Setup/Utils.cs b/Setup/Utils/Utils.cs similarity index 97% rename from Setup/Utils.cs rename to Setup/Utils/Utils.cs index 2e2fa85de..695926ca1 100644 --- a/Setup/Utils.cs +++ b/Setup/Utils/Utils.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace Setup; +namespace Setup.Utils; public static class Utils { From f4d5b1776e77c28ff569028279fda49a45a4c3a0 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Wed, 16 Oct 2024 11:00:59 +0300 Subject: [PATCH 24/62] manual workflow and release added --- .github/workflows/release.yaml | 48 ++++++++++++++++++++++++++++++++++ .github/workflows/setup.yaml | 31 ---------------------- Setup/Git.cs | 14 +++++++++- Setup/Release.cs | 14 ++++++---- 4 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/release.yaml delete mode 100644 .github/workflows/setup.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..930176a67 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,48 @@ +name: Release Workflow + +on: + workflow_dispatch: + inputs: + version: + description: 'Version to Release' + required: true + release_notes: + description: 'Version Release Notes' + required: true + +env: + git_email: "${{ github.actor }}@users.noreply.github.com" + git_actor: "${{ github.actor }}" + +jobs: + setup: + name: Setup job + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + lfs: true + ssh-key: ${{ secrets.DEPLOY_KEY }} + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Run + run: | + cd Setup + dotnet run -release:3.0.2 Setup/Setup.csproj + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.event.inputs.version }} + release_name: Release ${{ github.event.inputs.version }} + body: | + ${{ github.event.inputs.release_notes }} + draft: false + prerelease: false \ No newline at end of file diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml deleted file mode 100644 index f8cc741ec..000000000 --- a/.github/workflows/setup.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: Setup Workflow - -on: - push: - branches: - - rob/publish-and-release-tool-1120 - -env: - git_email: "${{ github.actor }}@users.noreply.github.com" - git_actor: "${{ github.actor }}" - -jobs: - setup: - name: Setup job - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - lfs: true - ssh-key: ${{ secrets.DEPLOY_KEY }} - - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x - - - name: Run - run: | - cd Setup - dotnet run -release:3.0.2 Setup/Setup.csproj \ No newline at end of file diff --git a/Setup/Git.cs b/Setup/Git.cs index 2ced499d9..0675c1ebc 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -26,7 +26,7 @@ public static void Commit(string message, string[] tags = null) { if (!string.IsNullOrEmpty(tag)) { - $"git tag \"{tag}\"".RunWithBash(); + Tag(tag); } } } @@ -48,6 +48,18 @@ public static void Push(string[] tags = null) } } + public static void CommitAndPush(string message, string[] tags = null) + { + Commit(message, tags); + + Push(tags); + } + + public static void Tag(string tag) + { + $"git tag \"{tag}\"".RunWithBash(); + } + private static void Configure() { "git config user.email $git_email".RunWithBash(); diff --git a/Setup/Release.cs b/Setup/Release.cs index 6af99bd4a..a5785de2f 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; namespace Setup; @@ -17,6 +19,10 @@ public Release(string version) public void Run() { + List tags = new List(); + + tags.Add(_version); + foreach (Package package in _packages) { package.SetVersion(_version); @@ -24,12 +30,10 @@ public void Run() package.Save(); Git.Add(package.Path); + + tags.Add($"{package.Name}/{_version}"); } - string[] tags = Array.ConvertAll(_packages, p => $"{p.Name}/{_version}"); - - Git.Commit($"Release {_version}", tags); - - Git.Push(tags); + Git.CommitAndPush($"Release {_version}", tags.ToArray()); } } \ No newline at end of file From 2960ba82830c190485c5925eb84dd0d5a2e7b0b7 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Wed, 16 Oct 2024 12:21:31 +0300 Subject: [PATCH 25/62] release version from input --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 930176a67..de5f0acec 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -33,7 +33,7 @@ jobs: - name: Run run: | cd Setup - dotnet run -release:3.0.2 Setup/Setup.csproj + dotnet run -release:${{ github.event.inputs.version }} Setup/Setup.csproj - name: Create Release id: create_release uses: actions/create-release@v1 From 2fcf7ebffc4a3518f405f6238fa85bb3ec7e9983 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Wed, 16 Oct 2024 12:57:08 +0300 Subject: [PATCH 26/62] cool-er title for release workflow --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index de5f0acec..1e3691889 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,4 +1,4 @@ -name: Release Workflow +name: Release ⬆️ on: workflow_dispatch: From 5387d108019716447dc6c66bd7cd34f2225d50cc Mon Sep 17 00:00:00 2001 From: rob1997 Date: Wed, 16 Oct 2024 13:04:32 +0300 Subject: [PATCH 27/62] Ignore serialization only, on some Package properties --- Setup/Package.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Setup/Package.cs b/Setup/Package.cs index 598a32f0b..c5613e16f 100644 --- a/Setup/Package.cs +++ b/Setup/Package.cs @@ -13,7 +13,7 @@ public class Package [JsonIgnore] public string Path { get; private set; } - [JsonProperty("name")] + [JsonProperty("name"), JsonIgnoreSerialization] public string Name { get; private set; } [JsonProperty("version")] @@ -22,10 +22,10 @@ public class Package [JsonProperty("dependencies", NullValueHandling = NullValueHandling.Ignore)] public Dictionary Dependencies { get; private set; } - [JsonProperty("testables", NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("testables", NullValueHandling = NullValueHandling.Ignore), JsonIgnoreSerialization] public string[] Testables { get; private set; } - [JsonProperty("samples", NullValueHandling = NullValueHandling.Ignore)] + [JsonProperty("samples", NullValueHandling = NullValueHandling.Ignore), JsonIgnoreSerialization] public Sample[] Samples { get; private set; } // For Json Deserialize. From f8f3d3d644a56b46e80b0478a0b71ce35f99b81d Mon Sep 17 00:00:00 2001 From: rob1997 Date: Wed, 16 Oct 2024 13:05:34 +0300 Subject: [PATCH 28/62] removed unused using statement --- Setup/Setup.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Setup/Setup.cs b/Setup/Setup.cs index 79122de95..a35c8f9ac 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using Newtonsoft.Json; From 9f8cf2de462f15e6b1628ff15242484c234ddea3 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Wed, 16 Oct 2024 14:03:37 +0300 Subject: [PATCH 29/62] documentation added --- Setup/Git.cs | 3 +++ Setup/Package.cs | 15 +++++++++++++++ Setup/Release.cs | 10 ++++++++-- Setup/Setup.cs | 3 +++ Setup/Utils/JsonIgnoreSerializationAttribute.cs | 4 ++++ Setup/Utils/JsonPropertiesResolver.cs | 3 +++ Setup/Utils/Utils.cs | 5 +++++ 7 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index 0675c1ebc..b3b862d2c 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -2,6 +2,9 @@ namespace Setup; +/// +/// Git helper class. +/// public static class Git { private static bool _configured; diff --git a/Setup/Package.cs b/Setup/Package.cs index c5613e16f..c1152242a 100644 --- a/Setup/Package.cs +++ b/Setup/Package.cs @@ -8,8 +8,15 @@ namespace Setup { + /// + /// Unity package.json model for UPM. + /// https://docs.unity3d.com/Manual/upm-manifestPkg.html. + /// public class Package { + /// + /// Path of package from root of repository. + /// [JsonIgnore] public string Path { get; private set; } @@ -39,6 +46,11 @@ public Package(string path) Path = path; } + /// + /// Sets Package Version. + /// + /// Version string. + /// Exception thrown if version format doesn't match guidelines https://semver.org/. public void SetVersion(string version) { string[] increments = version.Split('.'); @@ -63,6 +75,9 @@ public void SetVersion(string version) } } + /// + /// Save altered package to . + /// public void Save() { string json = File.ReadAllText(Path); diff --git a/Setup/Release.cs b/Setup/Release.cs index a5785de2f..dbaf0e55b 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -1,9 +1,10 @@ -using System; using System.Collections.Generic; -using System.Linq; namespace Setup; +/// +/// Release. +/// public class Release { private readonly Package[] _packages; @@ -17,6 +18,11 @@ public Release(string version) _version = version; } + /// + /// Bumps the version and makes a release. + /// Commit and push with package.json versions bumped. + /// Tag the commits so another CI (open-upm) can pick them up. + /// public void Run() { List tags = new List(); diff --git a/Setup/Setup.cs b/Setup/Setup.cs index a35c8f9ac..a8226e9d9 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -11,6 +11,7 @@ internal class Setup // dotnet run -release:3.0.0 -duplicate_samples -publish_dependencies; static void Main(string[] args) { + // Initialize packages from file. string json = File.ReadAllText("packages.json"); string[] paths = JsonConvert.DeserializeObject(json); @@ -26,6 +27,8 @@ static void Main(string[] args) Packages.Add(package); } + // Parse arguments and Run operations based on that. + // TODO: use runnable and runner to run multiple operations sort orders. foreach (var arg in args) { switch (arg) diff --git a/Setup/Utils/JsonIgnoreSerializationAttribute.cs b/Setup/Utils/JsonIgnoreSerializationAttribute.cs index 808a9314d..e91191b8a 100644 --- a/Setup/Utils/JsonIgnoreSerializationAttribute.cs +++ b/Setup/Utils/JsonIgnoreSerializationAttribute.cs @@ -2,6 +2,10 @@ namespace Setup.Utils; +/// +/// Fir ignoring serialization of a property. +/// Deserialization still works. +/// [AttributeUsage(AttributeTargets.Property)] public class JsonIgnoreSerializationAttribute : Attribute { diff --git a/Setup/Utils/JsonPropertiesResolver.cs b/Setup/Utils/JsonPropertiesResolver.cs index 9d156f770..930ad9937 100644 --- a/Setup/Utils/JsonPropertiesResolver.cs +++ b/Setup/Utils/JsonPropertiesResolver.cs @@ -6,6 +6,9 @@ namespace Setup.Utils; +/// +/// Resolver for custom serialization. +/// public class JsonPropertiesResolver : DefaultContractResolver { protected override List GetSerializableMembers(Type objectType) diff --git a/Setup/Utils/Utils.cs b/Setup/Utils/Utils.cs index 695926ca1..7895d41d0 100644 --- a/Setup/Utils/Utils.cs +++ b/Setup/Utils/Utils.cs @@ -5,6 +5,11 @@ namespace Setup.Utils; public static class Utils { + /// + /// Runs commands with bash. + /// + /// Command to run. + /// If command fails. public static void RunWithBash( this string command) { command = command.Replace( "\"", "\\\"" ); From b882d53473ee441f9a8afe6ca5809257c57ba8bc Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 13:13:29 +0300 Subject: [PATCH 30/62] first draft for duplicate sample and fixed release --- .github/workflows/duplicate_samples.yaml | 12 ++++ .github/workflows/release.yaml | 23 ++----- .github/workflows/setup.yaml | 33 +++++++++ Setup/DuplicateSamples.cs | 43 ++++++++++++ Setup/Git.cs | 5 +- Setup/Package.cs | 23 ++++++- Setup/Release.cs | 26 ++++++- Setup/Setup.cs | 45 ++++++++++-- Setup/SyncDependencies.cs | 13 ++++ Setup/UnityTests.cs | 13 ++++ Setup/Utils/IRunnable.cs | 8 +++ Setup/Utils/Utilities.cs | 87 ++++++++++++++++++++++++ Setup/Utils/Utils.cs | 45 ------------ Setup/packages.json | 14 ++-- 14 files changed, 309 insertions(+), 81 deletions(-) create mode 100644 .github/workflows/duplicate_samples.yaml create mode 100644 .github/workflows/setup.yaml create mode 100644 Setup/DuplicateSamples.cs create mode 100644 Setup/SyncDependencies.cs create mode 100644 Setup/UnityTests.cs create mode 100644 Setup/Utils/IRunnable.cs create mode 100644 Setup/Utils/Utilities.cs delete mode 100644 Setup/Utils/Utils.cs diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml new file mode 100644 index 000000000..73f992fbf --- /dev/null +++ b/.github/workflows/duplicate_samples.yaml @@ -0,0 +1,12 @@ +name: Duplicate Samples 🪞 + +on: + workflow_dispatch: + +jobs: + setup: + name: Setup job + uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main + with: + arguments: " -duplicate_samples" + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1e3691889..0d973a22a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,30 +10,21 @@ on: description: 'Version Release Notes' required: true -env: - git_email: "${{ github.actor }}@users.noreply.github.com" - git_actor: "${{ github.actor }}" - jobs: setup: name: Setup job + uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main + with: + arguments: " -release:${{ github.event.inputs.version }}" + secrets: inherit + release: + name: Release job runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: - lfs: true - ssh-key: ${{ secrets.DEPLOY_KEY }} - - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x - - - name: Run - run: | - cd Setup - dotnet run -release:${{ github.event.inputs.version }} Setup/Setup.csproj + lfs: true - name: Create Release id: create_release uses: actions/create-release@v1 diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml new file mode 100644 index 000000000..8c64fe752 --- /dev/null +++ b/.github/workflows/setup.yaml @@ -0,0 +1,33 @@ +name: Setup Workflow + +on: + workflow_call: + inputs: + arguments: + required: true + type: string + +env: + git_email: "${{ github.actor }}@users.noreply.github.com" + git_actor: "${{ github.actor }}" + +jobs: + setup: + name: Setup job + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + lfs: true + ssh-key: ${{ secrets.DEPLOY_KEY }} + + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 8.0.x + + - name: Run + run: | + cd Setup + dotnet run${{ inputs.arguments }} Setup/Setup.csproj \ No newline at end of file diff --git a/Setup/DuplicateSamples.cs b/Setup/DuplicateSamples.cs new file mode 100644 index 000000000..295376dad --- /dev/null +++ b/Setup/DuplicateSamples.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using Setup.Utils; + +namespace Setup; + +public class DuplicateSamples : IRunnable +{ + private readonly Package[] _packages; + + public int Order => 0; + + public DuplicateSamples() + { + _packages = Setup.Packages.ToArray(); + } + + public void Run() + { + foreach (Package package in _packages) + { + if (package.HasSamples()) + { + string path = Path.Combine(Setup.SampleProjectPath, "Assets/Samples", package.DisplayName); + + foreach (var sample in package.Samples) + { + string source = Path.Combine(path, package.Version, sample.DisplayName); + + string destination = Path.Combine(package.Path, sample.Path); + + Utilities.CopyDirectory(source, destination); + + Console.WriteLine($"Duplicated Sample {package.Name} - {sample.DisplayName} from {source} to {destination}"); + + Git.Add(destination); + } + } + } + + Git.CommitAndPush("Duplicated Samples"); + } +} \ No newline at end of file diff --git a/Setup/Git.cs b/Setup/Git.cs index b3b862d2c..9ddf7c27e 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -20,8 +20,9 @@ public static void Commit(string message, string[] tags = null) { Configure(); } - - $"git commit -m \"{message} [skip ci]\"".RunWithBash(); + + // Checks if there are any changes to commit before committing + $"git diff-index --cached --quiet HEAD || git commit -m \"{message} [skip ci]\"".RunWithBash(); if (tags != null) { diff --git a/Setup/Package.cs b/Setup/Package.cs index c1152242a..1d0fc1622 100644 --- a/Setup/Package.cs +++ b/Setup/Package.cs @@ -23,6 +23,9 @@ public class Package [JsonProperty("name"), JsonIgnoreSerialization] public string Name { get; private set; } + [JsonProperty("displayName"), JsonIgnoreSerialization] + public string DisplayName { get; private set; } + [JsonProperty("version")] public string Version { get; private set; } @@ -35,6 +38,12 @@ public class Package [JsonProperty("samples", NullValueHandling = NullValueHandling.Ignore), JsonIgnoreSerialization] public Sample[] Samples { get; private set; } + /// + /// Path of package.json file. + /// + [JsonIgnore] + public string FilePath { get; private set; } + // For Json Deserialize. public Package() { @@ -44,6 +53,8 @@ public Package() public Package(string path) { Path = path; + + FilePath = System.IO.Path.Combine(path, "package.json"); } /// @@ -80,7 +91,7 @@ public void SetVersion(string version) /// public void Save() { - string json = File.ReadAllText(Path); + string json = File.ReadAllText(FilePath); JObject jObject = JObject.Parse(json); @@ -89,12 +100,20 @@ public void Save() new JsonSerializerSettings { ContractResolver = new JsonPropertiesResolver() })), new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Merge }); - File.WriteAllText(Path, jObject.ToString(Formatting.Indented)); + File.WriteAllText(FilePath, jObject.ToString(Formatting.Indented)); + } + + public bool HasSamples() + { + return Samples != null && Samples.Length > 0; } } public struct Sample { + [JsonProperty("displayName")] + public string DisplayName { get; private set; } + [JsonProperty("path")] public string Path { get; private set; } } diff --git a/Setup/Release.cs b/Setup/Release.cs index dbaf0e55b..f05fed81c 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -1,23 +1,27 @@ using System.Collections.Generic; +using System.IO; +using Setup.Utils; namespace Setup; /// /// Release. /// -public class Release +public class Release : IRunnable { private readonly Package[] _packages; private readonly string _version; + public int Order => 2; + public Release(string version) { _packages = Setup.Packages.ToArray(); _version = version; } - + /// /// Bumps the version and makes a release. /// Commit and push with package.json versions bumped. @@ -31,6 +35,8 @@ public void Run() foreach (Package package in _packages) { + string previousVersion = package.Version; + package.SetVersion(_version); package.Save(); @@ -38,6 +44,22 @@ public void Run() Git.Add(package.Path); tags.Add($"{package.Name}/{_version}"); + + // Move samples to new directory + if (package.HasSamples()) + { + string path = Path.Combine(Setup.SampleProjectPath, "Assets/Samples", package.DisplayName); + + string source = Path.Combine(path, previousVersion); + + string destination = Path.Combine(path, _version); + + Directory.Move(source, destination); + + File.Move($"{source}.meta", $"{destination}.meta"); + + Git.Add(path); + } } Git.CommitAndPush($"Release {_version}", tags.ToArray()); diff --git a/Setup/Setup.cs b/Setup/Setup.cs index a8226e9d9..c89561e6d 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -1,15 +1,33 @@ using System.Collections.Generic; using System.IO; +using System.Linq; using Newtonsoft.Json; +using Setup.Utils; namespace Setup { internal class Setup { + public const string SampleProjectPath = "../src/UnitySampleProject"; + public static readonly List Packages = new List(); // dotnet run -release:3.0.0 -duplicate_samples -publish_dependencies; static void Main(string[] args) + { + InitializePackages(); + + List runnableList = GetRunnableList(args); + + runnableList = runnableList.OrderBy(r => r.Order).ToList(); + + foreach (IRunnable runnable in runnableList) + { + runnable.Run(); + } + } + + private static void InitializePackages() { // Initialize packages from file. string json = File.ReadAllText("packages.json"); @@ -22,13 +40,17 @@ static void Main(string[] args) Package package = new Package(path); - JsonConvert.PopulateObject(File.ReadAllText(path), package); + JsonConvert.PopulateObject(File.ReadAllText(package.FilePath), package); Packages.Add(package); } + } + + private static List GetRunnableList(string[] args) + { + List runnableLit = new List(); // Parse arguments and Run operations based on that. - // TODO: use runnable and runner to run multiple operations sort orders. foreach (var arg in args) { switch (arg) @@ -36,14 +58,23 @@ static void Main(string[] args) case not null when arg.StartsWith("-release"): string version = arg.Split(":")[1]; - - Release release = new Release(version); - - release.Run(); - + runnableLit.AddRunnable(new Release(version)); + break; + + case "-duplicate_samples": + runnableLit.AddRunnable(new DuplicateSamples()); + break; + + case "-sync_dependencies": + runnableLit.AddRunnable(new SyncDependencies()); + break; + case "-unity_test": + runnableLit.AddRunnable(new UnityTests()); break; } } + + return runnableLit; } } } \ No newline at end of file diff --git a/Setup/SyncDependencies.cs b/Setup/SyncDependencies.cs new file mode 100644 index 000000000..8294e268f --- /dev/null +++ b/Setup/SyncDependencies.cs @@ -0,0 +1,13 @@ +using Setup.Utils; + +namespace Setup; + +public class SyncDependencies : IRunnable +{ + public int Order => 1; + + public void Run() + { + throw new System.NotImplementedException(); + } +} \ No newline at end of file diff --git a/Setup/UnityTests.cs b/Setup/UnityTests.cs new file mode 100644 index 000000000..c7a2ab9b9 --- /dev/null +++ b/Setup/UnityTests.cs @@ -0,0 +1,13 @@ +using Setup.Utils; + +namespace Setup; + +public class UnityTests : IRunnable +{ + public int Order => 2; + + public void Run() + { + throw new System.NotImplementedException(); + } +} \ No newline at end of file diff --git a/Setup/Utils/IRunnable.cs b/Setup/Utils/IRunnable.cs new file mode 100644 index 000000000..848b51916 --- /dev/null +++ b/Setup/Utils/IRunnable.cs @@ -0,0 +1,8 @@ +namespace Setup.Utils; + +public interface IRunnable +{ + public int Order { get; } + + public void Run(); +} \ No newline at end of file diff --git a/Setup/Utils/Utilities.cs b/Setup/Utils/Utilities.cs new file mode 100644 index 000000000..fb35d2d68 --- /dev/null +++ b/Setup/Utils/Utilities.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; + +namespace Setup.Utils; + +public static class Utilities +{ + /// + /// Runs commands with bash. + /// + /// Command to run. + /// If command fails. + public static void RunWithBash( this string command) + { + command = command.Replace( "\"", "\\\"" ); + + Process process = new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = "/bin/bash", + Arguments = $"-c \"{command}\"", + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + + process.Start(); + + string result = process.StandardOutput.ReadToEnd(); + + process.WaitForExit(); + + foreach (string line in result.Split('\n')) + { + Console.WriteLine(line); + } + + if (process.ExitCode != 0) + { + throw new Exception($"Error executing bash command {command}"); + } + } + + public static void AddRunnable(this List runnableList, IRunnable runnable) + { + if (runnableList.Contains(runnable)) + { + throw new Exception($"Duplicate command {runnable.GetType().Name}"); + } + + runnableList.Add(runnable); + } + + public static void CopyDirectory(string source, string destination, bool copyAsNew = true, bool overwriteFile = true) + { + DirectoryInfo sourceDirectory = new DirectoryInfo(source); + + DirectoryInfo destinationDirectory = new DirectoryInfo(destination); + + if (copyAsNew) + { + if (destinationDirectory.Exists) + { + destinationDirectory.Delete(true); + } + + Directory.CreateDirectory(destination); + } + + DirectoryInfo[] subDirectories = sourceDirectory.GetDirectories(); + + foreach (FileInfo file in sourceDirectory.GetFiles()) + { + file.CopyTo(Path.Combine(destination, file.Name), overwriteFile); + } + + // Copy Recursively + foreach (DirectoryInfo directory in subDirectories) + { + CopyDirectory(directory.FullName, Path.Combine(destination, directory.Name)); + } + } +} \ No newline at end of file diff --git a/Setup/Utils/Utils.cs b/Setup/Utils/Utils.cs deleted file mode 100644 index 7895d41d0..000000000 --- a/Setup/Utils/Utils.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Diagnostics; - -namespace Setup.Utils; - -public static class Utils -{ - /// - /// Runs commands with bash. - /// - /// Command to run. - /// If command fails. - public static void RunWithBash( this string command) - { - command = command.Replace( "\"", "\\\"" ); - - Process process = new Process() - { - StartInfo = new ProcessStartInfo - { - FileName = "/bin/bash", - Arguments = $"-c \"{command}\"", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; - - process.Start(); - - string result = process.StandardOutput.ReadToEnd(); - - process.WaitForExit(); - - foreach (string line in result.Split('\n')) - { - Console.WriteLine(line); - } - - if (process.ExitCode != 0) - { - throw new Exception($"Error executing bash command {command}"); - } - } -} \ No newline at end of file diff --git a/Setup/packages.json b/Setup/packages.json index 4aa46954f..b67f39928 100644 --- a/Setup/packages.json +++ b/Setup/packages.json @@ -1,9 +1,9 @@ [ - "Packages/io.chainsafe.web3-unity/package.json", - "Packages/io.chainsafe.web3-unity.hyperplay/package.json", - "Packages/io.chainsafe.web3-unity.lootboxes/package.json", - "Packages/io.chainsafe.web3-unity.marketplace/package.json", - "Packages/io.chainsafe.web3-unity.mud/package.json", - "Packages/io.chainsafe.web3-unity.ramp/package.json", - "Packages/io.chainsafe.web3-unity.web3auth/package.json" + "Packages/io.chainsafe.web3-unity", + "Packages/io.chainsafe.web3-unity.hyperplay", + "Packages/io.chainsafe.web3-unity.lootboxes", + "Packages/io.chainsafe.web3-unity.marketplace", + "Packages/io.chainsafe.web3-unity.mud", + "Packages/io.chainsafe.web3-unity.ramp", + "Packages/io.chainsafe.web3-unity.web3auth" ] \ No newline at end of file From 8065cf73f69ab2a8b4a768d00dd1ffefc2bcb32e Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 14:37:54 +0300 Subject: [PATCH 31/62] fixed parallel run of jobs --- .github/workflows/release.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0d973a22a..feb4f0f3c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,6 +20,7 @@ jobs: release: name: Release job runs-on: ubuntu-latest + needs: [ setup ] steps: - name: Checkout repository uses: actions/checkout@v4 From b97d17ca30832160a193097ef236b1eb81e51c12 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 15:35:50 +0300 Subject: [PATCH 32/62] extra arguments for release Git push added as a runnable so push happens at the end release order changed --- .github/workflows/release.yaml | 5 ++++- Setup/DuplicateSamples.cs | 5 ++++- Setup/Git.cs | 16 +++++++++++++++- Setup/Release.cs | 2 +- Setup/Setup.cs | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index feb4f0f3c..dcae4f0ab 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,13 +9,16 @@ on: release_notes: description: 'Version Release Notes' required: true + additional_arguments: + description: 'Additional arguments such as -duplicate_samples or -sync_dependencies' + required: false jobs: setup: name: Setup job uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main with: - arguments: " -release:${{ github.event.inputs.version }}" + arguments: "${{ github.event.inputs.additional_arguments }} -release:${{ github.event.inputs.version }}" secrets: inherit release: name: Release job diff --git a/Setup/DuplicateSamples.cs b/Setup/DuplicateSamples.cs index 295376dad..d7b49f61e 100644 --- a/Setup/DuplicateSamples.cs +++ b/Setup/DuplicateSamples.cs @@ -4,6 +4,9 @@ namespace Setup; +/// +/// Duplicates samples in Sample Project into package samples. +/// public class DuplicateSamples : IRunnable { private readonly Package[] _packages; @@ -38,6 +41,6 @@ public void Run() } } - Git.CommitAndPush("Duplicated Samples"); + Git.Commit("Duplicated Samples"); } } \ No newline at end of file diff --git a/Setup/Git.cs b/Setup/Git.cs index 9ddf7c27e..56ed25770 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -1,3 +1,6 @@ +using System; +using System.Collections.Generic; +using System.Linq; using Setup.Utils; namespace Setup; @@ -5,8 +8,17 @@ namespace Setup; /// /// Git helper class. /// -public static class Git +public class Git : IRunnable { + public int Order => int.MaxValue; + + public void Run() + { + Push(); + } + + #region Git Commands + private static bool _configured; public static void Add(string path) @@ -71,4 +83,6 @@ private static void Configure() _configured = true; } + + #endregion } \ No newline at end of file diff --git a/Setup/Release.cs b/Setup/Release.cs index f05fed81c..eedbd830f 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -13,7 +13,7 @@ public class Release : IRunnable private readonly string _version; - public int Order => 2; + public int Order => 3; public Release(string version) { diff --git a/Setup/Setup.cs b/Setup/Setup.cs index c89561e6d..96d9dbf8d 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -19,7 +19,7 @@ static void Main(string[] args) List runnableList = GetRunnableList(args); - runnableList = runnableList.OrderBy(r => r.Order).ToList(); + runnableList = runnableList.OrderBy(r => r.Order).Append(new Git()).ToList(); foreach (IRunnable runnable in runnableList) { From b7835985ee4e77a7020967f694a221f3f052f525 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 16:21:27 +0300 Subject: [PATCH 33/62] new trigger for testing --- .github/workflows/duplicate_samples.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 73f992fbf..8b9e99803 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -1,11 +1,14 @@ name: Duplicate Samples 🪞 on: - workflow_dispatch: + pull_request: + types: + - labeled jobs: setup: - name: Setup job + name: Duplicate job + if: ${{ github.event.label.name == 'ready-to-merge' }} uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main with: arguments: " -duplicate_samples" From a951ee5c7e7ecd0306078e6b65df3069d626c933 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 16:22:56 +0300 Subject: [PATCH 34/62] fixed compile error --- Setup/Utils/Utils.cs | 45 -------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 Setup/Utils/Utils.cs diff --git a/Setup/Utils/Utils.cs b/Setup/Utils/Utils.cs deleted file mode 100644 index 7895d41d0..000000000 --- a/Setup/Utils/Utils.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Diagnostics; - -namespace Setup.Utils; - -public static class Utils -{ - /// - /// Runs commands with bash. - /// - /// Command to run. - /// If command fails. - public static void RunWithBash( this string command) - { - command = command.Replace( "\"", "\\\"" ); - - Process process = new Process() - { - StartInfo = new ProcessStartInfo - { - FileName = "/bin/bash", - Arguments = $"-c \"{command}\"", - RedirectStandardOutput = true, - UseShellExecute = false, - CreateNoWindow = true, - } - }; - - process.Start(); - - string result = process.StandardOutput.ReadToEnd(); - - process.WaitForExit(); - - foreach (string line in result.Split('\n')) - { - Console.WriteLine(line); - } - - if (process.ExitCode != 0) - { - throw new Exception($"Error executing bash command {command}"); - } - } -} \ No newline at end of file From e596f0ec955a5d983e9ea64a1b6cc8d073d21a4e Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 16:30:43 +0300 Subject: [PATCH 35/62] documentation --- Setup/Git.cs | 1 + Setup/Release.cs | 2 +- Setup/Setup.cs | 10 +++++++++- Setup/Utils/IRunnable.cs | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index 56ed25770..6263a0a88 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -14,6 +14,7 @@ public class Git : IRunnable public void Run() { + // Push just to make sure we have the latest changes. Push(); } diff --git a/Setup/Release.cs b/Setup/Release.cs index eedbd830f..f98c58f3f 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -45,7 +45,7 @@ public void Run() tags.Add($"{package.Name}/{_version}"); - // Move samples to new directory + // Move samples to new directory with new version if (package.HasSamples()) { string path = Path.Combine(Setup.SampleProjectPath, "Assets/Samples", package.DisplayName); diff --git a/Setup/Setup.cs b/Setup/Setup.cs index 96d9dbf8d..94a66b610 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -19,6 +19,7 @@ static void Main(string[] args) List runnableList = GetRunnableList(args); + // Add Git to the end of the list to push at the end if there are any new commits. runnableList = runnableList.OrderBy(r => r.Order).Append(new Git()).ToList(); foreach (IRunnable runnable in runnableList) @@ -27,9 +28,11 @@ static void Main(string[] args) } } + /// + /// Initialize packages from packages.json in root of this project. + /// private static void InitializePackages() { - // Initialize packages from file. string json = File.ReadAllText("packages.json"); string[] paths = JsonConvert.DeserializeObject(json); @@ -46,6 +49,11 @@ private static void InitializePackages() } } + /// + /// Get runnable list based on passed arguments. + /// + /// Arguments passed. + /// Runnable List. private static List GetRunnableList(string[] args) { List runnableLit = new List(); diff --git a/Setup/Utils/IRunnable.cs b/Setup/Utils/IRunnable.cs index 848b51916..34aebe23e 100644 --- a/Setup/Utils/IRunnable.cs +++ b/Setup/Utils/IRunnable.cs @@ -1,7 +1,13 @@ namespace Setup.Utils; +/// +/// Runnable objects added to run queue. +/// public interface IRunnable { + /// + /// Run order. + /// public int Order { get; } public void Run(); From e23e4aef77edce0420d653dbba707cca41043a1a Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 17:07:38 +0300 Subject: [PATCH 36/62] added ref branch to commit on pull requst --- .github/workflows/setup.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 8c64fe752..5b313804d 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -19,6 +19,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: + ref: ${{ github.head_ref || github.ref_name }} lfs: true ssh-key: ${{ secrets.DEPLOY_KEY }} From 7186b2ec380c2ae9ad498a69a4526717edaab74d Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 17:21:13 +0300 Subject: [PATCH 37/62] removed additional arguments for release --- .github/workflows/duplicate_samples.yaml | 9 +++------ .github/workflows/release.yaml | 5 +---- .github/workflows/setup.yaml | 2 +- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 8b9e99803..7eecf5dde 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -1,15 +1,12 @@ name: Duplicate Samples 🪞 on: - pull_request: - types: - - labeled - + workflow_call: + jobs: setup: name: Duplicate job - if: ${{ github.event.label.name == 'ready-to-merge' }} uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main with: - arguments: " -duplicate_samples" + arguments: "-duplicate_samples" secrets: inherit \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index dcae4f0ab..a73bb718c 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -9,16 +9,13 @@ on: release_notes: description: 'Version Release Notes' required: true - additional_arguments: - description: 'Additional arguments such as -duplicate_samples or -sync_dependencies' - required: false jobs: setup: name: Setup job uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main with: - arguments: "${{ github.event.inputs.additional_arguments }} -release:${{ github.event.inputs.version }}" + arguments: "-release:${{ github.event.inputs.version }}" secrets: inherit release: name: Release job diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 5b313804d..55518855d 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -31,4 +31,4 @@ jobs: - name: Run run: | cd Setup - dotnet run${{ inputs.arguments }} Setup/Setup.csproj \ No newline at end of file + dotnet run ${{ inputs.arguments }} Setup/Setup.csproj \ No newline at end of file From aae787179e5a860e1c7d22149b9d68cd87dea7ba Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 18:12:47 +0300 Subject: [PATCH 38/62] setup works on both workflow call or form workflow dispatch --- .github/workflows/setup.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 55518855d..b17125a90 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -1,4 +1,4 @@ -name: Setup Workflow +name: Setup ⚙️ on: workflow_call: @@ -6,7 +6,12 @@ on: arguments: required: true type: string - + workflow_dispatch: + inputs: + arguments: + required: true + description: 'Arguments to pass to the setup script' + type: string env: git_email: "${{ github.actor }}@users.noreply.github.com" git_actor: "${{ github.actor }}" @@ -31,4 +36,4 @@ jobs: - name: Run run: | cd Setup - dotnet run ${{ inputs.arguments }} Setup/Setup.csproj \ No newline at end of file + dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} Setup/Setup.csproj \ No newline at end of file From 1f9632e620772a5958af29b2e3db979b64922829 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 23:29:30 +0300 Subject: [PATCH 39/62] cache test --- .github/workflows/duplicate_samples.yaml | 25 +++- .github/workflows/setup.yaml | 8 +- .../3.0.1/Marketplace Samples/MudSample.cs | 117 ------------------ .../Marketplace Samples/MudSample.cs.meta | 11 -- .../Scripts/MarketplaceSample.cs | 1 + 5 files changed, 31 insertions(+), 131 deletions(-) delete mode 100644 src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs delete mode 100644 src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 7eecf5dde..d5d9477f7 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -1,7 +1,9 @@ name: Duplicate Samples 🪞 on: - workflow_call: + push: + branches: + - rob/publish-tool-1120 jobs: setup: @@ -9,4 +11,23 @@ jobs: uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main with: arguments: "-duplicate_samples" - secrets: inherit \ No newline at end of file + secrets: inherit + check: + name: Check job + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref || github.ref_name }} + lfs: true + ssh-key: ${{ secrets.DEPLOY_KEY }} + - name: Cache + uses: actions/cache/restore@v4 + with: + path: .git + key: ${{ runner.os }}-git + - name: Run + run: | + git reset --hard + \ No newline at end of file diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index b17125a90..004970f4e 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -36,4 +36,10 @@ jobs: - name: Run run: | cd Setup - dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} Setup/Setup.csproj \ No newline at end of file + dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} Setup/Setup.csproj + git reset --hard + - name: Cache + uses: actions/cache/save@v4 + with: + path: .git + key: ${{ runner.os }}-git \ No newline at end of file diff --git a/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs b/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs deleted file mode 100644 index aadb7b4b7..000000000 --- a/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs +++ /dev/null @@ -1,117 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using ChainSafe.Gaming.Debugging; -using ChainSafe.Gaming.EVM.Events; -using ChainSafe.Gaming.Evm.JsonRpc; -using ChainSafe.Gaming.Mud; -using ChainSafe.Gaming.Mud.Tables; -using ChainSafe.Gaming.Mud.Unity; -using ChainSafe.Gaming.Mud.Worlds; -using ChainSafe.Gaming.RPC.Events; -using ChainSafe.Gaming.UnityPackage; -using ChainSafe.Gaming.Wallets; -using ChainSafe.Gaming.Web3; -using ChainSafe.Gaming.Web3.Build; -using ChainSafe.Gaming.Web3.Unity; -using TMPro; -using UnityEngine; - -public class MudSample : MonoBehaviour -{ - public MudConfigAsset mudConfig; - public string worldContractAddress; - public TextAsset worldContractAbi; - public TMP_Text counterLabel; - - private Web3 web3; - private MudWorld world; - - private async void Awake() - { - Debug.Log("To run this sample successfully you should have the MUD tutorial project running in the background.\n" + - "Follow the link to get started: https://mud.dev/quickstart"); - - // 1. Initialize Web3 client. - web3 = await new Web3Builder(ProjectConfigUtilities.Load(), ProjectConfigUtilities.BuildLocalhostConfig()) - .Configure(services => - { - // Enable basic components - services.UseUnityEnvironment(); - services.UseRpcProvider(); - - // Initializes Wallet as the first account of the locally running Ethereum Node (Anvil). - services.Debug().UseJsonRpcWallet(new JsonRpcWalletConfig { AccountIndex = 0 }); - - // Enable Events as MUD requires them - services.UseEvents(new PollingEventManagerConfig { PollInterval = TimeSpan.FromSeconds(1) }); // the config is only being used for WebGL platform; 1 second poll interval is extremely fast, consider using longer interval in production so that your RPC endpoint doesn't get too overwhelmed - - // Enable MUD - services.UseMud(mudConfig); - }) - .LaunchAsync(); - Debug.Log($"Web3 client ready. Player address: {web3.Signer.PublicAddress}"); - - // 2. Create MUD World client. - world = await web3.Mud().BuildWorld(new MudWorldConfig - { - ContractAddress = worldContractAddress, - ContractAbi = worldContractAbi.text, - DefaultNamespace = "app", - TableSchemas = new List - { - new() - { - Namespace = "app", - TableName = "Counter", - Columns = new List> - { - new("value", "uint32"), - }, - KeyColumns = new string[0], // empty key schema - singleton table (one record only) - }, - }, - }); - Debug.Log("MUD World client ready"); - - // 3. Get Table client. - var table = world.GetTable("Counter"); - - // 4. Query counter value - var allRecords = await table.Query(MudQuery.All); // Query all records of the Counter table - var singleRecord = allRecords.Single(); // Get single record - var counterValue = (BigInteger)singleRecord[0]; // Get value of the first column - Debug.Log($"Counter value on load: {counterValue}"); - UpdateGui(counterValue); - - // 5. Subscribe to table updates. - table.RecordUpdated += OnCounterRecordUpdated; - } - - public async void IncrementCounter() - { - if (web3 is null) - { - Debug.LogError("Can't run sample. Web3 client was not initialized."); - return; - } - - // 5. Send transaction to execute the Increment function of the World contract. - Debug.Log("Sending transaction to execute the Increment function.."); - await world.GetSystems().Send("increment"); - Debug.Log($"Increment successful"); - } - - private void OnCounterRecordUpdated(object[] key, object[] record) - { - var counterValue = (BigInteger)record[0]; - Debug.Log($"Counter value updated: {counterValue}"); - UpdateGui(counterValue); - } - - private void UpdateGui(BigInteger counterValue) - { - counterLabel.text = counterValue.ToString("d"); - } -} diff --git a/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta b/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta deleted file mode 100644 index 392f646f6..000000000 --- a/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0784d678e93c29d44b5621a24b931617 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs b/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs index 298ad6aaf..fb7d293ef 100644 --- a/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs +++ b/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs @@ -8,6 +8,7 @@ namespace ChainSafe.Gaming.Marketplace.Samples { + // More tests public class MarketplaceSample : MonoBehaviour { [SerializeField] private Transform parentForItems; From 544fc7760458e552a3092d1dfe0a034d7403cbb4 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 23:30:20 +0300 Subject: [PATCH 40/62] compile error fix --- .github/workflows/duplicate_samples.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index d5d9477f7..af2839136 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -8,7 +8,7 @@ on: jobs: setup: name: Duplicate job - uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main + uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 with: arguments: "-duplicate_samples" secrets: inherit From c564488c821002836e4f268ffd5fb068c933f3bd Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 23:32:04 +0300 Subject: [PATCH 41/62] parallel fix --- .github/workflows/duplicate_samples.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index af2839136..07a0a5c89 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -14,6 +14,7 @@ jobs: secrets: inherit check: name: Check job + needs: [ setup ] runs-on: ubuntu-latest steps: - name: Checkout repository From 560bcfd2b8213f9dba1528563356670054e6a927 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Thu, 17 Oct 2024 23:32:51 +0300 Subject: [PATCH 42/62] removed push at the end --- Setup/Git.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index 6263a0a88..d860eb31b 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -15,7 +15,7 @@ public class Git : IRunnable public void Run() { // Push just to make sure we have the latest changes. - Push(); + // Push(); } #region Git Commands From cf240148199b674bec03c2719497528816dd8a4e Mon Sep 17 00:00:00 2001 From: rob1997 Date: Fri, 18 Oct 2024 14:22:15 +0300 Subject: [PATCH 43/62] sync dependencies done --- .github/workflows/duplicate_samples.yaml | 23 +----- .github/workflows/setup.yaml | 2 +- .github/workflows/sync_dependencies.yaml | 16 ++++ Setup/DuplicateSamples.cs | 4 +- Setup/Git.cs | 30 +++----- Setup/Release.cs | 2 +- Setup/Setup.cs | 8 +- Setup/Setup.csproj | 2 + Setup/SyncDependencies.cs | 69 ++++++++++++++++- Setup/UnityTests.cs | 13 ---- Setup/Utils/Dependency.cs | 12 +++ Setup/Utils/Utilities.cs | 58 +++++++++++++- Setup/dependencies.json | 98 ++++++++++++++++++++++++ 13 files changed, 268 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/sync_dependencies.yaml delete mode 100644 Setup/UnityTests.cs create mode 100644 Setup/Utils/Dependency.cs create mode 100644 Setup/dependencies.json diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 07a0a5c89..07d2e41e3 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -1,9 +1,7 @@ name: Duplicate Samples 🪞 on: - push: - branches: - - rob/publish-tool-1120 + workflow_call: jobs: setup: @@ -12,23 +10,4 @@ jobs: with: arguments: "-duplicate_samples" secrets: inherit - check: - name: Check job - needs: [ setup ] - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref || github.ref_name }} - lfs: true - ssh-key: ${{ secrets.DEPLOY_KEY }} - - name: Cache - uses: actions/cache/restore@v4 - with: - path: .git - key: ${{ runner.os }}-git - - name: Run - run: | - git reset --hard \ No newline at end of file diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 004970f4e..8d4674e05 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -36,7 +36,7 @@ jobs: - name: Run run: | cd Setup - dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} Setup/Setup.csproj + dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} Setup/Setup.csproj /property:GIT_ENABLED=true git reset --hard - name: Cache uses: actions/cache/save@v4 diff --git a/.github/workflows/sync_dependencies.yaml b/.github/workflows/sync_dependencies.yaml new file mode 100644 index 000000000..84c6e2f84 --- /dev/null +++ b/.github/workflows/sync_dependencies.yaml @@ -0,0 +1,16 @@ +name: Sync Dependencies 🔄 + +on: + workflow_call: + push: + branches: + - rob/publish-tool-1120 + +jobs: + setup: + name: Sync job + uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 + with: + arguments: "-sync_dependencies" + secrets: inherit + \ No newline at end of file diff --git a/Setup/DuplicateSamples.cs b/Setup/DuplicateSamples.cs index d7b49f61e..5565ad227 100644 --- a/Setup/DuplicateSamples.cs +++ b/Setup/DuplicateSamples.cs @@ -11,7 +11,7 @@ public class DuplicateSamples : IRunnable { private readonly Package[] _packages; - public int Order => 0; + public int Order => 1; public DuplicateSamples() { @@ -41,6 +41,6 @@ public void Run() } } - Git.Commit("Duplicated Samples"); + Git.CommitAndPush("Duplicated Samples"); } } \ No newline at end of file diff --git a/Setup/Git.cs b/Setup/Git.cs index d860eb31b..b284c6826 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -8,23 +8,13 @@ namespace Setup; /// /// Git helper class. /// -public class Git : IRunnable +public class Git { - public int Order => int.MaxValue; - - public void Run() - { - // Push just to make sure we have the latest changes. - // Push(); - } - - #region Git Commands - private static bool _configured; - + public static void Add(string path) { - $"git add \"{path}\" -f".RunWithBash(); + $"git add \"{path}\" -f".Run(); } public static void Commit(string message, string[] tags = null) @@ -35,7 +25,7 @@ public static void Commit(string message, string[] tags = null) } // Checks if there are any changes to commit before committing - $"git diff-index --cached --quiet HEAD || git commit -m \"{message} [skip ci]\"".RunWithBash(); + $"git diff-index --cached --quiet HEAD || git commit -m \"{message} [skip ci]\"".Run(); if (tags != null) { @@ -51,7 +41,7 @@ public static void Commit(string message, string[] tags = null) public static void Push(string[] tags = null) { - "git push -f".RunWithBash(); + "git push -f".Run(); if (tags != null) { @@ -59,7 +49,7 @@ public static void Push(string[] tags = null) { if (!string.IsNullOrEmpty(tag)) { - $"git push origin \"{tag}\"".RunWithBash(); + $"git push origin \"{tag}\"".Run(); } } } @@ -74,16 +64,14 @@ public static void CommitAndPush(string message, string[] tags = null) public static void Tag(string tag) { - $"git tag \"{tag}\"".RunWithBash(); + $"git tag \"{tag}\"".Run(); } private static void Configure() { - "git config user.email $git_email".RunWithBash(); - "git config user.name $git_actor".RunWithBash(); + "git config user.email $git_email".Run(); + "git config user.name $git_actor".Run(); _configured = true; } - - #endregion } \ No newline at end of file diff --git a/Setup/Release.cs b/Setup/Release.cs index f98c58f3f..5a8f40331 100644 --- a/Setup/Release.cs +++ b/Setup/Release.cs @@ -13,7 +13,7 @@ public class Release : IRunnable private readonly string _version; - public int Order => 3; + public int Order => 2; public Release(string version) { diff --git a/Setup/Setup.cs b/Setup/Setup.cs index 94a66b610..8cfdc798b 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -12,15 +12,14 @@ internal class Setup public static readonly List Packages = new List(); - // dotnet run -release:3.0.0 -duplicate_samples -publish_dependencies; + // dotnet run -release:3.0.0 -duplicate_samples -sync_dependencies; static void Main(string[] args) { InitializePackages(); List runnableList = GetRunnableList(args); - // Add Git to the end of the list to push at the end if there are any new commits. - runnableList = runnableList.OrderBy(r => r.Order).Append(new Git()).ToList(); + runnableList = runnableList.OrderBy(r => r.Order).ToList(); foreach (IRunnable runnable in runnableList) { @@ -76,9 +75,6 @@ private static List GetRunnableList(string[] args) case "-sync_dependencies": runnableLit.AddRunnable(new SyncDependencies()); break; - case "-unity_test": - runnableLit.AddRunnable(new UnityTests()); - break; } } diff --git a/Setup/Setup.csproj b/Setup/Setup.csproj index b35ce995f..bbfae008f 100644 --- a/Setup/Setup.csproj +++ b/Setup/Setup.csproj @@ -6,7 +6,9 @@ + + diff --git a/Setup/SyncDependencies.cs b/Setup/SyncDependencies.cs index 8294e268f..6826a0f33 100644 --- a/Setup/SyncDependencies.cs +++ b/Setup/SyncDependencies.cs @@ -1,13 +1,78 @@ +using System; +using System.IO; +using Newtonsoft.Json; using Setup.Utils; namespace Setup; public class SyncDependencies : IRunnable { - public int Order => 1; + public int Order => 0; + + private readonly Dependency[] _dependencies; + + private const string ProjectPath = "../src/ChainSafe.Gaming.Unity/"; + + public SyncDependencies() + { + _dependencies = JsonConvert.DeserializeObject(File.ReadAllText("dependencies.json")); + } public void Run() { - throw new System.NotImplementedException(); +#if DEBUG + string configuration = "Debug"; +#else + string configuration = "Release"; +#endif + $"dotnet publish \"{ProjectPath}ChainSafe.Gaming.Unity.csproj\" -c {configuration} /property:Unity=true".Run(); + + string source = Path.Combine(ProjectPath, "bin", configuration, "netstandard2.1", "publish"); + + foreach (Dependency dependency in _dependencies) + { + string[] namespaces = dependency.Namespaces; + + string destination = Path.Combine("../", dependency.Path); + + // Remove previous dependencies first + if (Directory.Exists(destination)) + { + DirectoryInfo directory = new DirectoryInfo(destination); + + foreach (var file in directory.GetFiles()) + { + if (file.Extension == ".dll" || file.Extension == ".pdb") + { + file.Delete(); + } + } + } + + else + { + Directory.CreateDirectory(destination); + } + + Console.WriteLine($"Copying Dependencies to {destination}..."); + + foreach (string name in namespaces) + { + File.Copy(Path.Combine(source, $"{name}.dll"), Path.Combine(destination, $"{name}.dll"), true); +#if DEBUG + string filePath = Path.Combine(source, $"{name}.pdb"); + + if (File.Exists(filePath)) + { + File.Copy(filePath, Path.Combine(destination, $"{name}.pdb"), true); + } +#endif + Console.WriteLine(name); + } + + Git.Add(destination); + } + + Git.CommitAndPush("Sync Dependencies"); } } \ No newline at end of file diff --git a/Setup/UnityTests.cs b/Setup/UnityTests.cs deleted file mode 100644 index c7a2ab9b9..000000000 --- a/Setup/UnityTests.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Setup.Utils; - -namespace Setup; - -public class UnityTests : IRunnable -{ - public int Order => 2; - - public void Run() - { - throw new System.NotImplementedException(); - } -} \ No newline at end of file diff --git a/Setup/Utils/Dependency.cs b/Setup/Utils/Dependency.cs new file mode 100644 index 000000000..f6eb099d1 --- /dev/null +++ b/Setup/Utils/Dependency.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Setup.Utils; + +public struct Dependency +{ + [JsonProperty("path")] + public string Path { get; private set; } + + [JsonProperty("namespaces")] + public string[] Namespaces { get; private set; } +} \ No newline at end of file diff --git a/Setup/Utils/Utilities.cs b/Setup/Utils/Utilities.cs index fb35d2d68..0a6e00306 100644 --- a/Setup/Utils/Utilities.cs +++ b/Setup/Utils/Utilities.cs @@ -2,11 +2,60 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Management.Automation; +using System.Runtime.InteropServices; namespace Setup.Utils; public static class Utilities { + public static void Run(this string command) + { +#if !GIT_ENABLED + if (command.ToLower().StartsWith("git")) + { + Console.WriteLine($"Git disabled skipping command: {command}"); + + return; + } +#endif + + // Tried switch statement couldn't find a way to make it work + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + command.RunWithBash(); + } + + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + command.RunWithPowershell(); + } + + else + { + throw new Exception($"[Unsupported OS] Can't run command: {command}"); + } + } + + public static void RunWithPowershell(this string command) + { + using (PowerShell powerShell = PowerShell.Create()) + { + var result = powerShell.AddScript($"{command} | Out-String").Invoke(); + + // Output + foreach (var line in result) + { + Console.WriteLine(line.ToString()); + } + + if (powerShell.HadErrors) + { + throw new Exception($"Error executing powershell command: {command}"); + } + } + } + /// /// Runs commands with bash. /// @@ -14,6 +63,13 @@ public static class Utilities /// If command fails. public static void RunWithBash( this string command) { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + Console.WriteLine($"Skipping bash command \"{command}\" on non-linux platform."); + + return; + } + command = command.Replace( "\"", "\\\"" ); Process process = new Process() @@ -41,7 +97,7 @@ public static void RunWithBash( this string command) if (process.ExitCode != 0) { - throw new Exception($"Error executing bash command {command}"); + throw new Exception($"Error executing bash command: {command} Exit Code: {process.ExitCode}"); } } diff --git a/Setup/dependencies.json b/Setup/dependencies.json new file mode 100644 index 000000000..0ca9b64ca --- /dev/null +++ b/Setup/dependencies.json @@ -0,0 +1,98 @@ +[ + { + "path":"Packages/io.chainsafe.web3-unity/Runtime/Libraries/", + "namespaces": + [ + "ADRaffy.ENSNormalize", + "Nethereum.Model", + "BouncyCastle.Crypto", + "Nethereum.RLP", + "ChainSafe.Gaming.Debugging", + "Nethereum.RPC", + "Nethereum.RPC.Reactive", + "Nethereum.JsonRpc.WebSocketClient", + "ChainSafe.Gaming.Gelato", + "ChainSafe.Gaming.SygmaClient", + "Nethereum.Signer.EIP712", + "ChainSafe.Gaming.InProcessSigner", + "Nethereum.Signer", + "ChainSafe.Gaming.InProcessTransactionExecutor", + "Nethereum.Util", + "ChainSafe.Gaming.Unity.ThirdParty", + "Nethereum.Web3", + "ChainSafe.Gaming.Unity", + "System.Buffers", + "ChainSafe.Gaming.WalletConnect", + "System.Memory", + "ChainSafe.Gaming", + "System.Numerics.Vectors", + "Microsoft.Bcl.AsyncInterfaces", + "System.Reactive", + "Microsoft.Extensions.DependencyInjection.Abstractions", + "System.Runtime.CompilerServices.Unsafe", + "Microsoft.Extensions.DependencyInjection", + "System.Runtime.InteropServices.WindowsRuntime", + "Microsoft.Extensions.Logging.Abstractions", + "System.Security.Cryptography.Cng", + "Microsoft.IdentityModel.Abstractions", + "System.Text.Encodings.Web", + "Microsoft.IdentityModel.Logging", + "System.Text.Json", + "Microsoft.IdentityModel.Tokens", + "System.Threading.Channels", + "NBitcoin", + "System.Threading.Tasks.Extensions", + "Nethereum.ABI", + "WalletConnectSharp.Auth", + "Nethereum.Accounts", + "WalletConnectSharp.Common", + "WalletConnectSharp.Events", + "Nethereum.BlockchainProcessing", + "WalletConnectSharp.Core", + "Nethereum.Contracts", + "WalletConnectSharp.Crypto", + "Nethereum.Hex", + "Nethereum.JsonRpc.Client", + "WalletConnectSharp.Network.Websocket", + "WalletConnectSharp.Network", + "Nethereum.JsonRpc.RpcClient", + "WalletConnectSharp.Sign", + "Nethereum.KeyStore", + "WalletConnectSharp.Storage", + "Nethereum.Merkle.Patricia", + "WalletConnectSharp.Web3Wallet", + "Nethereum.Merkle", + "Websocket.Client", + "Nethereum.Siwe.Core", + "Nethereum.Siwe", + "Nethereum.UI", + "ChainSafe.Gaming.Unity.MetaMask", + "ChainSafe.Gaming.Marketplace", + "ChainSafe.Gaming.Unity.EthereumWindow" + ] + }, + { + "path":"Packages/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/", + "namespaces": + [ + "Chainsafe.Gaming.Chainlink", + "ChainSafe.Gaming.Lootboxes.Chainlink" + ] + }, + { + "path":"Packages/io.chainsafe.web3-unity.hyperplay/Runtime/Libraries/", + "namespaces": + [ + "ChainSafe.Gaming.HyperPlay" + ] + }, + { + "path":"Packages/io.chainsafe.web3-unity.mud/Runtime/Libraries/", + "namespaces": + [ + "ChainSafe.Gaming.Mud", + "Nethereum.Mud", + "Nethereum.Mud.Contracts" + ] + } +] \ No newline at end of file From f10e9124dd156744011971cb7fb3d231fc1aa134 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Fri, 18 Oct 2024 14:29:40 +0300 Subject: [PATCH 44/62] added dotnet restore --- Setup/SyncDependencies.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Setup/SyncDependencies.cs b/Setup/SyncDependencies.cs index 6826a0f33..3b88d71dc 100644 --- a/Setup/SyncDependencies.cs +++ b/Setup/SyncDependencies.cs @@ -25,6 +25,8 @@ public void Run() #else string configuration = "Release"; #endif + $"dotnet restore \"{ProjectPath}ChainSafe.Gaming.Unity.csproj\"".Run(); + $"dotnet publish \"{ProjectPath}ChainSafe.Gaming.Unity.csproj\" -c {configuration} /property:Unity=true".Run(); string source = Path.Combine(ProjectPath, "bin", configuration, "netstandard2.1", "publish"); From d7b004cb1756ab7dd826be4a44f874a060bbaddb Mon Sep 17 00:00:00 2001 From: rob1997 Date: Fri, 18 Oct 2024 14:35:37 +0300 Subject: [PATCH 45/62] removed restore added git enable property --- Setup/Setup.csproj | 4 ++++ Setup/SyncDependencies.cs | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Setup/Setup.csproj b/Setup/Setup.csproj index bbfae008f..ae398a998 100644 --- a/Setup/Setup.csproj +++ b/Setup/Setup.csproj @@ -11,4 +11,8 @@ + + GIT_ENABLED + + diff --git a/Setup/SyncDependencies.cs b/Setup/SyncDependencies.cs index 3b88d71dc..6826a0f33 100644 --- a/Setup/SyncDependencies.cs +++ b/Setup/SyncDependencies.cs @@ -25,8 +25,6 @@ public void Run() #else string configuration = "Release"; #endif - $"dotnet restore \"{ProjectPath}ChainSafe.Gaming.Unity.csproj\"".Run(); - $"dotnet publish \"{ProjectPath}ChainSafe.Gaming.Unity.csproj\" -c {configuration} /property:Unity=true".Run(); string source = Path.Combine(ProjectPath, "bin", configuration, "netstandard2.1", "publish"); From b378b07d8bc5f03f860ac0ef5112353313af6a86 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Fri, 18 Oct 2024 14:40:24 +0300 Subject: [PATCH 46/62] update submodule before dotnet run --- .github/workflows/setup.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 8d4674e05..f24d96a25 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -27,7 +27,10 @@ jobs: ref: ${{ github.head_ref || github.ref_name }} lfs: true ssh-key: ${{ secrets.DEPLOY_KEY }} - + - name: update submodules + run: | + git submodule update --init + shell: bash - name: Setup .NET uses: actions/setup-dotnet@v3 with: From 8466621f1c935fbf1b62af5a95a4e719239dc8c5 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Fri, 18 Oct 2024 15:10:59 +0300 Subject: [PATCH 47/62] git fix --- .github/workflows/setup.yaml | 2 +- Setup/Git.cs | 7 +++++++ Setup/Setup.cs | 13 ++++++++++--- Setup/Setup.csproj | 4 ---- Setup/Utils/Utilities.cs | 13 +++++++------ 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index f24d96a25..5f3d22d9b 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -39,7 +39,7 @@ jobs: - name: Run run: | cd Setup - dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} Setup/Setup.csproj /property:GIT_ENABLED=true + dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} -git_enabled Setup/Setup.csproj git reset --hard - name: Cache uses: actions/cache/save@v4 diff --git a/Setup/Git.cs b/Setup/Git.cs index b284c6826..b69c0fb48 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -11,7 +11,14 @@ namespace Setup; public class Git { private static bool _configured; + + public static bool Enabled { get; private set; } + public static void Enable() + { + Enabled = true; + } + public static void Add(string path) { $"git add \"{path}\" -f".Run(); diff --git a/Setup/Setup.cs b/Setup/Setup.cs index 8cfdc798b..45d71a2ff 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -60,22 +60,29 @@ private static List GetRunnableList(string[] args) // Parse arguments and Run operations based on that. foreach (var arg in args) { + IRunnable runnable = null; + switch (arg) { case not null when arg.StartsWith("-release"): string version = arg.Split(":")[1]; - runnableLit.AddRunnable(new Release(version)); + runnable = new Release(version); break; case "-duplicate_samples": - runnableLit.AddRunnable(new DuplicateSamples()); + runnable = new DuplicateSamples(); break; case "-sync_dependencies": - runnableLit.AddRunnable(new SyncDependencies()); + runnable = new SyncDependencies(); break; + case "-git_enabled": + Git.Enable(); + continue; } + + runnableLit.AddRunnable(runnable); } return runnableLit; diff --git a/Setup/Setup.csproj b/Setup/Setup.csproj index ae398a998..e567b1161 100644 --- a/Setup/Setup.csproj +++ b/Setup/Setup.csproj @@ -10,9 +10,5 @@ - - - GIT_ENABLED - diff --git a/Setup/Utils/Utilities.cs b/Setup/Utils/Utilities.cs index 0a6e00306..aab767060 100644 --- a/Setup/Utils/Utilities.cs +++ b/Setup/Utils/Utilities.cs @@ -11,14 +11,15 @@ public static class Utilities { public static void Run(this string command) { -#if !GIT_ENABLED - if (command.ToLower().StartsWith("git")) + if (!Git.Enabled) { - Console.WriteLine($"Git disabled skipping command: {command}"); + if (command.ToLower().StartsWith("git")) + { + Console.WriteLine($"Git disabled skipping command: {command}"); - return; - } -#endif + return; + } + } // Tried switch statement couldn't find a way to make it work if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) From dcc91e26d934081f8a967af85ff51f6974bcac6a Mon Sep 17 00:00:00 2001 From: rob1997 Date: Fri, 18 Oct 2024 15:13:05 +0300 Subject: [PATCH 48/62] default case added for runnable args switch --- Setup/Setup.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Setup/Setup.cs b/Setup/Setup.cs index 45d71a2ff..223ea79c9 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -60,7 +60,7 @@ private static List GetRunnableList(string[] args) // Parse arguments and Run operations based on that. foreach (var arg in args) { - IRunnable runnable = null; + IRunnable runnable; switch (arg) { @@ -80,6 +80,8 @@ private static List GetRunnableList(string[] args) case "-git_enabled": Git.Enable(); continue; + default: + continue; } runnableLit.AddRunnable(runnable); From 800bebaef4e80e92f61aecba4a80895adf4f8237 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Fri, 18 Oct 2024 16:17:57 +0300 Subject: [PATCH 49/62] release by default, git enabled by default and duplicate and sync now can also be triggered manually --- .github/workflows/duplicate_samples.yaml | 17 ++++++++++++++++- .github/workflows/setup.yaml | 2 +- .github/workflows/sync_dependencies.yaml | 16 +++++++++++++++- Setup/Git.cs | 18 ++++++++++++++---- Setup/Setup.cs | 22 +++++++++++----------- 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 07d2e41e3..00878f8f8 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -2,12 +2,27 @@ name: Duplicate Samples 🪞 on: workflow_call: + workflow_dispatch: + inputs: + arguments: + required: false + description: 'Run Arguments' + type: string + configuration: + required: true + description: 'Run Configuration' + default: 'Release' + type: choice + options: + - Release + - Debug + jobs: setup: name: Duplicate job uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 with: - arguments: "-duplicate_samples" + arguments: "-duplicate_samples ${{ github.event.inputs.arguments || '-git:enabled' }} -c ${{ github.event.inputs.configuration || 'Release' }}" secrets: inherit \ No newline at end of file diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml index 5f3d22d9b..5cd086a04 100644 --- a/.github/workflows/setup.yaml +++ b/.github/workflows/setup.yaml @@ -39,7 +39,7 @@ jobs: - name: Run run: | cd Setup - dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} -git_enabled Setup/Setup.csproj + dotnet run ${{ inputs.arguments || github.event.inputs.arguments }} Setup/Setup.csproj git reset --hard - name: Cache uses: actions/cache/save@v4 diff --git a/.github/workflows/sync_dependencies.yaml b/.github/workflows/sync_dependencies.yaml index 84c6e2f84..7baf432a2 100644 --- a/.github/workflows/sync_dependencies.yaml +++ b/.github/workflows/sync_dependencies.yaml @@ -5,12 +5,26 @@ on: push: branches: - rob/publish-tool-1120 + workflow_dispatch: + inputs: + arguments: + required: false + description: 'Run Arguments' + type: string + configuration: + required: true + description: 'Run Configuration' + default: 'Release' + type: choice + options: + - Release + - Debug jobs: setup: name: Sync job uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 with: - arguments: "-sync_dependencies" + arguments: "-sync_dependencies ${{ github.event.inputs.arguments || '-git:enabled' }} -c ${{ github.event.inputs.configuration || 'Release' }}" secrets: inherit \ No newline at end of file diff --git a/Setup/Git.cs b/Setup/Git.cs index b69c0fb48..77be8fea5 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -11,12 +11,22 @@ namespace Setup; public class Git { private static bool _configured; - - public static bool Enabled { get; private set; } - public static void Enable() + public static bool Enabled { get; private set; } = true; + + public static void Configure(string configuration) { - Enabled = true; + switch (configuration) + { + case "enabled": + Enabled = true; + break; + case "disabled": + Enabled = false; + break; + default: + throw new Exception($"-git can't configure {configuration}"); + } } public static void Add(string path) diff --git a/Setup/Setup.cs b/Setup/Setup.cs index 223ea79c9..28d96e9d2 100644 --- a/Setup/Setup.cs +++ b/Setup/Setup.cs @@ -55,39 +55,39 @@ private static void InitializePackages() /// Runnable List. private static List GetRunnableList(string[] args) { - List runnableLit = new List(); + List runnableList = new List(); // Parse arguments and Run operations based on that. foreach (var arg in args) { - IRunnable runnable; - switch (arg) { case not null when arg.StartsWith("-release"): string version = arg.Split(":")[1]; - runnable = new Release(version); + runnableList.AddRunnable(new Release(version)); break; case "-duplicate_samples": - runnable = new DuplicateSamples(); + runnableList.AddRunnable(new DuplicateSamples()); break; case "-sync_dependencies": - runnable = new SyncDependencies(); + runnableList.AddRunnable(new SyncDependencies()); break; - case "-git_enabled": - Git.Enable(); + + case not null when arg.StartsWith("-git"): + + string configuration = arg.Split(":")[1]; + Git.Configure(configuration); continue; + default: continue; } - - runnableLit.AddRunnable(runnable); } - return runnableLit; + return runnableList; } } } \ No newline at end of file From 5c1b327a883c35491869ff2387f7fcebda1eda40 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Sat, 19 Oct 2024 06:45:55 +0300 Subject: [PATCH 50/62] cleaned up scripts --- .github/workflows/duplicate_samples.yaml | 3 +- .github/workflows/sync_dependencies.yaml | 3 - Setup/DuplicateSamples.cs | 2 + Setup/SyncDependencies.cs | 2 + scripts/data/duplicate_samples.txt | 15 ----- scripts/data/published_dependencies.txt | 76 ---------------------- scripts/debug-publish-to-unity-package.bat | 56 ---------------- scripts/debug-publish-to-unity-package.sh | 44 ------------- scripts/publish-to-unity-package.bat | 44 ------------- scripts/publish-to-unity-package.sh | 40 ------------ scripts/publish.bat | 5 -- scripts/publish.sh | 11 ---- scripts/release-web3-auth.sh | 12 ---- scripts/release-web3-unity.sh | 14 ---- scripts/setup.bat | 11 +++- scripts/setup.sh | 7 +- 16 files changed, 17 insertions(+), 328 deletions(-) delete mode 100644 scripts/data/duplicate_samples.txt delete mode 100644 scripts/data/published_dependencies.txt delete mode 100644 scripts/debug-publish-to-unity-package.bat delete mode 100755 scripts/debug-publish-to-unity-package.sh delete mode 100644 scripts/publish-to-unity-package.bat delete mode 100755 scripts/publish-to-unity-package.sh delete mode 100644 scripts/publish.bat delete mode 100644 scripts/publish.sh delete mode 100644 scripts/release-web3-auth.sh delete mode 100644 scripts/release-web3-unity.sh diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 00878f8f8..2b669c405 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -16,8 +16,7 @@ on: options: - Release - Debug - - + jobs: setup: name: Duplicate job diff --git a/.github/workflows/sync_dependencies.yaml b/.github/workflows/sync_dependencies.yaml index 7baf432a2..05c280456 100644 --- a/.github/workflows/sync_dependencies.yaml +++ b/.github/workflows/sync_dependencies.yaml @@ -2,9 +2,6 @@ name: Sync Dependencies 🔄 on: workflow_call: - push: - branches: - - rob/publish-tool-1120 workflow_dispatch: inputs: arguments: diff --git a/Setup/DuplicateSamples.cs b/Setup/DuplicateSamples.cs index 5565ad227..8ad287a49 100644 --- a/Setup/DuplicateSamples.cs +++ b/Setup/DuplicateSamples.cs @@ -42,5 +42,7 @@ public void Run() } Git.CommitAndPush("Duplicated Samples"); + + Console.WriteLine("Duplicated Samples Successfully!"); } } \ No newline at end of file diff --git a/Setup/SyncDependencies.cs b/Setup/SyncDependencies.cs index 6826a0f33..9ce014f48 100644 --- a/Setup/SyncDependencies.cs +++ b/Setup/SyncDependencies.cs @@ -74,5 +74,7 @@ public void Run() } Git.CommitAndPush("Sync Dependencies"); + + Console.WriteLine("Dependencies Synced Successfully!"); } } \ No newline at end of file diff --git a/scripts/data/duplicate_samples.txt b/scripts/data/duplicate_samples.txt deleted file mode 100644 index 5ff46cb8c..000000000 --- a/scripts/data/duplicate_samples.txt +++ /dev/null @@ -1,15 +0,0 @@ -source:src/UnitySampleProject/Assets/Samples/web3.unity SDK - display_name:Web3.Unity Samples - destination:Packages/io.chainsafe.web3-unity/Samples~/Web3.Unity/ -source:src/UnitySampleProject/Assets/Samples/web3.unity SDK Lootboxes - display_name:Lootboxes Samples - destination:Packages/io.chainsafe.web3-unity.lootboxes/Samples~/Web3.Unity Chainlink Lootboxes/ -source:src/UnitySampleProject/Assets/Samples/web3.unity SDK Ramp - display_name:Ramp Samples - destination:Packages/io.chainsafe.web3-unity.ramp/Samples~/Web3.Unity Ramp/ -source:src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace - display_name:Marketplace Samples - destination:Packages/io.chainsafe.web3-unity.marketplace/Samples~/Web3.Unity Marketplace/ -source:src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD - display_name:Marketplace Samples - destination:Packages/io.chainsafe.web3-unity.mud/Samples~/Web3.Unity MUD/ \ No newline at end of file diff --git a/scripts/data/published_dependencies.txt b/scripts/data/published_dependencies.txt deleted file mode 100644 index 44cf01d1f..000000000 --- a/scripts/data/published_dependencies.txt +++ /dev/null @@ -1,76 +0,0 @@ -Packages/io.chainsafe.web3-unity/Runtime/Libraries/: - ADRaffy.ENSNormalize - Nethereum.Model - BouncyCastle.Crypto - Nethereum.RLP - ChainSafe.Gaming.Debugging - Nethereum.RPC - Nethereum.RPC.Reactive - Nethereum.JsonRpc.WebSocketClient - ChainSafe.Gaming.Gelato - ChainSafe.Gaming.SygmaClient - Nethereum.Signer.EIP712 - ChainSafe.Gaming.InProcessSigner - Nethereum.Signer - ChainSafe.Gaming.InProcessTransactionExecutor - Nethereum.Util - ChainSafe.Gaming.Unity.ThirdParty - Nethereum.Web3 - ChainSafe.Gaming.Unity - System.Buffers - ChainSafe.Gaming.WalletConnect - System.Memory - ChainSafe.Gaming - System.Numerics.Vectors - Microsoft.Bcl.AsyncInterfaces - System.Reactive - Microsoft.Extensions.DependencyInjection.Abstractions - System.Runtime.CompilerServices.Unsafe - Microsoft.Extensions.DependencyInjection - System.Runtime.InteropServices.WindowsRuntime - Microsoft.Extensions.Logging.Abstractions - System.Security.Cryptography.Cng - Microsoft.IdentityModel.Abstractions - System.Text.Encodings.Web - Microsoft.IdentityModel.Logging - System.Text.Json - Microsoft.IdentityModel.Tokens - System.Threading.Channels - NBitcoin - System.Threading.Tasks.Extensions - Nethereum.ABI - WalletConnectSharp.Auth - Nethereum.Accounts - WalletConnectSharp.Common - WalletConnectSharp.Events - Nethereum.BlockchainProcessing - WalletConnectSharp.Core - Nethereum.Contracts - WalletConnectSharp.Crypto - Nethereum.Hex - Nethereum.JsonRpc.Client - WalletConnectSharp.Network.Websocket - WalletConnectSharp.Network - Nethereum.JsonRpc.RpcClient - WalletConnectSharp.Sign - Nethereum.KeyStore - WalletConnectSharp.Storage - Nethereum.Merkle.Patricia - WalletConnectSharp.Web3Wallet - Nethereum.Merkle - Websocket.Client - Nethereum.Siwe.Core - Nethereum.Siwe - Nethereum.UI - ChainSafe.Gaming.Unity.MetaMask - ChainSafe.Gaming.Marketplace - ChainSafe.Gaming.Unity.EthereumWindow -Packages/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/: - Chainsafe.Gaming.Chainlink - ChainSafe.Gaming.Lootboxes.Chainlink -Packages/io.chainsafe.web3-unity.hyperplay/Runtime/Libraries/: - ChainSafe.Gaming.HyperPlay -Packages/io.chainsafe.web3-unity.mud/Runtime/Libraries/: - ChainSafe.Gaming.Mud - Nethereum.Mud - Nethereum.Mud.Contracts \ No newline at end of file diff --git a/scripts/debug-publish-to-unity-package.bat b/scripts/debug-publish-to-unity-package.bat deleted file mode 100644 index 1d40e8c45..000000000 --- a/scripts/debug-publish-to-unity-package.bat +++ /dev/null @@ -1,56 +0,0 @@ -@echo off - -SET SCRIPT_DIR=%~dp0 - -setlocal enabledelayedexpansion - -echo Building project... -pushd "%SCRIPT_DIR%\..\src\ChainSafe.Gaming.Unity" - -rem Publish the project -dotnet publish ChainSafe.Gaming.Unity.csproj -c Debug /property:Unity=true - -IF %ERRORLEVEL% NEQ 0 ( - echo Execution failed - exit /b %ERRORLEVEL% -) - -set PUBLISH_PATH=bin\Debug\netstandard2.1\publish - -rem List generated DLLs -echo DLLs Generated -dir /b "%PUBLISH_PATH%" - -set PACKAGE_LIB_PATH= - -rem Read and process each line from the dependencies file -for /f "usebackq tokens=*" %%A in ("%SCRIPT_DIR%\data\published_dependencies.txt") do ( - - set entry=%%A - - rem Check if the line ends with a colon - if "!entry:~-1!" == ":" ( - set "PACKAGE_LIB_PATH=%SCRIPT_DIR%..\!entry:~0,-1!" - if exist "!PACKAGE_LIB_PATH!\" ( - del /q "!PACKAGE_LIB_PATH!\*.dll" - del /q "!PACKAGE_LIB_PATH!\*.pdb" - ) else ( - mkdir "!PACKAGE_LIB_PATH!" - ) - - echo Copying to !PACKAGE_LIB_PATH!... - ) else ( - set "DEPENDENCY=!entry: =!" - copy /y "%PUBLISH_PATH%\!DEPENDENCY!.dll" "!PACKAGE_LIB_PATH!" - copy /y "%PUBLISH_PATH%\!DEPENDENCY!.pdb" "!PACKAGE_LIB_PATH!" - ) -) - -popd - -rem Restore solution -pushd "..\" -dotnet restore -popd - -echo Done \ No newline at end of file diff --git a/scripts/debug-publish-to-unity-package.sh b/scripts/debug-publish-to-unity-package.sh deleted file mode 100755 index 89a449766..000000000 --- a/scripts/debug-publish-to-unity-package.sh +++ /dev/null @@ -1,44 +0,0 @@ -#! /usr/bin/env sh - -set -e - -scripts_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) - -echo Publishing project... - -pushd "$scripts_dir"/../src/ChainSafe.Gaming.Unity - -dotnet publish ChainSafe.Gaming.Unity.csproj -c Debug /property:Unity=true - -export PUBLISH_PATH="bin/Debug/netstandard2.1/publish" - -echo -e "DLLs Generated\n$(ls "$PUBLISH_PATH")" - -export PACKAGE_LIB_PATH= - -while IFS= read -r entry || [ -n "$entry" ]; -do - entry=$(echo "$entry" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [[ $entry == *: ]] - then - PACKAGE_LIB_PATH="$scripts_dir/../${entry%:}" - if [ -d "$PACKAGE_LIB_PATH" ]; then - rm -rf "$PACKAGE_LIB_PATH"/*.dll - rm -rf "$PACKAGE_LIB_PATH"/*.pdb - else - mkdir -p "$PACKAGE_LIB_PATH" - fi - echo "Copying to $PACKAGE_LIB_PATH..." - else - export DEPENDENCY=$(echo "$entry" | tr -d '\t' | tr -d ' ') - cp -fr "$PUBLISH_PATH/$DEPENDENCY".dll $PACKAGE_LIB_PATH - - if [ -f "$PUBLISH_PATH/$DEPENDENCY".pdb ]; then - cp -fr "$PUBLISH_PATH/$DEPENDENCY".pdb $PACKAGE_LIB_PATH - fi - fi -done < "$scripts_dir/data/published_dependencies.txt" - -popd - -echo Done \ No newline at end of file diff --git a/scripts/publish-to-unity-package.bat b/scripts/publish-to-unity-package.bat deleted file mode 100644 index 83a99385c..000000000 --- a/scripts/publish-to-unity-package.bat +++ /dev/null @@ -1,44 +0,0 @@ -@echo off -SET SCRIPT_DIR=%~dp0 - -setlocal enabledelayedexpansion - -echo Building project... -pushd "%SCRIPT_DIR%\..\src\ChainSafe.Gaming.Unity" - -rem Publish the project -dotnet publish ChainSafe.Gaming.Unity.csproj -c Release /property:Unity=true - -set PUBLISH_PATH=bin\Release\netstandard2.1\publish - -rem List generated DLLs -echo DLLs Generated -dir /b "%PUBLISH_PATH%" - -set PACKAGE_LIB_PATH= - -rem Read and process each line from the dependencies file -for /f "usebackq tokens=*" %%A in ("%SCRIPT_DIR%\data\published_dependencies.txt") do ( - - set entry=%%A - - rem Check if the line ends with a colon - if "!entry:~-1!" == ":" ( - set "PACKAGE_LIB_PATH=%SCRIPT_DIR%..\!entry:~0,-1!" - if exist "!PACKAGE_LIB_PATH!\" ( - del /q "!PACKAGE_LIB_PATH!\*.dll" - del /q "!PACKAGE_LIB_PATH!\*.pdb" - ) else ( - mkdir "!PACKAGE_LIB_PATH!" - ) - - echo Copying to !PACKAGE_LIB_PATH!... - ) else ( - set "DEPENDENCY=!entry: =!" - copy /y "%PUBLISH_PATH%\!DEPENDENCY!.dll" "!PACKAGE_LIB_PATH!" - ) -) - -popd - -echo Done \ No newline at end of file diff --git a/scripts/publish-to-unity-package.sh b/scripts/publish-to-unity-package.sh deleted file mode 100755 index 150615f04..000000000 --- a/scripts/publish-to-unity-package.sh +++ /dev/null @@ -1,40 +0,0 @@ -#! /usr/bin/env sh - -set -e - -scripts_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) - -echo Publishing project... - -pushd "$scripts_dir"/../src/ChainSafe.Gaming.Unity - -dotnet publish ChainSafe.Gaming.Unity.csproj -c Release /property:Unity=true - -export PUBLISH_PATH="bin/Release/netstandard2.1/publish" - -echo -e "DLLs Generated\n$(ls "$PUBLISH_PATH")" - -export PACKAGE_LIB_PATH= - -while IFS= read -r entry || [ -n "$entry" ]; -do - entry=$(echo "$entry" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') - if [[ $entry == *: ]] - then - PACKAGE_LIB_PATH="$scripts_dir/../${entry%:}" - if [ -d "$PACKAGE_LIB_PATH" ]; then - rm -rf "$PACKAGE_LIB_PATH"/*.dll - rm -rf "$PACKAGE_LIB_PATH"/*.pdb - else - mkdir -p "$PACKAGE_LIB_PATH" - fi - echo "Copying to $PACKAGE_LIB_PATH..." - else - export DEPENDENCY=$(echo "$entry" | tr -d '\t' | tr -d ' ') - cp -fr "$PUBLISH_PATH/$DEPENDENCY".dll $PACKAGE_LIB_PATH - fi -done < "$scripts_dir/data/published_dependencies.txt" - -popd - -echo Done \ No newline at end of file diff --git a/scripts/publish.bat b/scripts/publish.bat deleted file mode 100644 index 9a0ca8895..000000000 --- a/scripts/publish.bat +++ /dev/null @@ -1,5 +0,0 @@ -dotnet publish -c release /property:Unity=true - -pushd ..\.. -dotnet restore -popd \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh deleted file mode 100644 index 01ea93249..000000000 --- a/scripts/publish.sh +++ /dev/null @@ -1,11 +0,0 @@ -#! /usr/bin/env sh -scripts_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) - -pushd "$scripts_dir"/../ -dotnet publish -c release /property:Unity=true - -pushd ../.. -dotnet restore - -popd -popd \ No newline at end of file diff --git a/scripts/release-web3-auth.sh b/scripts/release-web3-auth.sh deleted file mode 100644 index 2ed33b5e5..000000000 --- a/scripts/release-web3-auth.sh +++ /dev/null @@ -1,12 +0,0 @@ -#! /usr/bin/env sh - -scripts_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) -source "$scripts_dir"/setup.sh - -git add "$scripts_dir"/../Packages/io.chainsafe.web3-unity.web3auth/. - -MESSAGE="release-v$1" - -git commit -m "$MESSAGE" -git tag -a "io.chainsafe.web3-unity.web3auth/$1" -m "$MESSAGE" -git push \ No newline at end of file diff --git a/scripts/release-web3-unity.sh b/scripts/release-web3-unity.sh deleted file mode 100644 index 0e6d971af..000000000 --- a/scripts/release-web3-unity.sh +++ /dev/null @@ -1,14 +0,0 @@ -#! /usr/bin/env sh - -scripts_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) -source "$scripts_dir"/setup.sh - -git add "$scripts_dir"/../Packages/io.chainsafe.web3-unity/. - -git add "$scripts_dir"/../Packages/io.chainsafe.web3-unity/Runtime/Libraries/. -f - -MESSAGE="release-v$1" - -git commit -m "$MESSAGE" -git tag -a "io.chainsafe.web3-unity/$1" -m "$MESSAGE" -git push \ No newline at end of file diff --git a/scripts/setup.bat b/scripts/setup.bat index 663aa2483..f94a29e1c 100644 --- a/scripts/setup.bat +++ b/scripts/setup.bat @@ -3,12 +3,17 @@ SET SCRIPT_DIR=%~dp0 REM Change to the directory where the script resides, then navigate to the parent. -pushd "%SCRIPT_DIR%\.." +pushd "%SCRIPT_DIR%\..\Setup" REM clone submodules git submodule update --init -REM publish DLLs to unity package -"%SCRIPT_DIR%\publish-to-unity-package.bat" +if "%1"=="" ( + set "config=Release" +) else ( + set "config=%1" +) + +dotnet run -sync_dependencies -git:disabled -c %config% Setup.csproj popd diff --git a/scripts/setup.sh b/scripts/setup.sh index c7e53008c..f1ef9469c 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,11 +1,12 @@ #! /usr/bin/env sh scripts_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) -pushd "$scripts_dir"/../ # clone submodules git submodule update --init -popd + +pushd "$scripts_dir"/../Setup # publish DLLs to unity package -source "$scripts_dir"/publish-to-unity-package.sh +dotnet run -sync_dependencies -git:disabled -c ${1:-Release} Setup.csproj +popd \ No newline at end of file From 17064c9a5c9c5539405fd757ba31439fd77d3491 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 13:15:33 +0300 Subject: [PATCH 51/62] workflows updated and optimized --- .github/workflows/check_and_commit.yml | 136 ------------------ .github/workflows/duplicate_samples.yaml | 4 +- .github/workflows/pull_request_checks.yml | 20 ++- .github/workflows/push_checks.yml | 16 ++- .github/workflows/sync_dependencies.yaml | 4 +- .github/workflows/test.yaml | 2 +- .github/workflows/unity_tests.yml | 58 ++++++++ .../ProjectSettings/EditorBuildSettings.asset | 2 +- 8 files changed, 92 insertions(+), 150 deletions(-) delete mode 100644 .github/workflows/check_and_commit.yml create mode 100644 .github/workflows/unity_tests.yml diff --git a/.github/workflows/check_and_commit.yml b/.github/workflows/check_and_commit.yml deleted file mode 100644 index 215e0243a..000000000 --- a/.github/workflows/check_and_commit.yml +++ /dev/null @@ -1,136 +0,0 @@ -name: Check and Commit - -on: - workflow_call: - -jobs: - duplicate_samples_and_publish_dependencies: - name: Duplicate Samples And Publish Dependencies - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - projectPath: - - src/UnitySampleProject - testMode: - - PlayMode - steps: - - uses: actions/checkout@v4 - with: - lfs: true - ssh-key: ${{ secrets.DEPLOY_KEY }} - - name: Configure Git - run: | - git config user.email $git_email - git config user.name "${{ github.actor }}" - env: - git_email: "${{ github.actor }}@users.noreply.github.com" - - name: Duplicate Web3 Unity Samples - run: | - export SOURCE_PATH= - export DESTINATION_DIRECTORY= - export DESTINATION_PATH= - - while IFS= read -r entry || [ -n "$entry" ]; - do - source_prefix="source:" - display_name_prefix="display_name:" - destination_prefix="destination:" - - entry=$(echo "$entry" | sed -e 's/^[[:space:]]*//') - - if [[ $entry = $source_prefix* ]] - then - SOURCE_PATH=${entry#"$source_prefix"} - elif [[ $entry = $display_name_prefix* ]] - then - DESTINATION_DIRECTORY=${entry#"$display_name_prefix"} - SOURCE_PATH="${GITHUB_WORKSPACE}/$SOURCE_PATH/$(ls "$SOURCE_PATH" | head -n 1)/$DESTINATION_DIRECTORY" - elif [[ $entry = $destination_prefix* ]] - then - DESTINATION_PATH="${GITHUB_WORKSPACE}/${entry#"$destination_prefix"}" - rm -rf "$DESTINATION_PATH" - mkdir -p "$DESTINATION_PATH" - cp -r "$SOURCE_PATH/." "$DESTINATION_PATH" - git add "$DESTINATION_PATH." -f - fi - done < "${GITHUB_WORKSPACE}/scripts/data/duplicate_samples.txt" - - name: update submodules - # clone submodules - run: | - git submodule update --init - shell: bash - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 6.0.x - - name: Publish Solution DLLs - run: | - dotnet publish src/ChainSafe.Gaming.Unity/ChainSafe.Gaming.Unity.csproj -c Release /property:Unity=true - - name: Move DLLs to Unity Packages - run: | - - export PUBLISH_PATH="${GITHUB_WORKSPACE}/${{ vars.PUBLISH_PATH }}" - - echo -e "DLLs Generated\n$(ls "$PUBLISH_PATH")" - - export DLL_META_FILE_TEMPLATE="${{ vars.DLL_META_FILE_TEMPLATE }}" - - export PACKAGE_LIB_PATH= - - while IFS= read -r entry || [ -n "$entry" ]; - do - if [[ $entry == *: ]] - then - PACKAGE_LIB_PATH="${GITHUB_WORKSPACE}/${entry%:}" - if [ -d "$PACKAGE_LIB_PATH" ]; then - rm -rf "$PACKAGE_LIB_PATH"*.dll - rm -rf "$PACKAGE_LIB_PATH"*.pdb - else - mkdir -p "$PACKAGE_LIB_PATH" - fi - else - export DEPENDENCY=$(echo "$entry" | tr -d '\t' | tr -d ' ') - cp "$PUBLISH_PATH/$DEPENDENCY".dll $PACKAGE_LIB_PATH - if ! [ -f "$PACKAGE_LIB_PATH$DEPENDENCY.dll.meta" ]; then - echo -e "${DLL_META_FILE_TEMPLATE/"[[assetGuid]]"/"$(uuidgen | tr -d '-')"}" >> "$PACKAGE_LIB_PATH$DEPENDENCY.dll.meta" - fi - fi - git add "$PACKAGE_LIB_PATH." -f - done < "${GITHUB_WORKSPACE}/scripts/data/published_dependencies.txt" - - uses: actions/cache@v2 - with: - path: ${{ matrix.projectPath }}/Library - key: Library-${{ matrix.projectPath }} - restore-keys: | - Library- - - uses: game-ci/unity-test-runner@v3 - id: tests - env: - UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} - with: - projectPath: ${{ matrix.projectPath }} - customImage: 'unityci/editor:ubuntu-2022.3.26f1-linux-il2cpp-3.1.0' - testMode: ${{ matrix.testMode }} - artifactsPath: ${{ matrix.testMode }}-artifacts - githubToken: ${{ secrets.GITHUB_TOKEN }} - checkName: ${{ matrix.testMode }} Test Results - coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;' - - uses: actions/upload-artifact@v3 - if: always() - with: - name: Test results for ${{ matrix.testMode }} - path: ${{ steps.tests.outputs.artifactsPath }} - - uses: actions/upload-artifact@v3 - if: always() - with: - name: Coverage results for ${{ matrix.testMode }} - path: ${{ steps.tests.outputs.coveragePath }} - - name: Commit and Push changes - run: | - git diff-index --cached --quiet HEAD || git commit -m 'Auto Commit [skip ci] - - Duplicate Packages Samples - - Publish DLL Dependencies' - git push -f origin HEAD:$branch - env: - branch: ${{ github.head_ref || github.ref_name }} \ No newline at end of file diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 2b669c405..04c9b11bc 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -1,4 +1,4 @@ -name: Duplicate Samples 🪞 +name: Duplicate Samples on: workflow_call: @@ -19,7 +19,7 @@ on: jobs: setup: - name: Duplicate job + name: Duplicate Samples 🪞 uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 with: arguments: "-duplicate_samples ${{ github.event.inputs.arguments || '-git:enabled' }} -c ${{ github.event.inputs.configuration || 'Release' }}" diff --git a/.github/workflows/pull_request_checks.yml b/.github/workflows/pull_request_checks.yml index 6a7966e1b..75eb07663 100644 --- a/.github/workflows/pull_request_checks.yml +++ b/.github/workflows/pull_request_checks.yml @@ -5,16 +5,26 @@ on: jobs: web3_tests: - name: Web3 Tests + name: Web3 tests 🕸 if: ${{ github.event.action == 'ready_for_review' || github.event.label.name == 'ready-to-merge'}} uses: ChainSafe/web3.unity/.github/workflows/test.yaml@main analyze_code: - name: Analyze Code + name: Analyze 🧐 uses: ChainSafe/web3.unity/.github/workflows/codeql.yml@main needs: [ web3_tests ] - unity_tests: - name: Unity Tests + duplicate_samples: + name: Duplicate Samples 🪞 if: ${{ github.base_ref == 'main' }} - uses: ChainSafe/web3.unity/.github/workflows/check_and_commit.yml@main + uses: ChainSafe/web3.unity/.github/workflows/duplicate_samples.yaml@main needs: [ analyze_code ] + secrets: inherit + sync_dependencies: + name: Sync Dependencies 🔄 + uses: ChainSafe/web3.unity/.github/workflows/sync_dependencies.yaml@main + needs: [ duplicate_samples ] + secrets: inherit + unity_tests: + name: Unity Tests 🧪 + uses: ChainSafe/web3.unity/.github/workflows/unity_tests.yml@main + needs: [ sync_dependencies ] secrets: inherit \ No newline at end of file diff --git a/.github/workflows/push_checks.yml b/.github/workflows/push_checks.yml index 5cd430cf3..8ec539366 100644 --- a/.github/workflows/push_checks.yml +++ b/.github/workflows/push_checks.yml @@ -5,7 +5,17 @@ on: branches: [ dev ] jobs: - check_and_commit: - name: Check and Commit - uses: ChainSafe/web3.unity/.github/workflows/check_and_commit.yml@main + duplicate_samples: + name: Duplicate Samples 🪞 + uses: ChainSafe/web3.unity/.github/workflows/duplicate_samples.yaml@main + secrets: inherit + sync_dependencies: + name: Sync Dependencies 🔄 + uses: ChainSafe/web3.unity/.github/workflows/sync_dependencies.yaml@main + needs: [ duplicate_samples ] + secrets: inherit + unity_tests: + name: Unity Tests 🧪 + uses: ChainSafe/web3.unity/.github/workflows/unity_tests.yml@main + needs: [ sync_dependencies ] secrets: inherit \ No newline at end of file diff --git a/.github/workflows/sync_dependencies.yaml b/.github/workflows/sync_dependencies.yaml index 05c280456..d0a8ce4ce 100644 --- a/.github/workflows/sync_dependencies.yaml +++ b/.github/workflows/sync_dependencies.yaml @@ -1,4 +1,4 @@ -name: Sync Dependencies 🔄 +name: Sync Dependencies on: workflow_call: @@ -19,7 +19,7 @@ on: jobs: setup: - name: Sync job + name: Sync Dependencies 🔄 uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 with: arguments: "-sync_dependencies ${{ github.event.inputs.arguments || '-git:enabled' }} -c ${{ github.event.inputs.configuration || 'Release' }}" diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2a4ed695f..d84cd6527 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,7 +5,7 @@ on: jobs: check: - name: Web3 tests job 🕸️ + name: Web3 tests 🕸️ runs-on: ubuntu-latest strategy: matrix: diff --git a/.github/workflows/unity_tests.yml b/.github/workflows/unity_tests.yml new file mode 100644 index 000000000..df205b91c --- /dev/null +++ b/.github/workflows/unity_tests.yml @@ -0,0 +1,58 @@ +name: Unity Tests + +on: + workflow_call: + push: + branches: + - rob/publish-tool-1120 + +jobs: + unity_tests: + name: Unity Tests 🧪 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + projectPath: + - src/UnitySampleProject + testMode: + - PlayMode + steps: + - uses: actions/checkout@v4 + with: + lfs: true + - name: update submodules + run: | + git submodule update --init + shell: bash + - uses: actions/cache@v2 + with: + path: ${{ matrix.projectPath }}/Library + key: Library-${{ matrix.projectPath }} + restore-keys: | + Library- + - uses: game-ci/unity-test-runner@v4 + id: tests + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} + with: + projectPath: ${{ matrix.projectPath }} + testMode: ${{ matrix.testMode }} + scopedRegistryUrl: https://package.openupm.com + registryScopes: 'io.chainsafe.web3-unity, com.nethereum.unity' + artifactsPath: ${{ matrix.testMode }}-artifacts + githubToken: ${{ secrets.GITHUB_TOKEN }} + checkName: ${{ matrix.testMode }} Test Results + coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;' + - uses: actions/upload-artifact@v3 + if: always() + with: + name: Test results for ${{ matrix.testMode }} + path: ${{ steps.tests.outputs.artifactsPath }} + - uses: actions/upload-artifact@v3 + if: always() + with: + name: Coverage results for ${{ matrix.testMode }} + path: ${{ steps.tests.outputs.coveragePath }} \ No newline at end of file diff --git a/src/UnitySampleProject/ProjectSettings/EditorBuildSettings.asset b/src/UnitySampleProject/ProjectSettings/EditorBuildSettings.asset index 93c806863..e7b189653 100644 --- a/src/UnitySampleProject/ProjectSettings/EditorBuildSettings.asset +++ b/src/UnitySampleProject/ProjectSettings/EditorBuildSettings.asset @@ -6,6 +6,6 @@ EditorBuildSettings: serializedVersion: 2 m_Scenes: - enabled: 1 - path: Assets/Samples/web3.unity SDK/3.0.0/Web3.Unity Samples/Scenes/SampleMain.unity + path: Assets/Samples/web3.unity SDK/3.0.1/Web3.Unity Samples/Scenes/SampleMain.unity guid: 516f54f8261cf44459691b7adc25e055 m_configObjects: {} From eaa86887283307918d1739279cb6f3dc8f99e2cb Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 13:36:21 +0300 Subject: [PATCH 52/62] more workflow updates and optimizations --- .github/workflows/duplicate_samples.yaml | 2 +- .../{push_checks.yml => push_checks_dev.yml} | 0 .github/workflows/push_checks_main.yml | 11 +++++++++ .github/workflows/sync_branches.yaml | 23 +++++++++++++++++++ .github/workflows/sync_dependencies.yaml | 2 +- .github/workflows/unity_tests.yml | 4 +--- .../Tests/Runtime/Erc20Tests.cs | 2 +- 7 files changed, 38 insertions(+), 6 deletions(-) rename .github/workflows/{push_checks.yml => push_checks_dev.yml} (100%) create mode 100644 .github/workflows/push_checks_main.yml create mode 100644 .github/workflows/sync_branches.yaml diff --git a/.github/workflows/duplicate_samples.yaml b/.github/workflows/duplicate_samples.yaml index 04c9b11bc..011db5ce7 100644 --- a/.github/workflows/duplicate_samples.yaml +++ b/.github/workflows/duplicate_samples.yaml @@ -20,7 +20,7 @@ on: jobs: setup: name: Duplicate Samples 🪞 - uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 + uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main with: arguments: "-duplicate_samples ${{ github.event.inputs.arguments || '-git:enabled' }} -c ${{ github.event.inputs.configuration || 'Release' }}" secrets: inherit diff --git a/.github/workflows/push_checks.yml b/.github/workflows/push_checks_dev.yml similarity index 100% rename from .github/workflows/push_checks.yml rename to .github/workflows/push_checks_dev.yml diff --git a/.github/workflows/push_checks_main.yml b/.github/workflows/push_checks_main.yml new file mode 100644 index 000000000..a6fe61eb7 --- /dev/null +++ b/.github/workflows/push_checks_main.yml @@ -0,0 +1,11 @@ +name: Post Push Checks + +on: + push: + branches: [ main ] + +jobs: + sync_branches: + name: Sync Branches ♾️ + uses: ChainSafe/web3.unity/.github/workflows/sync_branches.yaml@main + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml new file mode 100644 index 000000000..e68a0f346 --- /dev/null +++ b/.github/workflows/sync_branches.yaml @@ -0,0 +1,23 @@ +name: Duplicate Samples + +on: + workflow_call: + workflow_dispatch: + +jobs: + setup: + name: Sync Branches ♾️ + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref || github.ref_name }} + lfs: true + ssh-key: ${{ secrets.DEPLOY_KEY }} + - name: Sync Branches + run: | + git checkout dev + git merge main + git push + shell: bash \ No newline at end of file diff --git a/.github/workflows/sync_dependencies.yaml b/.github/workflows/sync_dependencies.yaml index d0a8ce4ce..af96dfa70 100644 --- a/.github/workflows/sync_dependencies.yaml +++ b/.github/workflows/sync_dependencies.yaml @@ -20,7 +20,7 @@ on: jobs: setup: name: Sync Dependencies 🔄 - uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@rob/publish-tool-1120 + uses: ChainSafe/web3.unity/.github/workflows/setup.yaml@main with: arguments: "-sync_dependencies ${{ github.event.inputs.arguments || '-git:enabled' }} -c ${{ github.event.inputs.configuration || 'Release' }}" secrets: inherit diff --git a/.github/workflows/unity_tests.yml b/.github/workflows/unity_tests.yml index df205b91c..ac48950fb 100644 --- a/.github/workflows/unity_tests.yml +++ b/.github/workflows/unity_tests.yml @@ -2,9 +2,7 @@ name: Unity Tests on: workflow_call: - push: - branches: - - rob/publish-tool-1120 + workflow_dispatch: jobs: unity_tests: diff --git a/Packages/io.chainsafe.web3-unity/Tests/Runtime/Erc20Tests.cs b/Packages/io.chainsafe.web3-unity/Tests/Runtime/Erc20Tests.cs index 8b70621b0..11e64ba33 100644 --- a/Packages/io.chainsafe.web3-unity/Tests/Runtime/Erc20Tests.cs +++ b/Packages/io.chainsafe.web3-unity/Tests/Runtime/Erc20Tests.cs @@ -39,7 +39,7 @@ public IEnumerator TestNativeBalanceOf() { var getNativeBalanceOf = web3.RpcProvider.GetBalance(Account); yield return new WaitUntil(() => getNativeBalanceOf.IsCompleted); - Assert.AreEqual(new HexBigInteger(510000000000000000), new HexBigInteger(getNativeBalanceOf.Result)); + Assert.AreEqual(new HexBigInteger(0), new HexBigInteger(getNativeBalanceOf.Result)); } [UnityTest] From acac9db24fa77324760f1b9ac269862cb0999c1f Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:08:20 +0300 Subject: [PATCH 53/62] parallel runs (to save time) --- .github/workflows/pull_request_checks.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pull_request_checks.yml b/.github/workflows/pull_request_checks.yml index 75eb07663..056546591 100644 --- a/.github/workflows/pull_request_checks.yml +++ b/.github/workflows/pull_request_checks.yml @@ -11,17 +11,16 @@ jobs: analyze_code: name: Analyze 🧐 uses: ChainSafe/web3.unity/.github/workflows/codeql.yml@main - needs: [ web3_tests ] - duplicate_samples: - name: Duplicate Samples 🪞 - if: ${{ github.base_ref == 'main' }} - uses: ChainSafe/web3.unity/.github/workflows/duplicate_samples.yaml@main - needs: [ analyze_code ] - secrets: inherit sync_dependencies: name: Sync Dependencies 🔄 + if: ${{ github.base_ref == 'main' }} uses: ChainSafe/web3.unity/.github/workflows/sync_dependencies.yaml@main - needs: [ duplicate_samples ] + needs: [ web3_tests , analyze_code ] + secrets: inherit + duplicate_samples: + name: Duplicate Samples 🪞 + uses: ChainSafe/web3.unity/.github/workflows/duplicate_samples.yaml@main + needs: [ sync_dependencies ] secrets: inherit unity_tests: name: Unity Tests 🧪 From 346b5c490b0db4ea5e307e000d70c0cfc2f9884c Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:10:58 +0300 Subject: [PATCH 54/62] test sync branches --- .github/workflows/sync_branches.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml index e68a0f346..b6d04f3b4 100644 --- a/.github/workflows/sync_branches.yaml +++ b/.github/workflows/sync_branches.yaml @@ -3,7 +3,10 @@ name: Duplicate Samples on: workflow_call: workflow_dispatch: - + push: + branches: + - rob/publish-tool-1120 + jobs: setup: name: Sync Branches ♾️ @@ -17,7 +20,6 @@ jobs: ssh-key: ${{ secrets.DEPLOY_KEY }} - name: Sync Branches run: | - git checkout dev git merge main git push shell: bash \ No newline at end of file From 26f6d663b3d64c57538bc2f3b973f8cfe3b53c87 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:13:17 +0300 Subject: [PATCH 55/62] fetch added --- .github/workflows/sync_branches.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml index b6d04f3b4..2bd910db0 100644 --- a/.github/workflows/sync_branches.yaml +++ b/.github/workflows/sync_branches.yaml @@ -20,6 +20,7 @@ jobs: ssh-key: ${{ secrets.DEPLOY_KEY }} - name: Sync Branches run: | + git fetch origin main git merge main git push shell: bash \ No newline at end of file From 933f19721ea88be65ad1113244cb1188386143ca Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:14:18 +0300 Subject: [PATCH 56/62] main renamed --- .github/workflows/sync_branches.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml index 2bd910db0..e14998d07 100644 --- a/.github/workflows/sync_branches.yaml +++ b/.github/workflows/sync_branches.yaml @@ -21,6 +21,6 @@ jobs: - name: Sync Branches run: | git fetch origin main - git merge main + git merge origin/main git push shell: bash \ No newline at end of file From bb3c490b69bf3490c5b1241f7a84cb22f96fb2d4 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:15:31 +0300 Subject: [PATCH 57/62] --allow-unrelated-histories flag added --- .github/workflows/sync_branches.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml index e14998d07..00874d1ea 100644 --- a/.github/workflows/sync_branches.yaml +++ b/.github/workflows/sync_branches.yaml @@ -21,6 +21,6 @@ jobs: - name: Sync Branches run: | git fetch origin main - git merge origin/main + git merge origin/main --allow-unrelated-histories git push shell: bash \ No newline at end of file From 8e27d4dcffc435c9fd9daea13d5815b5c03fadd1 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:19:52 +0300 Subject: [PATCH 58/62] git config added --- .github/workflows/sync_branches.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml index 00874d1ea..a352a764e 100644 --- a/.github/workflows/sync_branches.yaml +++ b/.github/workflows/sync_branches.yaml @@ -20,6 +20,8 @@ jobs: ssh-key: ${{ secrets.DEPLOY_KEY }} - name: Sync Branches run: | + git config --global user.email "rob1997@users.noreply.github.com" + git config --global user.name "rob1997" git fetch origin main git merge origin/main --allow-unrelated-histories git push From 0c1fadd238c94c3eb58ad0fc97a430714a507f8e Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:27:38 +0300 Subject: [PATCH 59/62] sync branches to main workflow --- .github/workflows/push_checks_main.yml | 2 ++ .github/workflows/sync_branches.yaml | 27 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/push_checks_main.yml b/.github/workflows/push_checks_main.yml index a6fe61eb7..f6aebda25 100644 --- a/.github/workflows/push_checks_main.yml +++ b/.github/workflows/push_checks_main.yml @@ -8,4 +8,6 @@ jobs: sync_branches: name: Sync Branches ♾️ uses: ChainSafe/web3.unity/.github/workflows/sync_branches.yaml@main + with: + branch: dev secrets: inherit \ No newline at end of file diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml index a352a764e..08897c156 100644 --- a/.github/workflows/sync_branches.yaml +++ b/.github/workflows/sync_branches.yaml @@ -1,11 +1,17 @@ -name: Duplicate Samples +name: Sync Branches on: workflow_call: + inputs: + branch: + required: true + type: string workflow_dispatch: - push: - branches: - - rob/publish-tool-1120 + inputs: + branch: + required: true + description: "Branch to Sync" + type: string jobs: setup: @@ -20,9 +26,12 @@ jobs: ssh-key: ${{ secrets.DEPLOY_KEY }} - name: Sync Branches run: | - git config --global user.email "rob1997@users.noreply.github.com" - git config --global user.name "rob1997" - git fetch origin main - git merge origin/main --allow-unrelated-histories + git config user.email $git_email + git config user.name $git_actor + git fetch origin ${{ github.event.inputs.branch }} + git merge main --allow-unrelated-histories git push - shell: bash \ No newline at end of file + shell: bash + env: + git_email: "${{ github.actor }}@users.noreply.github.com" + git_actor: "${{ github.actor }}" \ No newline at end of file From 0e6996dc502e1c47c3ff51c47b64ef8d88f6703e Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:39:28 +0300 Subject: [PATCH 60/62] git back to static --- Setup/Git.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/Git.cs b/Setup/Git.cs index 77be8fea5..d8f97a260 100644 --- a/Setup/Git.cs +++ b/Setup/Git.cs @@ -8,7 +8,7 @@ namespace Setup; /// /// Git helper class. /// -public class Git +public static class Git { private static bool _configured; From e930277d235249baae395fe2afd6cdd0ed3e5adb Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 14:40:32 +0300 Subject: [PATCH 61/62] reverted sample duplicate test --- .../3.0.1/Marketplace Samples/MudSample.cs | 117 ++++++++++++++++++ .../Marketplace Samples/MudSample.cs.meta | 11 ++ .../Scripts/MarketplaceSample.cs | 1 - 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs create mode 100644 src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta diff --git a/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs b/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs new file mode 100644 index 000000000..aadb7b4b7 --- /dev/null +++ b/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; +using ChainSafe.Gaming.Debugging; +using ChainSafe.Gaming.EVM.Events; +using ChainSafe.Gaming.Evm.JsonRpc; +using ChainSafe.Gaming.Mud; +using ChainSafe.Gaming.Mud.Tables; +using ChainSafe.Gaming.Mud.Unity; +using ChainSafe.Gaming.Mud.Worlds; +using ChainSafe.Gaming.RPC.Events; +using ChainSafe.Gaming.UnityPackage; +using ChainSafe.Gaming.Wallets; +using ChainSafe.Gaming.Web3; +using ChainSafe.Gaming.Web3.Build; +using ChainSafe.Gaming.Web3.Unity; +using TMPro; +using UnityEngine; + +public class MudSample : MonoBehaviour +{ + public MudConfigAsset mudConfig; + public string worldContractAddress; + public TextAsset worldContractAbi; + public TMP_Text counterLabel; + + private Web3 web3; + private MudWorld world; + + private async void Awake() + { + Debug.Log("To run this sample successfully you should have the MUD tutorial project running in the background.\n" + + "Follow the link to get started: https://mud.dev/quickstart"); + + // 1. Initialize Web3 client. + web3 = await new Web3Builder(ProjectConfigUtilities.Load(), ProjectConfigUtilities.BuildLocalhostConfig()) + .Configure(services => + { + // Enable basic components + services.UseUnityEnvironment(); + services.UseRpcProvider(); + + // Initializes Wallet as the first account of the locally running Ethereum Node (Anvil). + services.Debug().UseJsonRpcWallet(new JsonRpcWalletConfig { AccountIndex = 0 }); + + // Enable Events as MUD requires them + services.UseEvents(new PollingEventManagerConfig { PollInterval = TimeSpan.FromSeconds(1) }); // the config is only being used for WebGL platform; 1 second poll interval is extremely fast, consider using longer interval in production so that your RPC endpoint doesn't get too overwhelmed + + // Enable MUD + services.UseMud(mudConfig); + }) + .LaunchAsync(); + Debug.Log($"Web3 client ready. Player address: {web3.Signer.PublicAddress}"); + + // 2. Create MUD World client. + world = await web3.Mud().BuildWorld(new MudWorldConfig + { + ContractAddress = worldContractAddress, + ContractAbi = worldContractAbi.text, + DefaultNamespace = "app", + TableSchemas = new List + { + new() + { + Namespace = "app", + TableName = "Counter", + Columns = new List> + { + new("value", "uint32"), + }, + KeyColumns = new string[0], // empty key schema - singleton table (one record only) + }, + }, + }); + Debug.Log("MUD World client ready"); + + // 3. Get Table client. + var table = world.GetTable("Counter"); + + // 4. Query counter value + var allRecords = await table.Query(MudQuery.All); // Query all records of the Counter table + var singleRecord = allRecords.Single(); // Get single record + var counterValue = (BigInteger)singleRecord[0]; // Get value of the first column + Debug.Log($"Counter value on load: {counterValue}"); + UpdateGui(counterValue); + + // 5. Subscribe to table updates. + table.RecordUpdated += OnCounterRecordUpdated; + } + + public async void IncrementCounter() + { + if (web3 is null) + { + Debug.LogError("Can't run sample. Web3 client was not initialized."); + return; + } + + // 5. Send transaction to execute the Increment function of the World contract. + Debug.Log("Sending transaction to execute the Increment function.."); + await world.GetSystems().Send("increment"); + Debug.Log($"Increment successful"); + } + + private void OnCounterRecordUpdated(object[] key, object[] record) + { + var counterValue = (BigInteger)record[0]; + Debug.Log($"Counter value updated: {counterValue}"); + UpdateGui(counterValue); + } + + private void UpdateGui(BigInteger counterValue) + { + counterLabel.text = counterValue.ToString("d"); + } +} diff --git a/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta b/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta new file mode 100644 index 000000000..392f646f6 --- /dev/null +++ b/src/UnitySampleProject/Assets/Samples/web3.unity SDK MUD/3.0.1/Marketplace Samples/MudSample.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0784d678e93c29d44b5621a24b931617 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs b/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs index fb7d293ef..298ad6aaf 100644 --- a/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs +++ b/src/UnitySampleProject/Assets/Samples/web3.unity SDK Marketplace/3.0.1/Marketplace Samples/Scripts/MarketplaceSample.cs @@ -8,7 +8,6 @@ namespace ChainSafe.Gaming.Marketplace.Samples { - // More tests public class MarketplaceSample : MonoBehaviour { [SerializeField] private Transform parentForItems; From 883c41eb7927dce7c5e56f5f56154a9c9143e988 Mon Sep 17 00:00:00 2001 From: rob1997 Date: Mon, 21 Oct 2024 15:02:34 +0300 Subject: [PATCH 62/62] parallel run to save some time --- .github/workflows/push_checks_dev.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/push_checks_dev.yml b/.github/workflows/push_checks_dev.yml index 8ec539366..0362af54e 100644 --- a/.github/workflows/push_checks_dev.yml +++ b/.github/workflows/push_checks_dev.yml @@ -5,14 +5,14 @@ on: branches: [ dev ] jobs: - duplicate_samples: - name: Duplicate Samples 🪞 - uses: ChainSafe/web3.unity/.github/workflows/duplicate_samples.yaml@main - secrets: inherit sync_dependencies: name: Sync Dependencies 🔄 uses: ChainSafe/web3.unity/.github/workflows/sync_dependencies.yaml@main - needs: [ duplicate_samples ] + secrets: inherit + duplicate_samples: + name: Duplicate Samples 🪞 + uses: ChainSafe/web3.unity/.github/workflows/duplicate_samples.yaml@main + needs: [ sync_dependencies ] secrets: inherit unity_tests: name: Unity Tests 🧪