Skip to content

Commit

Permalink
Merge pull request #1 from gsoft-inc/feature/strong-naming
Browse files Browse the repository at this point in the history
Assemblies are now signed and added Cake as build tool
  • Loading branch information
asimmon authored May 10, 2022
2 parents 3fc8ca9 + 4ebde03 commit 9c1bce0
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 85 deletions.
66 changes: 28 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,37 @@ name: CI build

on:
push:
branches: [ master, develop ]
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.x

- name: Setup .NET 6.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x

- name: Restore dependencies
working-directory: ./src
run: dotnet restore

- name: Build
working-directory: ./src
run: dotnet build -c Release --no-restore

- name: List NuGet packages
working-directory: ./src
run: find . \( -name "*.nupkg" -o -name "*.snupkg" \) -type f

- name: Upload NuGet packages
uses: actions/upload-artifact@v3
with:
name: nuget-packages
path: |
./src/GSoft.Extensions.Configuration.Substitution/bin/Release/*.nupkg
./src/GSoft.Extensions.Configuration.Substitution/bin/Release/*.snupkg
- name: Test
working-directory: ./src
run: dotnet test -c Release --no-build --verbosity normal
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.x

- name: Setup .NET 6.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x

- name: Cake build
run: chmod +x ./build.sh && ./build.sh --target=Pack
shell: bash

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: ./.output/**/*
64 changes: 26 additions & 38 deletions .github/workflows/nuget-push.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
name: NuGet push

on:
workflow_dispatch:
push:
tags:
- "*.*.*"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.x

- name: Setup .NET 6.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x

- name: Remove outdated Nuget packages
working-directory: ./src
run: find . \( -name "*.nupkg" -o -name "*.snupkg" \) -type f -delete

- name: Restore dependencies
working-directory: ./src
run: dotnet restore

- name: Build
working-directory: ./src
run: dotnet build -c Release --no-restore

- name: Test
working-directory: ./src
run: dotnet test -c Release --no-build --verbosity normal

- name: Rename NuGet packages
working-directory: ./src/GSoft.Extensions.Configuration.Substitution/bin/Release
run: mv *.nupkg GSoft.Extensions.Configuration.Substitution.nupkg && mv *.snupkg GSoft.Extensions.Configuration.Substitution.snupkg

- name: Push NuGet packages
working-directory: ./src/GSoft.Extensions.Configuration.Substitution/bin/Release
run: dotnet nuget push GSoft.Extensions.Configuration.Substitution.nupkg --api-key ${{ secrets.nuget_api_key }} --source https://api.nuget.org/v3/index.json
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.x

- name: Setup .NET 6.0
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x

- name: Cake build
run: chmod +x ./build.sh && ./build.sh --target=Push --nuget-api-key=${{ secrets.nuget_api_key }} --nuget-source=${{ secrets.nuget_source }}
shell: bash

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: ./.output/**/*
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,8 @@ FodyWeavers.xsd
Desktop.ini
ehthumbs.db
Thumbs.db
$RECYCLE.BIN/
$RECYCLE.BIN/

