-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
identity-server - simplify build process by building from solution
- Loading branch information
1 parent
251a73d
commit 5a0cb2f
Showing
6 changed files
with
73 additions
and
199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,29 +5,27 @@ | |
using static GitHubContexts; | ||
|
||
var contexts = Instance; | ||
Component[] components = [ | ||
new("identity-server", | ||
["AspNetIdentity", "Configuration", "Configuration.EntityFramework", "EntityFramework", "EntityFramework.Storage", "IdentityServer", "Storage"], | ||
["Configuration.IntegrationTests", "EntityFramework.IntegrationTests", "EntityFramework.Storage.IntegrationTests", "EntityFramework.Storage.UnitTests", "IdentityServer.IntegrationTests", "IdentityServer.UnitTests"], | ||
"is") | ||
]; | ||
|
||
foreach (var component in components) | ||
|
||
{ | ||
SystemDescription identityServer = new("identity-server", "Duende.IdentityServer.sln", "is"); | ||
GenerateIdentityServerWorkflow(identityServer); | ||
GenerateIdentityServerReleaseWorkflow(identityServer); | ||
} | ||
|
||
{ | ||
GenerateCiWorkflow(component); | ||
GenerateReleaseWorkflow(component); | ||
SystemDescription bff = new("bff", "bff.sln", "bff"); | ||
GenerateBffWorkflow(bff); | ||
GenerateBffReleaseWorkflow(bff); | ||
} | ||
|
||
GenerateBffWorkflow(); | ||
GenerateBffReleaseWorkflow(); | ||
|
||
void GenerateCiWorkflow(Component component) | ||
void GenerateIdentityServerWorkflow(SystemDescription system) | ||
{ | ||
var workflow = new Workflow($"{component.Name}/ci"); | ||
var paths = new[] | ||
var workflow = new Workflow($"{system.Name}/ci"); | ||
var paths = new[] | ||
{ | ||
$".github/workflows/{component.Name}-**", | ||
$"{component.Name}/**", | ||
$".github/workflows/{system.Name}-**", | ||
$"{system.Name}/**", | ||
"Directory.Packages.props" | ||
}; | ||
|
||
|
@@ -47,13 +45,13 @@ void GenerateCiWorkflow(Component component) | |
.RunEitherOnBranchOrAsPR() | ||
.Name("Build") | ||
.RunsOn(GitHubHostedRunners.UbuntuLatest) | ||
.Defaults().Run("bash", component.Name) | ||
.Defaults().Run("bash", system.Name) | ||
.Job; | ||
|
||
job.Permissions( | ||
actions: Permission.Read, | ||
contents: Permission.Read, | ||
checks: Permission.Write, | ||
checks: Permission.Write, | ||
packages: Permission.Write); | ||
|
||
job.TimeoutMinutes(15); | ||
|
@@ -63,73 +61,65 @@ void GenerateCiWorkflow(Component component) | |
|
||
job.StepSetupDotNet(); | ||
|
||
foreach (var testProject in component.Tests) | ||
{ | ||
job.StepTestAndReport(component.Name, testProject); | ||
} | ||
job.StepBuild(system.Solution); | ||
|
||
job.StepTest(system.Solution); | ||
|
||
job.StepToolRestore(); | ||
|
||
foreach (var project in component.Projects) | ||
{ | ||
job.StepPackProject(project); | ||
} | ||
job.StepPackSolution(system.Solution); | ||
|
||
job.StepSign(); | ||
|
||
job.StepPushToMyGet(); | ||
|
||
job.StepPushToGithub(contexts); | ||
|
||
job.StepUploadArtifacts(component.Name); | ||
job.StepUploadArtifacts(system.Name); | ||
|
||
var fileName = $"{component.Name}-ci"; | ||
var fileName = $"{system.Name}-ci"; | ||
WriteWorkflow(workflow, fileName); | ||
} | ||
|
||
void GenerateReleaseWorkflow(Component component) | ||
void GenerateIdentityServerReleaseWorkflow(SystemDescription system) | ||
{ | ||
var workflow = new Workflow($"{component.Name}/release"); | ||
var workflow = new Workflow($"{system.Name}/release"); | ||
|
||
workflow.On | ||
.WorkflowDispatch() | ||
.Inputs(new StringInput("version", "Version in format X.Y.Z or X.Y.Z-preview.", true, "0.0.0")); | ||
|
||
workflow.EnvDefaults(); | ||
|
||
var tagJob = workflow | ||
var job = workflow | ||
.Job("tag") | ||
.Name("Tag and Pack") | ||
.RunsOn(GitHubHostedRunners.UbuntuLatest) | ||
.Permissions(contents: Permission.Write, packages: Permission.Write) | ||
.Defaults().Run("bash", component.Name).Job; | ||
.Defaults().Run("bash", system.Name).Job; | ||
|
||
tagJob.Step() | ||
job.Step() | ||
.ActionsCheckout(); | ||
|
||
tagJob.StepSetupDotNet(); | ||
job.StepSetupDotNet(); | ||
|
||
tagJob.Step() | ||
job.Step() | ||
.Name("Git tag") | ||
.Run($@"git config --global user.email ""[email protected]"" | ||
git config --global user.name ""Duende Software GitHub Bot"" | ||
git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}"" | ||
git push origin {component.TagPrefix}-{contexts.Event.Input.Version}"); | ||
git tag -a {system.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}"" | ||
git push origin {system.TagPrefix}-{contexts.Event.Input.Version}"); | ||
|
||
foreach (var project in component.Projects) | ||
{ | ||
tagJob.StepPackProject(project); | ||
} | ||
job.StepPackSolution(system.Solution); | ||
|
||
tagJob.StepToolRestore(); | ||
job.StepToolRestore(); | ||
|
||
tagJob.StepSign(); | ||
job.StepSign(); | ||
|
||
tagJob.StepPushToMyGet(); | ||
job.StepPushToMyGet(); | ||
|
||
tagJob.StepPushToGithub(contexts); | ||
job.StepPushToGithub(contexts); | ||
|
||
tagJob.StepUploadArtifacts(component.Name); | ||
job.StepUploadArtifacts(system.Name); | ||
|
||
var publishJob = workflow.Job("publish") | ||
.Name("Publish to nuget.org") | ||
|
@@ -150,21 +140,17 @@ git tag -a {component.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{c | |
|
||
publishJob.StepPushToNuget(); | ||
|
||
var fileName = $"{component.Name}-release"; | ||
var fileName = $"{system.Name}-release"; | ||
WriteWorkflow(workflow, fileName); | ||
} | ||
|
||
|
||
void GenerateBffWorkflow() | ||
void GenerateBffWorkflow(SystemDescription system) | ||
{ | ||
const string name = "bff"; | ||
const string solution = name + ".sln"; | ||
|
||
var workflow = new Workflow($"{name}/ci"); | ||
var workflow = new Workflow($"{system.Name}/ci"); | ||
var paths = new[] | ||
{ | ||
$".github/workflows/{name}-**", | ||
$"{name}/**", | ||
$".github/workflows/{system.Name}-**", | ||
$"{system.Name}/**", | ||
"Directory.Packages.props" | ||
}; | ||
|
||
|
@@ -184,7 +170,7 @@ void GenerateBffWorkflow() | |
.RunEitherOnBranchOrAsPR() | ||
.Name("Build") | ||
.RunsOn(GitHubHostedRunners.UbuntuLatest) | ||
.Defaults().Run("bash", name) | ||
.Defaults().Run("bash", system.Name) | ||
.Job; | ||
|
||
job.Permissions( | ||
|
@@ -200,36 +186,31 @@ void GenerateBffWorkflow() | |
|
||
job.StepSetupDotNet(); | ||
|
||
job.StepBuild(solution); | ||
job.StepBuild(system.Solution); | ||
|
||
// Devcerts are needed because some tests run start an a http server with https. | ||
job.StepDotNetDevCerts(); | ||
|
||
job.StepTest(solution); | ||
job.StepTest(system.Solution); | ||
|
||
job.StepToolRestore(); | ||
|
||
job.StepPackSolution(solution); | ||
job.StepPackSolution(system.Solution); | ||
|
||
job.StepSign(); | ||
|
||
job.StepPushToMyGet(); | ||
|
||
job.StepPushToGithub(contexts); | ||
|
||
job.StepUploadArtifacts(name); | ||
job.StepUploadArtifacts(system.Name); | ||
|
||
var fileName = $"{name}-ci"; | ||
var fileName = $"{system.Name}-ci"; | ||
WriteWorkflow(workflow, fileName); | ||
} | ||
|
||
|
||
void GenerateBffReleaseWorkflow() | ||
void GenerateBffReleaseWorkflow(SystemDescription system) | ||
{ | ||
const string name = "bff"; | ||
const string solution = name + ".sln"; | ||
const string tagPrefix = "bff"; | ||
var workflow = new Workflow($"{name}/release"); | ||
var workflow = new Workflow($"{system.Name}/release"); | ||
|
||
workflow.On | ||
.WorkflowDispatch() | ||
|
@@ -242,7 +223,7 @@ void GenerateBffReleaseWorkflow() | |
.Name("Tag and Pack") | ||
.RunsOn(GitHubHostedRunners.UbuntuLatest) | ||
.Permissions(contents: Permission.Write, packages: Permission.Write) | ||
.Defaults().Run("bash", name).Job; | ||
.Defaults().Run("bash", system.Name).Job; | ||
|
||
job.Step() | ||
.ActionsCheckout(); | ||
|
@@ -253,10 +234,10 @@ void GenerateBffReleaseWorkflow() | |
.Name("Git tag") | ||
.Run($@"git config --global user.email ""[email protected]"" | ||
git config --global user.name ""Duende Software GitHub Bot"" | ||
git tag -a {tagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}"" | ||
git push origin {tagPrefix}-{contexts.Event.Input.Version}"); | ||
git tag -a {system.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}"" | ||
git push origin {system.TagPrefix}-{contexts.Event.Input.Version}"); | ||
|
||
job.StepPackSolution(solution); | ||
job.StepPackSolution(system.Solution); | ||
|
||
job.StepToolRestore(); | ||
|
||
|
@@ -266,7 +247,7 @@ git tag -a {tagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Ev | |
|
||
job.StepPushToGithub(contexts); | ||
|
||
job.StepUploadArtifacts(name); | ||
job.StepUploadArtifacts(system.Name); | ||
|
||
var publishJob = workflow.Job("publish") | ||
.Name("Publish to nuget.org") | ||
|
@@ -287,7 +268,7 @@ git tag -a {tagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Ev | |
|
||
publishJob.StepPushToNuget(); | ||
|
||
var fileName = $"{name}-release"; | ||
var fileName = $"{system.Name}-release"; | ||
WriteWorkflow(workflow, fileName); | ||
} | ||
|
||
|
@@ -299,7 +280,7 @@ void WriteWorkflow(Workflow workflow, string fileName) | |
Console.WriteLine($"Wrote workflow to {filePath}"); | ||
} | ||
|
||
record Component(string Name, string[] Projects, string[] Tests, string TagPrefix); | ||
record SystemDescription(string Name, string Solution, string TagPrefix); | ||
|
||
public static class StepExtensions | ||
{ | ||
|
@@ -326,29 +307,6 @@ public static Step IfRefMain(this Step step) | |
public static Step IfGithubEventIsPush(this Step step) | ||
=> step.If("github.event == 'push'"); | ||
|
||
public static void StepTestAndReport(this Job job, string componentName, string testProject) | ||
{ | ||
var path = $"test/{testProject}"; | ||
var logFileName = "Tests.trx"; | ||
var flags = $"--logger \"console;verbosity=normal\" " + | ||
$"--logger \"trx;LogFileName={logFileName}\" " + | ||
$"--collect:\"XPlat Code Coverage\""; | ||
job.Step() | ||
.Name($"Test - {testProject}") | ||
.Run($"dotnet test -c Release {path} {flags}"); | ||
|
||
job.Step() | ||
.Name($"Test report - {testProject}") | ||
.Uses("dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5") // v1.9.1 | ||
.If("success() || failure()") | ||
.With( | ||
("name", $"Test Report - {testProject}"), | ||
("path", $"{componentName}/{path}/TestResults/{logFileName}"), | ||
("reporter", "dotnet-trx"), | ||
("fail-on-error", "true"), | ||
("fail-on-empty", "true")); | ||
} | ||
|
||
public static void StepDotNetDevCerts(this Job job) | ||
=> job.Step() | ||
.Name("Dotnet devcerts") | ||
|
@@ -366,14 +324,6 @@ public static void StepPackSolution(this Job job, string solution) | |
.Run($"dotnet pack -c Release {solution} -o artifacts"); | ||
} | ||
|
||
public static void StepPackProject(this Job job, string project) | ||
{ | ||
var path = $"src/{project}"; | ||
job.Step() | ||
.Name($"Pack {project}") | ||
.Run($"dotnet pack -c Release {path} -o artifacts"); | ||
} | ||
|
||
public static Step StepBuild(this Job job, string solution) | ||
=> job.Step() | ||
.Name("Build") | ||
|
Oops, something went wrong.