forked from gitter-badger/IdentityServer4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update to new build script * fixup! update to new build script
- Loading branch information
Showing
8 changed files
with
69 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,110 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using McMaster.Extensions.CommandLineUtils; | ||
using static Bullseye.Targets; | ||
using static SimpleExec.Command; | ||
|
||
namespace build | ||
{ | ||
partial class Program | ||
{ | ||
private const bool RequireTests = false; | ||
private const string packOutput = "./artifacts"; | ||
private const string packOutputCopy = "../../nuget"; | ||
private const string envVarMissing = " environment variable is missing. Aborting."; | ||
|
||
private static class Targets | ||
{ | ||
public const string CleanBuildOutput = "clean-build-output"; | ||
public const string CleanPackOutput = "clean-pack-output"; | ||
public const string Build = "build"; | ||
public const string Test = "test"; | ||
public const string Pack = "pack"; | ||
public const string SignBinary = "sign-binary"; | ||
public const string SignPackage = "sign-package"; | ||
public const string CopyPackOutput = "copy-pack-output"; | ||
} | ||
|
||
private const string ArtifactsDir = "artifacts"; | ||
private const string Build = "build"; | ||
private const string Test = "test"; | ||
private const string Pack = "pack"; | ||
|
||
static void Main(string[] args) | ||
{ | ||
var app = new CommandLineApplication | ||
Target(Targets.CleanBuildOutput, () => | ||
{ | ||
UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.StopParsingAndCollect | ||
}; | ||
Run("dotnet", "clean -c Release -v m --nologo", echoPrefix: Prefix); | ||
}); | ||
|
||
var sign = app.Option<(bool hasValue, int theValue)>("--sign", "Sign binaries and nuget package", CommandOptionType.SingleOrNoValue); | ||
Target(Targets.Build, DependsOn(Targets.CleanBuildOutput), () => | ||
{ | ||
Run("dotnet", "build -c Release --nologo", echoPrefix: Prefix); | ||
}); | ||
|
||
Target(Targets.SignBinary, DependsOn(Targets.Build), () => | ||
{ | ||
Sign("./src/bin/Release", "*.dll"); | ||
}); | ||
|
||
CleanArtifacts(); | ||
Target(Targets.Test, DependsOn(Targets.Build), () => | ||
{ | ||
Run("dotnet", $"test -c Release --no-build", echoPrefix: Prefix); | ||
}); | ||
|
||
app.OnExecute(() => | ||
Target(Targets.CleanPackOutput, () => | ||
{ | ||
Target(Build, () => | ||
if (Directory.Exists(packOutput)) | ||
{ | ||
Run("dotnet", $"build -c Release", echoPrefix: Prefix); | ||
Directory.Delete(packOutput, true); | ||
} | ||
}); | ||
|
||
if (sign.HasValue()) | ||
{ | ||
Sign("*.dll", "./src/bin/release"); | ||
} | ||
}); | ||
Target(Targets.Pack, DependsOn(Targets.Build, Targets.CleanPackOutput), () => | ||
{ | ||
var project = Directory.GetFiles("./src", "*.csproj", SearchOption.TopDirectoryOnly).OrderBy(_ => _).First(); | ||
|
||
Target(Test, DependsOn(Build), () => | ||
{ | ||
Run("dotnet", $"test -c Release --no-build", echoPrefix: Prefix); | ||
|
||
}); | ||
|
||
Target(Pack, DependsOn(Build), () => | ||
{ | ||
var project = Directory.GetFiles("./src", "*.csproj", SearchOption.TopDirectoryOnly).OrderBy(_ => _).First(); | ||
Run("dotnet", $"pack {project} -c Release -o {Directory.CreateDirectory(packOutput).FullName} --no-build --nologo", echoPrefix: Prefix); | ||
}); | ||
|
||
Run("dotnet", $"pack {project} -c Release -o ./{ArtifactsDir} --no-build", echoPrefix: Prefix); | ||
|
||
if (sign.HasValue()) | ||
{ | ||
Sign("*.nupkg", $"./{ArtifactsDir}"); | ||
} | ||
Target(Targets.SignPackage, DependsOn(Targets.Pack), () => | ||
{ | ||
Sign(packOutput, "*.nupkg"); | ||
}); | ||
|
||
CopyArtifacts(); | ||
}); | ||
Target(Targets.CopyPackOutput, DependsOn(Targets.Pack), () => | ||
{ | ||
Directory.CreateDirectory(packOutputCopy); | ||
|
||
Target("quick", () => | ||
foreach (var file in Directory.GetFiles(packOutput)) | ||
{ | ||
var project = Directory.GetFiles("./src", "*.csproj", SearchOption.TopDirectoryOnly).OrderBy(_ => _).First(); | ||
File.Copy(file, Path.Combine(packOutputCopy, Path.GetFileName(file)), true); | ||
} | ||
}); | ||
|
||
Run("dotnet", $"pack {project} -c Release -o ./{ArtifactsDir}", echoPrefix: Prefix); | ||
|
||
CopyArtifacts(); | ||
}); | ||
Target("quick", DependsOn(Targets.CopyPackOutput)); | ||
|
||
Target("default", DependsOn(Targets.Test, Targets.CopyPackOutput)); | ||
|
||
Target("default", DependsOn(Test, Pack)); | ||
RunTargetsAndExit(app.RemainingArguments, logPrefix: Prefix); | ||
}); | ||
Target("sign", DependsOn(Targets.SignBinary, Targets.Test, Targets.SignPackage, Targets.CopyPackOutput)); | ||
|
||
app.Execute(args); | ||
RunTargetsAndExit(args, ex => ex is SimpleExec.NonZeroExitCodeException || ex.Message.EndsWith(envVarMissing), Prefix); | ||
} | ||
|
||
private static void Sign(string extension, string directory) | ||
private static void Sign(string path, string searchTerm) | ||
{ | ||
var signClientConfig = Environment.GetEnvironmentVariable("SignClientConfig"); | ||
var signClientSecret = Environment.GetEnvironmentVariable("SignClientSecret"); | ||
|
||
if (string.IsNullOrWhiteSpace(signClientConfig)) | ||
{ | ||
throw new Exception("SignClientConfig environment variable is missing. Aborting."); | ||
throw new Exception($"SignClientConfig{envVarMissing}"); | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(signClientSecret)) | ||
{ | ||
throw new Exception("SignClientSecret environment variable is missing. Aborting."); | ||
throw new Exception($"SignClientSecret{envVarMissing}"); | ||
} | ||
|
||
var files = Directory.GetFiles(directory, extension, SearchOption.AllDirectories); | ||
if (files.Count() == 0) | ||
foreach (var file in Directory.GetFiles(path, searchTerm, SearchOption.AllDirectories)) | ||
{ | ||
throw new Exception($"File to sign not found: {extension}"); | ||
} | ||
|
||
foreach (var file in files) | ||
{ | ||
Console.WriteLine(" Signing " + file); | ||
Console.WriteLine($" Signing {file}"); | ||
Run("dotnet", $"SignClient sign -c {signClientConfig} -i {file} -r [email protected] -s \"{signClientSecret}\" -n 'IdentityServer4'", noEcho: true); | ||
} | ||
} | ||
|
||
private static void CopyArtifacts() | ||
{ | ||
var files = Directory.GetFiles($"./{ArtifactsDir}"); | ||
|
||
foreach (string s in files) | ||
{ | ||
var fileName = Path.GetFileName(s); | ||
var destFile = Path.Combine("../../nuget", fileName); | ||
File.Copy(s, destFile, true); | ||
} | ||
} | ||
|
||
private static void CleanArtifacts() | ||
{ | ||
Directory.CreateDirectory($"./{ArtifactsDir}"); | ||
|
||
foreach (var file in Directory.GetFiles($"./{ArtifactsDir}")) | ||
{ | ||
File.Delete(file); | ||
} | ||
} | ||
} | ||
} | ||
} |