Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump Nuke/GitVersion, improve PR numbering, simplify Yaml script #1775

Merged
merged 3 commits into from Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 13 additions & 18 deletions .github/workflows/build.yml
Expand Up @@ -2,10 +2,10 @@ name: build

on:
pull_request:
paths-ignore:
paths-ignore:
- docs/**
push:
paths-ignore:
paths-ignore:
- docs/**

jobs:
Expand All @@ -17,37 +17,32 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup .NET 5
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

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

- name: Setup .NET 2.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x

- name: Install NUKE
run: |
dotnet tool install --global Nuke.GlobalTool


- name: Run NUKE
run: nuke
run: ./build.ps1
env:
BranchSpec: ${{ github.ref }}
BuildNumber: ${{ github.run_number}}
ApiKey: ${{ secrets.NUGETAPIKEY }}

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
path: ./Artifacts/*

- name: Push to Nuget
run: dotnet nuget push .\artifacts\*.nupkg --api-key "$env:ApiKey" --skip-duplicate --no-symbols true --source https://api.nuget.org/v3/index.json
if: contains(github.ref, 'refs/tags/')
env:
ApiKey: ${{ secrets.NUGETAPIKEY }}



16 changes: 16 additions & 0 deletions .nuke/build.schema.json
Expand Up @@ -6,6 +6,18 @@
"build": {
"type": "object",
"properties": {
"ApiKey": {
"type": "string",
"description": "The key to push to Nuget"
},
"BranchSpec": {
"type": "string",
"description": "A branch specification such as develop or refs/pull/1775/merge"
},
"BuildNumber": {
"type": "string",
"description": "An incrementing build number as provided by the build engine"
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
Expand Down Expand Up @@ -64,9 +76,11 @@
"type": "string",
"enum": [
"ApiChecks",
"CalculateNugetVersion",
"Clean",
"Compile",
"Pack",
"Push",
"Restore",
"TestFrameworks",
"UnitTests"
Expand All @@ -84,9 +98,11 @@
"type": "string",
"enum": [
"ApiChecks",
"CalculateNugetVersion",
"Clean",
"Compile",
"Pack",
"Push",
"Restore",
"TestFrameworks",
"UnitTests"
Expand Down
7 changes: 5 additions & 2 deletions Build/.editorconfig
Expand Up @@ -9,5 +9,8 @@ csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_accessors = true:warning

dotnet_diagnostic.IDE0044.severity = none
dotnet_diagnostic.IDE0051.severity = none
dotnet_diagnostic.ide0044.severity = none
dotnet_diagnostic.ide0051.severity = none

# ReSharper properties
resharper_place_field_attribute_on_same_line = false
83 changes: 74 additions & 9 deletions Build/Build.cs
@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Nuke.Common;
using Nuke.Common.Execution;
Expand All @@ -24,20 +26,54 @@ class Build : NukeBuild
- Microsoft VSCode https://nuke.build/vscode
*/

public static int Main() => Execute<Build>(x => x.Pack);
public static int Main() => Execute<Build>(x => x.Push);

[Solution(GenerateProjects = true)] readonly Solution Solution;
[GitVersion(Framework = "net5.0")] readonly GitVersion GitVersion;
[PackageExecutable("nspec", "NSpecRunner.exe", Version = "3.1.0")] Tool NSpec3;
[Parameter("A branch specification such as develop or refs/pull/1775/merge")]
readonly string BranchSpec;

[Parameter("An incrementing build number as provided by the build engine")]
readonly string BuildNumber;

[Parameter("The key to push to Nuget")]
readonly string ApiKey;

[Solution(GenerateProjects = true)]
readonly Solution Solution;

[GitVersion(Framework = "net5.0")]
readonly GitVersion GitVersion;

[PackageExecutable("nspec", "NSpecRunner.exe", Version = "3.1.0")]
Tool NSpec3;

AbsolutePath ArtifactsDirectory => RootDirectory / "Artifacts";

string SemVer;

Target Clean => _ => _
.Executes(() =>
{
EnsureCleanDirectory(ArtifactsDirectory);
});

Target CalculateNugetVersion => _ => _
.Executes(() =>
{
SemVer = GitVersion.SemVer;
if (IsPullRequest)
{
Serilog.Log.Information(
"Branch spec {branchspec} is a pull request. Adding build number {buildnumber}",
BranchSpec, BuildNumber);

SemVer = string.Join('.', GitVersion.SemVer.Split('.').Take(3).Union(new [] { BuildNumber }));
}

Serilog.Log.Information("SemVer = {semver}", SemVer);
});

bool IsPullRequest => BranchSpec != null && BranchSpec.Contains("pull", StringComparison.InvariantCultureIgnoreCase);

