Skip to content

Commit cdd5a91

Browse files
authored
Code Signing (#553)
* Start of Code Signing * Remove Ultz.Native from the filelist
1 parent 588eaa4 commit cdd5a91

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
- name: Setup NUKE
2020
run: dotnet tool install Nuke.GlobalTool --global
2121
- name: Push to NuGet
22-
run: nuke PushToNuGet --configuration Release --msbuild-properties ContinuousIntegrationBuild=true SilkEnableSourceLink=true --feature-sets Android iOS --nuget-api-key ${{ secrets.NUGET_TOKEN }}
22+
run: nuke PushToNuGet --configuration Release --msbuild-properties ContinuousIntegrationBuild=true SilkEnableSourceLink=true --feature-sets Android iOS --nuget-api-key ${{ secrets.NUGET_TOKEN }} --sign-username "${{ secrets.SIGN_USERNAME }}" --sign-password "${{ secrets.SIGN_PASSWORD }}"

build/codesigning/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tool/

build/codesigning/config.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"SignClient": {
3+
"AzureAd": {
4+
"AADInstance": "https://login.microsoftonline.com/",
5+
"ClientId": "c248d68a-ba6f-4aa9-8a68-71fe872063f8",
6+
"TenantId": "16076fdc-fcc1-4a15-b1ca-32c9a255900e"
7+
},
8+
"Service": {
9+
"Url": "https://codesign.dotnetfoundation.org/",
10+
"ResourceId": "https://SignService/3c30251f-36f3-490b-a955-520addb85001"
11+
}
12+
}
13+
}

build/codesigning/filelist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/Silk.NET*

build/nuke/Build.cs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
1515
using static Nuke.Common.Tools.DotNet.DotNetTasks;
1616
using static Nuke.Common.IO.FileSystemTasks;
17+
using static Nuke.Common.Tooling.ProcessTasks;
1718

1819
[CheckBuildProjectConfigurations]
1920
[UnsetVisualStudioEnvironmentVariables]
@@ -77,6 +78,8 @@ bool HasDesktopMsBuild
7778
[Parameter("NuGet feed")] readonly string NugetFeed = "https://api.nuget.org/v3/index.json";
7879
[Parameter("NuGet username")] readonly string NugetUsername;
7980
[Parameter("NuGet password")] readonly string NugetPassword;
81+
[Parameter("Code-signing service username")] readonly string SignUsername;
82+
[Parameter("Code-signing service password")] readonly string SignPassword;
8083
[Parameter("Extra properties passed to MSBuild commands")]
8184
readonly string[] MsbuildProperties = Array.Empty<string>();
8285

@@ -223,8 +226,8 @@ Dictionary<string, object> ProcessedMsbuildProperties
223226
{
224227
var silkDroid = SourceDirectory / "Windowing" / "Android" / "SilkDroid";
225228
using var process = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
226-
? ProcessTasks.StartProcess("bash", "-c \"./gradlew clean\"", silkDroid)
227-
: ProcessTasks.StartProcess("cmd", "/c \".\\gradlew clean\"", silkDroid);
229+
? StartProcess("bash", "-c \"./gradlew clean\"", silkDroid)
230+
: StartProcess("cmd", "/c \".\\gradlew clean\"", silkDroid);
228231
process.AssertZeroExitCode();
229232
return process.Output;
230233
}
@@ -365,8 +368,8 @@ Dictionary<string, object> ProcessedMsbuildProperties
365368
}
366369

367370
using var process = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
368-
? ProcessTasks.StartProcess("bash", "-c \"./gradlew build\"", silkDroid)
369-
: ProcessTasks.StartProcess("cmd", "/c \".\\gradlew build\"", silkDroid);
371+
? StartProcess("bash", "-c \"./gradlew build\"", silkDroid)
372+
: StartProcess("cmd", "/c \".\\gradlew build\"", silkDroid);
370373
process.AssertZeroExitCode();
371374
var ret = process.Output;
372375
CopyFile
@@ -417,19 +420,46 @@ Dictionary<string, object> ProcessedMsbuildProperties
417420
Target FullPack => _ => _
418421
.DependsOn(BuildLibSilkDroid, RegenerateBindings, Pack);
419422

420-
Target PushToNuGet => _ => _
423+
Target PushToNuGet => _ => _
421424
.DependsOn(Pack)
422425
.Executes(PushPackages);
423426

424427
Target FullPushToNuGet => _ => _
425428
.DependsOn(FullPack, PushToNuGet);
426429

430+
static string PackageDirectory => RootDirectory / "build" / "output_packages";
431+
static IEnumerable<string> Packages => Directory.GetFiles(PackageDirectory, "*.nupkg")
432+
.Where(x => Path.GetFileName(x).StartsWith("Silk.NET") || Path.GetFileName(x).StartsWith("Ultz.Native"));
433+
427434
async Task PushPackages()
428435
{
429436
const int rateLimit = 300;
430-
var allFiles = Directory.GetFiles(RootDirectory / "build" / "output_packages", "*.nupkg")
431-
.Where(x => Path.GetFileName(x).StartsWith("Silk.NET") || Path.GetFileName(x).StartsWith("Ultz.Native"))
432-
.Select((x, i) => new {Index = i, Value = x})
437+
if (!string.IsNullOrWhiteSpace(SignUsername) && !string.IsNullOrWhiteSpace(SignPassword))
438+
{
439+
var basePath = RootDirectory / "build" / "codesigning";
440+
var execPath = basePath / "tool" / (OperatingSystem.IsWindows() ? "SignClient.exe" : "SignClient");
441+
if (!File.Exists(execPath))
442+
{
443+
DotNetToolInstall(s => s.SetToolInstallationPath(basePath / "tool").SetPackageName("SignClient"));
444+
}
445+
446+
StartProcess
447+
(
448+
execPath,
449+
"sign " +
450+
$"--baseDirectory {PackageDirectory} " +
451+
"--input \"**/*.nupkg\" " +
452+
$"--config \"{basePath / "config.json"}\" " +
453+
$"--filelist \"{basePath / "filelist.txt"}\" " +
454+
$"--user \"{SignUsername}\" " +
455+
$"--secret \"{SignPassword}\" " +
456+
"--name \"Silk.NET\" " +
457+
"--description \"Silk.NET\" " +
458+
"--descriptionUrl \"https://github.com/dotnet/Silk.NET\""
459+
).AssertZeroExitCode();
460+
}
461+
462+
var allFiles = Packages.Select((x, i) => new {Index = i, Value = x})
433463
.GroupBy(x => x.Index / rateLimit)
434464
.Select(x => x.Select(v => v.Value).ToList())
435465
.ToList();

0 commit comments

Comments
 (0)