diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 367bca4fb5..ae74d40218 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -10,6 +10,12 @@ on: jobs: build: runs-on: windows-latest + strategy: + matrix: + paths: [ + "DUI3-DX\\Connectors\\Revit\\Speckle.Connectors.Revit2023\\Speckle.Connectors.Revit2023.csproj", + "DUI3-DX\\Connectors\\Revit\\Speckle.Connectors.ArcGIS3\\Speckle.Connectors.Revit2023.csproj" + ] steps: - name: Checkout uses: actions/checkout@v4 @@ -25,17 +31,31 @@ jobs: path: ~/.nuget/packages key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 + - name: Format + run: dotnet run --project Build/Build.csproj -- format + - name: Clean + env: + TARGET_PATH: ${{ matrix.paths }} + run: dotnet run --project Build/Build.csproj -- clean + - name: Restore + env: + TARGET_PATH: ${{ matrix.paths }} run: dotnet run --project Build/Build.csproj -- restore + - name: Add msbuild to PATH + uses: microsoft/setup-msbuild@v2 + - name: Build + env: + TARGET_PATH: ${{ matrix.paths }} run: dotnet run --project Build/Build.csproj -- build - - name: Pack - run: dotnet run --project Build/Build.csproj -- pack + - name: Pack + env: + TARGET_PATH: ${{ matrix.paths }} + run: dotnet run --project Build/Build.csproj -- zip - name: Upload artifacts uses: actions/upload-artifact@v4 diff --git a/Build/Consts.cs b/Build/Consts.cs index 7f45c91005..a2cc7f68ff 100644 --- a/Build/Consts.cs +++ b/Build/Consts.cs @@ -3,6 +3,7 @@ public static class Consts { public static readonly string[] Solutions = { "DUI3-DX.slnf" }; + public static readonly string[] Frameworks = { "net48" }; public static readonly (string, string)[] Projects = { ("DUI3-DX\\Connectors\\Revit\\Speckle.Connectors.Revit2023", "net48") diff --git a/Build/Http.cs b/Build/Http.cs new file mode 100644 index 0000000000..fa1b5b1d43 --- /dev/null +++ b/Build/Http.cs @@ -0,0 +1,34 @@ +using System; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Mime; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Build; + +public static class Http +{ + public static async Task TriggerWorkflow(string secret, string artifactId) + { + using var client = new HttpClient(); + var payload = new { event_type = "trigger-workflow", client_payload = new { artifact_id = artifactId } }; + var content = new StringContent( + JsonSerializer.Serialize(payload), + new MediaTypeHeaderValue(MediaTypeNames.Application.Json) + ); + + var request = new HttpRequestMessage() + { + RequestUri = new Uri("https://api.github.com/repos/specklesystems/connector-installers/dispatches"), + Headers = { Authorization = new AuthenticationHeaderValue($"Bearer {secret}") }, + Content = content + }; + request.Headers.Add("X-GitHub-Api-Version", "2022-11-28"); + var response = await client.SendAsync(request).ConfigureAwait(false); + if (!response.IsSuccessStatusCode) + { + throw new InvalidOperationException(response.StatusCode + response.ReasonPhrase); + } + } +} diff --git a/Build/Program.cs b/Build/Program.cs index b185980791..79ebf40b3f 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; +using System.Threading.Tasks; using Build; using GlobExpressions; using static Bullseye.Targets; @@ -12,11 +13,12 @@ const string BUILD = "build"; const string TEST = "test"; const string FORMAT = "format"; -const string PACK = "pack"; +const string ZIP = "zip"; +const string TRIGGER_WORKFLOW = "trigger-workflow"; Target( CLEAN, - ForEach("**/bin", "**/obj"), + ForEach("**/output"), dir => { IEnumerable GetDirectories(string d) @@ -48,15 +50,22 @@ void RemoveDirectory(string d) Run("dotnet", "csharpier --check ."); } ); -Target(RESTORE, DependsOn(FORMAT), Consts.Solutions, s => Run("dotnet", $"dotnet restore --locked-mode {s}")); +Target( + RESTORE, + DependsOn(FORMAT), + () => + { + var path = Environment.GetEnvironmentVariable("TARGET_PATH"); + Run("dotnet", $"dotnet restore --locked-mode {path}"); + } +); Target( BUILD, - Consts.Solutions, - s => + () => { - //Run("dotnet", $"build {s} -c Release --no-restore"); - Run("msbuild", $"{s} /p:Configuration=Release /p:IsDesktopBuild=false /p:NuGetRestorePackages=false -v:m"); + var path = Environment.GetEnvironmentVariable("TARGET_PATH"); + Run("msbuild", $"{path} /p:Configuration=Release /p:IsDesktopBuild=false /p:NuGetRestorePackages=false -v:m"); } ); @@ -78,16 +87,26 @@ IEnumerable GetFiles(string d) ); Target( - PACK, - Consts.Projects, - x => + ZIP, + Consts.Frameworks, + framework => { - var fullPath = Path.Combine(Consts.Root, x.Item1, "bin", "Release", x.Item2); - var outputPath = Path.Combine(Consts.Root, "output", $"{new DirectoryInfo(x.Item1).Name}.zip"); + var path = Environment.GetEnvironmentVariable("TARGET_PATH"); + var fullPath = Path.Combine(".", path, "bin", "Release", framework); + var outputPath = Path.Combine(".", "output", $"{new DirectoryInfo(path).Name}.zip"); + Console.WriteLine($"Zipping: '{fullPath}' to '{outputPath}'"); ZipFile.CreateFromDirectory(fullPath, outputPath); } ); -Target("default", DependsOn(PACK), () => Console.WriteLine("Done!")); +Target( + TRIGGER_WORKFLOW, + async () => + { + await Task.CompletedTask; + } +); + +Target("default", DependsOn(ZIP), () => Console.WriteLine("Done!")); await RunTargetsAndExitAsync(args).ConfigureAwait(true);