Target Restore => _ => _
.DependsOn(Clean)
.Executes(() =>
Expand Down Expand Up @@ -78,11 +114,18 @@ class Build : NukeBuild
{
if (EnvironmentInfo.IsWin)
{
Xunit2(s => s
.SetFramework("net47")
.AddTargetAssemblies(GlobFiles(
Xunit2(s =>
{
IReadOnlyCollection<string> testAssemblies = GlobFiles(
Solution.Specs.FluentAssertions_Specs.Directory,
"bin/Debug/net47/*.Specs.dll").NotEmpty()));
"bin/Debug/net47/*.Specs.dll");

Assert.NotEmpty(testAssemblies.ToList());

return s
.SetFramework("net47")
.AddTargetAssemblies(testAssemblies);
});
}

DotNetTest(s => s
Expand Down Expand Up @@ -128,13 +171,35 @@ class Build : NukeBuild
.DependsOn(ApiChecks)
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.DependsOn(CalculateNugetVersion)
.Executes(() =>
{
DotNetPack(s => s
.SetProject(Solution.Core.FluentAssertions)
.SetOutputDirectory(ArtifactsDirectory)
.SetConfiguration("Release")
.EnableContinuousIntegrationBuild() // Necessary for deterministic builds
.SetVersion(GitVersion.NuGetVersionV2));
.SetVersion(SemVer));
});

Target Push => _ => _
.DependsOn(Pack)
.OnlyWhenDynamic(() => IsTag)
.Executes(() =>
{
var packages = GlobFiles(ArtifactsDirectory, "*.nupkg");
dennisdoomen marked this conversation as resolved.
Show resolved Hide resolved

Assert.NotEmpty(packages.ToList());

DotNetNuGetPush(s => s
.SetApiKey(ApiKey)
.EnableSkipDuplicate()
.SetSource("https://api.nuget.org/v3/index.json")
.EnableNoSymbols()
.CombineWith(packages,
(v, path) => v.SetTargetPath(path)));
});

bool IsTag => BranchSpec != null && BranchSpec.Contains("refs/tags", StringComparison.InvariantCultureIgnoreCase);

}
4 changes: 2 additions & 2 deletions Build/_build.csproj
Expand Up @@ -8,9 +8,9 @@
<NukeScriptDirectory>..\</NukeScriptDirectory>
</PropertyGroup>
<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.7.0]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.8.1]" />
<PackageDownload Include="NSpec" Version="[3.1.0]" />
<PackageDownload Include="xunit.runner.console" Version="[2.4.1]" />
<PackageReference Include="Nuke.Common" Version="5.3.0" />
<PackageReference Include="Nuke.Common" Version="6.0.1" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions GitVersion.yml
Expand Up @@ -3,5 +3,11 @@ branches:
release:
regex: releases?[/-]
tag: rc
pull-request:
mode: ContinuousDeployment
regex: ((pull|pull\-requests|pr)[/-]|[/-](merge))
tag: pr
tag-number-pattern: '[/-]?(?<number>\d+)'
prevent-increment-of-merged-branch-version: false
ignore:
sha: []
18 changes: 14 additions & 4 deletions build.ps1
Expand Up @@ -14,15 +14,16 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
###########################################################################

$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
$TempDirectory = "$PSScriptRoot\\.nuke\temp"
$TempDirectory = "$PSScriptRoot\.nuke\temp"

$DotNetGlobalFile = "$PSScriptRoot\\global.json"
$DotNetGlobalFile = "$PSScriptRoot\global.json"
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
$DotNetChannel = "Current"

$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
$env:DOTNET_MULTILEVEL_LOOKUP = 0
$env:DOTNET_ROLL_FORWARD = "Major"
$env:NUKE_TELEMETRY_OPTOUT = 1

###########################################################################
Expand All @@ -34,9 +35,18 @@ function ExecSafe([scriptblock] $cmd) {
if ($LASTEXITCODE) { exit $LASTEXITCODE }
}

# Print environment variables
# WARNING: Make sure that secrets are actually scrambled in build log
# Get-Item -Path Env:* | Sort-Object -Property Name | ForEach-Object {"{0}={1}" -f $_.Name,$_.Value}

# Check if any dotnet is installed
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue)) {
ExecSafe { & dotnet --info }
}

# If dotnet CLI is installed globally and it matches requested version, use for execution
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
$env:DOTNET_EXE = (Get-Command "dotnet").Path
}
else {
Expand Down Expand Up @@ -66,5 +76,5 @@ else {

Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)"

ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary }
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }
16 changes: 13 additions & 3 deletions build.sh
Expand Up @@ -10,15 +10,16 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
###########################################################################

BUILD_PROJECT_FILE="$SCRIPT_DIR/Build/_build.csproj"
TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
TEMP_DIRECTORY="$SCRIPT_DIR/.nuke/temp"

DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
DOTNET_GLOBAL_FILE="$SCRIPT_DIR/global.json"
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
DOTNET_CHANNEL="Current"

export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_MULTILEVEL_LOOKUP=0
export DOTNET_ROLL_FORWARD="Major"
export NUKE_TELEMETRY_OPTOUT=1

###########################################################################
Expand All @@ -29,6 +30,15 @@ function FirstJsonValue {
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
}

# Print environment variables
# WARNING: Make sure that secrets are actually scrambled in build log
# env | sort

# Check if any dotnet is installed
if [[ -x "$(command -v dotnet)" ]]; then
dotnet --info
fi

# If dotnet CLI is installed globally and it matches requested version, use for execution
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
export DOTNET_EXE="$(command -v dotnet)"
Expand Down Expand Up @@ -59,5 +69,5 @@ fi

echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)"

"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"