# Cake
build/tools/**
!build/tools/packages.config
2 changes: 2 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dotnet run --project build/Build.csproj -- $args
exit $LASTEXITCODE;
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet run --project ./build/Build.csproj -- "$@"
14 changes: 14 additions & 0 deletions build/Build.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Frosting" Version="2.2.0" />
</ItemGroup>
</Project>
180 changes: 180 additions & 0 deletions build/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using System;
using System.IO;
using Cake.Common;
using Cake.Common.IO;
using Cake.Common.Tools.DotNet;
using Cake.Common.Tools.DotNet.Build;
using Cake.Common.Tools.DotNet.MSBuild;
using Cake.Common.Tools.DotNet.NuGet.Push;
using Cake.Common.Tools.DotNet.Pack;
using Cake.Common.Tools.DotNet.Restore;
using Cake.Common.Tools.DotNet.Test;
using Cake.Common.Tools.GitVersion;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Frosting;

return new CakeHost()
.InstallTool(new Uri("dotnet:?package=GitVersion.Tool&version=5.10.1"))
.UseContext<BuildContext>()
.Run(args);

public static class Constants
{
public const string Release = "Release";
public const string ProjectName = "GSoft.Extensions.Configuration.Substitution";

public static readonly string SourceDirectoryPath = Path.Combine("..", "src");
public static readonly string OutputDirectoryPath = Path.Combine("..", ".output");
public static readonly string SolutionPath = Path.Combine(SourceDirectoryPath, ProjectName + ".sln");
public static readonly string MainProjectPath = Path.Combine(SourceDirectoryPath, ProjectName, ProjectName + ".csproj");
}

public class BuildContext : FrostingContext
{
public BuildContext(ICakeContext context) : base(context)
{
this.NugetApiKey = context.Argument("nuget-api-key", string.Empty);
this.NugetSource = context.Argument("nuget-source", string.Empty);
}

public DotNetMSBuildSettings MSBuildSettings { get; } = new DotNetMSBuildSettings();

public string NugetApiKey { get; }

public string NugetSource { get; }

public void AddMSBuildSetting(string name, string value, bool log = false)
{
if (log)
{
this.Log.Information(name + ": " + value);
}

if (!string.IsNullOrWhiteSpace(value))
{
this.MSBuildSettings.Properties[name] = new[] { value };
}
}
}

[TaskName("Clean")]
public sealed class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var objGlobPath = Path.Combine(Constants.SourceDirectoryPath, "*", "obj");
var binGlobPath = Path.Combine(Constants.SourceDirectoryPath, "*", "bin");

context.CleanDirectories(Constants.OutputDirectoryPath);
context.CleanDirectories(objGlobPath);
context.CleanDirectories(binGlobPath);
}
}

[TaskName("GitVersion")]
public sealed class GitVersionTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var gitVersion = context.GitVersion();

context.AddMSBuildSetting("Version", gitVersion.NuGetVersion, log: true);
context.AddMSBuildSetting("VersionPrefix", gitVersion.MajorMinorPatch, log: true);
context.AddMSBuildSetting("VersionSuffix", gitVersion.PreReleaseTag, log: true);
context.AddMSBuildSetting("PackageVersion", gitVersion.FullSemVer, log: true);
context.AddMSBuildSetting("InformationalVersion", gitVersion.InformationalVersion, log: true);
context.AddMSBuildSetting("AssemblyVersion", gitVersion.AssemblySemVer, log: true);
context.AddMSBuildSetting("FileVersion", gitVersion.AssemblySemFileVer, log: true);
context.AddMSBuildSetting("RepositoryBranch", gitVersion.BranchName, log: true);
context.AddMSBuildSetting("RepositoryCommit", gitVersion.Sha, log: true);
}
}

[TaskName("Restore")]
[IsDependentOn(typeof(CleanTask))]
[IsDependentOn(typeof(GitVersionTask))]
public sealed class RestoreTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context) => context.DotNetRestore(Constants.SolutionPath, new DotNetRestoreSettings
{
MSBuildSettings = context.MSBuildSettings,
});
}

[TaskName("Build")]
[IsDependentOn(typeof(RestoreTask))]
public sealed class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
context.AddMSBuildSetting("Deterministic", "true");
context.AddMSBuildSetting("ContinuousIntegrationBuild", "true");

context.DotNetBuild(Constants.SolutionPath, new DotNetBuildSettings
{
Configuration = Constants.Release,
MSBuildSettings = context.MSBuildSettings,
NoRestore = true,
NoLogo = true,
});
}
}

[TaskName("Test")]
[IsDependentOn(typeof(BuildTask))]
public sealed class TestTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
foreach (var testProjectFilePath in context.GetFiles(Path.Combine(Constants.SourceDirectoryPath, "*", "*.Tests.csproj")))
{
context.DotNetTest(testProjectFilePath.FullPath, new DotNetTestSettings
{
Configuration = Constants.Release,
Loggers = new[] { "console;verbosity=detailed" },
NoBuild = true,
NoLogo = true,
});
}
}
}

[TaskName("Pack")]
[IsDependentOn(typeof(TestTask))]
public sealed class PackTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context) => context.DotNetPack(Constants.MainProjectPath, new DotNetPackSettings
{
Configuration = Constants.Release,
MSBuildSettings = context.MSBuildSettings,
OutputDirectory = Constants.OutputDirectoryPath,
NoBuild = true,
NoRestore = true,
NoLogo = true,
});
}

[TaskName("Push")]
[IsDependentOn(typeof(PackTask))]
public sealed class PushTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
foreach (var packageFilePath in context.GetFiles(Path.Combine(Constants.OutputDirectoryPath, "*.nupkg")))
{
context.DotNetNuGetPush(packageFilePath, new DotNetNuGetPushSettings
{
ApiKey = context.NugetApiKey,
Source = context.NugetSource,
IgnoreSymbols = false
});
}
}
}

[TaskName("Default")]
[IsDependentOn(typeof(PackTask))]
public sealed class DefaultTask : FrostingTask
{
}
Binary file added src/GSoft.Extensions.Configuration.Substitution.snk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<AssemblyTitle>GSoft.Extensions.Configuration.Substitution</AssemblyTitle>
<PackageId>GSoft.Extensions.Configuration.Substitution</PackageId>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../GSoft.Extensions.Configuration.Substitution.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitVersion.MsBuild" Version="5.9.0">
<PrivateAssets>All</PrivateAssets>
</PackageReference>

<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.0" />
</ItemGroup>
</Project>

0 comments on commit 9c1bce0

Please sign in to comment.