Skip to content

Commit 8a6bd7e

Browse files
authored
update to new build script (#134)
1 parent 5d7d3fb commit 8a6bd7e

File tree

4 files changed

+57
-68
lines changed

4 files changed

+57
-68
lines changed

build.cmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
@echo off
2-
dotnet tool restore
3-
4-
dotnet run --project build -- %*
2+
dotnet run --project build -- %*

build.ps1

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
$ErrorActionPreference = "Stop";
2-
dotnet tool restore
3-
4-
dotnet run --project build -- $args
2+
dotnet run --project build -- $args

build.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
dotnet tool restore
4-
5-
dotnet run --project build -- "$@"
3+
dotnet run --project build -- "$@"

build/Program.cs

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,99 @@
11
using System;
22
using System.IO;
3-
using System.Linq;
4-
using McMaster.Extensions.CommandLineUtils;
53
using static Bullseye.Targets;
64
using static SimpleExec.Command;
75

86
namespace build
97
{
10-
class Program
8+
internal static class Program
119
{
10+
private const string packOutput = "./artifacts";
11+
private const string envVarMissing = " environment variable is missing. Aborting.";
12+
1213
private static class Targets
1314
{
15+
public const string RestoreTools = "restore-tools";
16+
public const string CleanBuildOutput = "clean-build-output";
17+
public const string CleanPackOutput = "clean-pack-output";
1418
public const string Build = "build";
1519
public const string Test = "test";
1620
public const string Pack = "pack";
21+
public const string SignBinary = "sign-binary";
22+
public const string SignPackage = "sign-package";
1723
}
1824

19-
static string BinaryToSign = "IdentityServer4.AccessTokenValidation.dll";
20-
21-
22-
static void Main(string[] args)
25+
internal static void Main(string[] args)
2326
{
24-
var app = new CommandLineApplication(throwOnUnexpectedArg: false);
25-
var sign = app.Option<(bool hasValue, int theValue)>("--sign", "Sign binaries and nuget package", CommandOptionType.SingleOrNoValue);
27+
Target(Targets.RestoreTools, () =>
28+
{
29+
Run("dotnet", "tool restore");
30+
});
2631

27-
CleanArtifacts();
32+
Target(Targets.CleanBuildOutput, () =>
33+
{
34+
Run("dotnet", "clean -c Release -v m --nologo");
35+
});
2836

29-
app.OnExecute(() =>
37+
Target(Targets.Build, DependsOn(Targets.CleanBuildOutput), () =>
3038
{
31-
Target(Targets.Build, () =>
32-
{
33-
Run("dotnet", $"build -c Release");
39+
Run("dotnet", "build -c Release --nologo");
40+
});
3441

35-
if (sign.HasValue())
36-
{
37-
Sign(BinaryToSign, "./src/bin/release");
38-
}
39-
});
42+
Target(Targets.SignBinary, DependsOn(Targets.Build, Targets.RestoreTools), () =>
43+
{
44+
Sign("./src/bin/Release", "IdentityServer4.AccessTokenValidation.dll");
45+
});
4046

41-
Target(Targets.Test, DependsOn(Targets.Build), () =>
42-
{
43-
Run("dotnet", $"test -c Release --no-build");
44-
});
45-
46-
Target(Targets.Pack, DependsOn(Targets.Test), () =>
47-
{
48-
var project = Directory.GetFiles("./src", "*.csproj", SearchOption.TopDirectoryOnly).First();
47+
Target(Targets.Test, DependsOn(Targets.Build), () =>
48+
{
49+
Run("dotnet", "test -c Release --no-build --nologo");
50+
});
4951

50-
Run("dotnet", $"pack {project} -c Release -o ./artifacts --no-build");
51-
52-
if (sign.HasValue())
53-
{
54-
Sign("*.nupkg", $"./artifacts");
55-
}
56-
});
52+
Target(Targets.CleanPackOutput, () =>
53+
{
54+
if (Directory.Exists(packOutput))
55+
{
56+
Directory.Delete(packOutput, true);
57+
}
58+
});
5759

60+
Target(Targets.Pack, DependsOn(Targets.Build, Targets.CleanPackOutput), () =>
61+
{
62+
Run("dotnet", $"pack ./src/IdentityServer4.AccessTokenValidation.csproj -c Release -o {Directory.CreateDirectory(packOutput).FullName} --no-build --nologo");
63+
});
5864

59-
Target("default", DependsOn(Targets.Test, Targets.Pack));
60-
RunTargetsAndExit(app.RemainingArguments);
65+
Target(Targets.SignPackage, DependsOn(Targets.Pack, Targets.RestoreTools), () =>
66+
{
67+
Sign(packOutput, "*.nupkg");
6168
});
6269

63-
app.Execute(args);
70+
Target("default", DependsOn(Targets.Test, Targets.Pack));
71+
72+
Target("sign", DependsOn(Targets.SignBinary, Targets.Test, Targets.SignPackage));
73+
74+
RunTargetsAndExit(args, ex => ex is SimpleExec.NonZeroExitCodeException || ex.Message.EndsWith(envVarMissing));
6475
}
6576

66-
private static void Sign(string extension, string directory)
77+
private static void Sign(string path, string searchTerm)
6778
{
6879
var signClientConfig = Environment.GetEnvironmentVariable("SignClientConfig");
6980
var signClientSecret = Environment.GetEnvironmentVariable("SignClientSecret");
7081

7182
if (string.IsNullOrWhiteSpace(signClientConfig))
7283
{
73-
throw new Exception("SignClientConfig environment variable is missing. Aborting.");
84+
throw new Exception($"SignClientConfig{envVarMissing}");
7485
}
7586

7687
if (string.IsNullOrWhiteSpace(signClientSecret))
7788
{
78-
throw new Exception("SignClientSecret environment variable is missing. Aborting.");
89+
throw new Exception($"SignClientSecret{envVarMissing}");
7990
}
8091

81-
var files = Directory.GetFiles(directory, extension, SearchOption.AllDirectories);
82-
if (files.Count() == 0)
92+
foreach (var file in Directory.GetFiles(path, searchTerm, SearchOption.AllDirectories))
8393
{
84-
throw new Exception($"File to sign not found: {extension}");
85-
}
86-
87-
foreach (var file in files)
88-
{
89-
Console.WriteLine(" Signing " + file);
94+
Console.WriteLine($" Signing {file}");
9095
Run("dotnet", $"SignClient sign -c {signClientConfig} -i {file} -r [email protected] -s \"{signClientSecret}\" -n 'IdentityServer4'", noEcho: true);
9196
}
9297
}
93-
94-
private static void CleanArtifacts()
95-
{
96-
Directory.CreateDirectory($"./artifacts");
97-
98-
foreach (var file in Directory.GetFiles($"./artifacts"))
99-
{
100-
File.Delete(file);
101-
}
102-
}
10398
}
104-
}
99+
}

0 commit comments

Comments
 (0)