Skip to content

Commit

Permalink
setup build
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwinvandervalk committed Feb 13, 2025
1 parent 2b7ce7e commit bb83972
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 163 deletions.
90 changes: 82 additions & 8 deletions .github/workflow-gen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
SystemDescription identityServer = new("identity-server", "identity-server.slnf", "is");
GenerateIdentityServerWorkflow(identityServer);
GenerateIdentityServerReleaseWorkflow(identityServer);

GenerateTemplatesReleaseWorkflow(identityServer);

}

{
SystemDescription bff = new("bff", "bff.slnf", "bff");
GenerateBffWorkflow(bff);
GenerateBffReleaseWorkflow(bff);

GenerateTemplatesReleaseWorkflow(bff);
}


Expand Down Expand Up @@ -67,7 +72,9 @@ void GenerateIdentityServerWorkflow(SystemDescription system)

job.StepToolRestore();

job.StepPackSolution(system.Solution);
job.StepPack(system.Solution);

job.StepPack(system.TemplateProject);

job.StepSign();

Expand Down Expand Up @@ -109,7 +116,7 @@ git config --global user.name ""Duende Software GitHub Bot""
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(system.Solution);
job.StepPack(system.Solution);

job.StepToolRestore();

Expand Down Expand Up @@ -197,7 +204,7 @@ void GenerateBffWorkflow(SystemDescription system)

job.StepToolRestore();

job.StepPackSolution(system.Solution);
job.StepPack(system.Solution);

job.StepSign();

Expand Down Expand Up @@ -239,7 +246,8 @@ git config --global user.name ""Duende Software GitHub Bot""
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(system.Solution);
job.StepPack(system.Solution);
job.StepPack(system.TemplateProject);

job.StepToolRestore();

