Skip to content

Commit

Permalink
try out matrix with env var
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed May 13, 2024
1 parent dee33ea commit 6fec4aa
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 17 deletions.
28 changes: 24 additions & 4 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Build/Consts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 34 additions & 0 deletions Build/Http.cs
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 10 in Build/Http.cs

View workflow job for this annotation

GitHub Actions / build (DUI3-DX\Connectors\Revit\Speckle.Connectors.Revit2023\Speckle.Connectors.Revit2023.csproj)

The type name Http conflicts in whole or in part with the namespace name 'System.Net.Http'. Change either name to eliminate the conflict. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1724)

Check warning on line 10 in Build/Http.cs

View workflow job for this annotation

GitHub Actions / build (DUI3-DX\Connectors\Revit\Speckle.Connectors.ArcGIS3\Speckle.Connectors.Revit2023.csproj)

The type name Http conflicts in whole or in part with the namespace name 'System.Net.Http'. Change either name to eliminate the conflict. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1724)
{
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);
}
}
}
45 changes: 32 additions & 13 deletions Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string> GetDirectories(string d)
Expand Down Expand Up @@ -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");
}
);

Expand All @@ -78,16 +87,26 @@ IEnumerable<string> 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;

Check warning on line 106 in Build/Program.cs

View workflow job for this annotation

GitHub Actions / build (DUI3-DX\Connectors\Revit\Speckle.Connectors.Revit2023\Speckle.Connectors.Revit2023.csproj)

Consider calling ConfigureAwait on the awaited task (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2007)

Check warning on line 106 in Build/Program.cs

View workflow job for this annotation

GitHub Actions / build (DUI3-DX\Connectors\Revit\Speckle.Connectors.ArcGIS3\Speckle.Connectors.Revit2023.csproj)

Consider calling ConfigureAwait on the awaited task (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2007)
}
);

Target("default", DependsOn(ZIP), () => Console.WriteLine("Done!"));

await RunTargetsAndExitAsync(args).ConfigureAwait(true);

0 comments on commit 6fec4aa

Please sign in to comment.