This repository was archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathProgram.cs
127 lines (105 loc) · 4.59 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.IO;
using static Bullseye.Targets;
using static SimpleExec.Command;
namespace build
{
internal static class Program
{
private const string NugetPackageVersion = "7.0.4";
private const string packOutput = "./artifacts";
private const string envVarMissing = " environment variable is missing. Aborting.";
private static class Targets
{
public const string CleanPackOutput = "clean-pack-output";
public const string Copy = "copy";
public const string Build = "build";
public const string Pack = "pack";
public const string SignPackage = "sign-package";
}
internal static void Main(string[] args)
{
Target(Targets.Build, () =>
{
Run("dotnet", $"build -c Release --nologo");
});
Target(Targets.CleanPackOutput, () =>
{
if (Directory.Exists(packOutput))
{
Directory.Delete(packOutput, true);
}
});
Target(Targets.Copy, () =>
{
DirectoryCopy("./src", "./feed/content", true);
DirectoryCopy("./ui", "./feed/content/ui", true);
});
Target(Targets.Pack, DependsOn(Targets.Copy, Targets.CleanPackOutput), () =>
{
var directory = Directory.CreateDirectory(packOutput).FullName;
Run("./tools/nuget.exe", $"pack ./feed/Duende.IdentityServer.Templates.nuspec -OutputDirectory {directory} -Version {NugetPackageVersion}");
});
Target(Targets.SignPackage, DependsOn(Targets.Pack), () =>
{
SignNuGet();
});
Target("default", DependsOn(Targets.Build));
Target("sign", DependsOn(Targets.SignPackage));
RunTargetsAndExit(args, ex => ex is SimpleExec.NonZeroExitCodeException || ex.Message.EndsWith(envVarMissing));
}
private static void SignNuGet()
{
var signClientSecret = Environment.GetEnvironmentVariable("SignClientSecret");
if (string.IsNullOrWhiteSpace(signClientSecret))
{
throw new Exception($"SignClientSecret{envVarMissing}");
}
foreach (var file in Directory.GetFiles(packOutput, "*.nupkg", SearchOption.AllDirectories))
{
Console.WriteLine($" Signing {file}");
Run("dotnet",
"NuGetKeyVaultSignTool " +
$"sign {file} " +
"--file-digest sha256 " +
"--timestamp-rfc3161 http://timestamp.digicert.com " +
"--azure-key-vault-url https://duendecodesigning.vault.azure.net/ " +
"--azure-key-vault-client-id 18e3de68-2556-4345-8076-a46fad79e474 " +
"--azure-key-vault-tenant-id ed3089f0-5401-4758-90eb-066124e2d907 " +
$"--azure-key-vault-client-secret {signClientSecret} " +
"--azure-key-vault-certificate CodeSigning"
,noEcho: true);
}
}
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}
DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
Directory.CreateDirectory(destDirName);
// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string tempPath = Path.Combine(destDirName, file.Name);
file.CopyTo(tempPath, true);
}
// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string tempPath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, tempPath, copySubDirs);
}
}
}
}
}