Expand Down Expand Up @@ -274,6 +282,69 @@ git tag -a {system.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{cont
WriteWorkflow(workflow, fileName);
}

void GenerateTemplatesReleaseWorkflow(SystemDescription system)
{
var workflow = new Workflow($"{system.Name}/templates/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 job = workflow
.Job("tag")
.Name("Tag and Pack")
.RunsOn(GitHubHostedRunners.UbuntuLatest)
.Permissions(contents: Permission.Write, packages: Permission.Write)
.Defaults().Run("bash", system.Name).Job;

job.Step()
.ActionsCheckout();

job.StepSetupDotNet();

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 templates-{system.TagPrefix}-{contexts.Event.Input.Version} -m ""Release v{contexts.Event.Input.Version}""
git push origin templates-{system.TagPrefix}-{contexts.Event.Input.Version}");

job.StepPack(system.TemplateProject);

job.StepToolRestore();

job.StepSign();

job.StepPushToMyGet();

job.StepPushToGithub(contexts);

job.StepUploadArtifacts(system.Name);

var publishJob = workflow.Job("publish")
.Name("Publish to nuget.org")
.RunsOn(GitHubHostedRunners.UbuntuLatest)
.Needs("tag")
.Environment("nuget.org", "");

publishJob.Step()
.Uses("actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16") // 4.1.8
.With(("name", "artifacts"), ("path", "artifacts"));

publishJob.StepSetupDotNet();

publishJob.Step()
.Name("List files")
.Shell("bash")
.Run("tree");

publishJob.StepPushToNuget();

var fileName = $"{system.Name}-templates-release";
WriteWorkflow(workflow, fileName);
}

void WriteWorkflow(Workflow workflow, string fileName)
{
Expand All @@ -282,7 +353,10 @@ void WriteWorkflow(Workflow workflow, string fileName)
Console.WriteLine($"Wrote workflow to {filePath}");
}

record SystemDescription(string Name, string Solution, string TagPrefix);
record SystemDescription(string Name, string Solution, string TagPrefix)
{
public string TemplateProject => $"{Name}/templates/templates.{Name}.csproj";
}

public static class StepExtensions
{
Expand Down Expand Up @@ -323,11 +397,11 @@ public static void StepToolRestore(this Job job)
.Name("Tool restore")
.Run("dotnet tool restore");

public static void StepPackSolution(this Job job, string solution)
public static void StepPack(this Job job, string target)
{
job.Step()
.Name($"Pack {solution}")
.Run($"dotnet pack -c Release {solution} -o artifacts");
.Name($"Pack {target}")
.Run($"dotnet pack -c Release {target} -o artifacts");
}

public static Step StepBuild(this Job job, string solution)
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/bff-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
git push origin bff-${{ github.event.inputs.version }}
- name: Pack bff.slnf
run: dotnet pack -c Release bff.slnf -o artifacts
- name: Pack bff/templates/templates.bff.csproj
run: dotnet pack -c Release bff/templates/templates.bff.csproj -o artifacts
- name: Tool restore
run: dotnet tool restore
- name: Sign packages
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/bff-templates-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# This was generated by tool. Edits will be overwritten.

name: bff/templates/release
on:
workflow_dispatch:
inputs:
version:
description: 'Version in format X.Y.Z or X.Y.Z-preview.'
type: string
required: true
default: '0.0.0'
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
tag:
name: Tag and Pack
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
defaults:
run:
shell: bash
working-directory: bff
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Dotnet
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25
with:
dotnet-version: |-
6.0.x
8.0.x
9.0.x
- name: Git tag
run: |-
git config --global user.email "[email protected]"
git config --global user.name "Duende Software GitHub Bot"
git tag -a templates-bff-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin templates-bff-${{ github.event.inputs.version }}
- name: Pack bff/templates/templates.bff.csproj
run: dotnet pack -c Release bff/templates/templates.bff.csproj -o artifacts
- name: Tool restore
run: dotnet tool restore
- name: Sign packages
if: github.event == 'push'
run: |-
for file in artifacts/*.nupkg; do
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.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 ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
done
- name: Push packages to MyGet
if: github.ref == 'refs/heads/main'
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
- name: Push packages to GitHub
if: github.ref == 'refs/heads/main'
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Artifacts
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: artifacts
path: bff/artifacts/*.nupkg
overwrite: true
retention-days: 15
publish:
name: Publish to nuget.org
needs:
- tag
runs-on: ubuntu-latest
environment:
name: nuget.org
steps:
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: artifacts
path: artifacts
- name: Setup Dotnet
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25
with:
dotnet-version: |-
6.0.x
8.0.x
9.0.x
- name: List files
run: tree
shell: bash
- name: Push packages to nuget.org
if: github.ref == 'refs/heads/main'
run: dotnet nuget push artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} --skip-duplicate
2 changes: 2 additions & 0 deletions .github/workflows/identity-server-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ jobs:
run: dotnet tool restore
- name: Pack identity-server.slnf
run: dotnet pack -c Release identity-server.slnf -o artifacts
- name: Pack identity-server/templates/templates.identity-server.csproj
run: dotnet pack -c Release identity-server/templates/templates.identity-server.csproj -o artifacts
- name: Sign packages
if: github.event == 'push'
run: |-
Expand Down
95 changes: 95 additions & 0 deletions .github/workflows/identity-server-templates-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# This was generated by tool. Edits will be overwritten.

name: identity-server/templates/release
on:
workflow_dispatch:
inputs:
version:
description: 'Version in format X.Y.Z or X.Y.Z-preview.'
type: string
required: true
default: '0.0.0'
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
tag:
name: Tag and Pack
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
defaults:
run:
shell: bash
working-directory: identity-server
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Dotnet
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25
with:
dotnet-version: |-
6.0.x
8.0.x
9.0.x
- name: Git tag
run: |-
git config --global user.email "[email protected]"
git config --global user.name "Duende Software GitHub Bot"
git tag -a templates-is-${{ github.event.inputs.version }} -m "Release v${{ github.event.inputs.version }}"
git push origin templates-is-${{ github.event.inputs.version }}
- name: Pack identity-server/templates/templates.identity-server.csproj
run: dotnet pack -c Release identity-server/templates/templates.identity-server.csproj -o artifacts
- name: Tool restore
run: dotnet tool restore
- name: Sign packages
if: github.event == 'push'
run: |-
for file in artifacts/*.nupkg; do
dotnet NuGetKeyVaultSignTool sign "$file" --file-digest sha256 --timestamp-rfc3161 http://timestamp.digicert.com --azure-key-vault-url https://duendecodesigninghsm.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 ${{ secrets.SignClientSecret }} --azure-key-vault-certificate NuGetPackageSigning
done
- name: Push packages to MyGet
if: github.ref == 'refs/heads/main'
run: dotnet nuget push artifacts/*.nupkg --source https://www.myget.org/F/duende_identityserver/api/v2/package --api-key ${{ secrets.MYGET }} --skip-duplicate
- name: Push packages to GitHub
if: github.ref == 'refs/heads/main'
run: dotnet nuget push artifacts/*.nupkg --source https://nuget.pkg.github.com/DuendeSoftware/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Artifacts
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: artifacts
path: identity-server/artifacts/*.nupkg
overwrite: true
retention-days: 15
publish:
name: Publish to nuget.org
needs:
- tag
runs-on: ubuntu-latest
environment:
name: nuget.org
steps:
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: artifacts
path: artifacts
- name: Setup Dotnet
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25
with:
dotnet-version: |-
6.0.x
8.0.x
9.0.x
- name: List files
run: tree
shell: bash
- name: Push packages to nuget.org
if: github.ref == 'refs/heads/main'
run: dotnet nuget push artifacts/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_ORG_API_KEY }} --skip-duplicate
1 change: 0 additions & 1 deletion bff/bff.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"bff\\src\\Bff.EntityFramework\\Bff.EntityFramework.csproj",
"bff\\src\\Bff.Yarp\\Bff.Yarp.csproj",
"bff\\src\\Bff\\Bff.csproj",
"bff\\templates\\templates.bff.csproj",
"bff\\templates\\templates\\BffLocalApi\\BffLocalApi.csproj",
"bff\\templates\\templates\\BffRemoteApi\\BffRemoteApi.csproj",
"bff\\test\\Bff.Blazor.Client.UnitTests\\Bff.Blazor.Client.UnitTests.csproj",
Expand Down
Loading

0 comments on commit bb83972

Please sign in to comment.