Skip to content

Commit 3b2baf0

Browse files
committed
Added a build project to automaticly build an create a ready to ship nuget package
1 parent eb72e5f commit 3b2baf0

13 files changed

Lines changed: 442 additions & 0 deletions

.nuke/build.schema.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$ref": "#/definitions/build",
4+
"title": "Build Schema",
5+
"definitions": {
6+
"build": {
7+
"type": "object",
8+
"properties": {
9+
"Continue": {
10+
"type": "boolean",
11+
"description": "Indicates to continue a previously failed build attempt"
12+
},
13+
"Help": {
14+
"type": "boolean",
15+
"description": "Shows the help text for this build assembly"
16+
},
17+
"Host": {
18+
"type": "string",
19+
"description": "Host for execution. Default is 'automatic'",
20+
"enum": [
21+
"AppVeyor",
22+
"AzurePipelines",
23+
"Bamboo",
24+
"Bitbucket",
25+
"Bitrise",
26+
"GitHubActions",
27+
"GitLab",
28+
"Jenkins",
29+
"Rider",
30+
"SpaceAutomation",
31+
"TeamCity",
32+
"Terminal",
33+
"TravisCI",
34+
"VisualStudio",
35+
"VSCode"
36+
]
37+
},
38+
"NoLogo": {
39+
"type": "boolean",
40+
"description": "Disables displaying the NUKE logo"
41+
},
42+
"Partition": {
43+
"type": "string",
44+
"description": "Partition to use on CI"
45+
},
46+
"Plan": {
47+
"type": "boolean",
48+
"description": "Shows the execution plan (HTML)"
49+
},
50+
"Profile": {
51+
"type": "array",
52+
"description": "Defines the profiles to load",
53+
"items": {
54+
"type": "string"
55+
}
56+
},
57+
"Root": {
58+
"type": "string",
59+
"description": "Root directory during build execution"
60+
},
61+
"Skip": {
62+
"type": "array",
63+
"description": "List of targets to be skipped. Empty list skips all dependencies",
64+
"items": {
65+
"type": "string",
66+
"enum": [
67+
"Compile",
68+
"Info",
69+
"Pack",
70+
"Restore"
71+
]
72+
}
73+
},
74+
"Solution": {
75+
"type": "string",
76+
"description": "Path to a solution file that is automatically loaded"
77+
},
78+
"Target": {
79+
"type": "array",
80+
"description": "List of targets to be invoked. Default is '{default_target}'",
81+
"items": {
82+
"type": "string",
83+
"enum": [
84+
"Compile",
85+
"Info",
86+
"Pack",
87+
"Restore"
88+
]
89+
}
90+
},
91+
"Verbosity": {
92+
"type": "string",
93+
"description": "Logging verbosity during build execution. Default is 'Normal'",
94+
"enum": [
95+
"Minimal",
96+
"Normal",
97+
"Quiet",
98+
"Verbose"
99+
]
100+
},
101+
"Version": {
102+
"type": "string",
103+
"description": "Version of the package"
104+
}
105+
}
106+
}
107+
}
108+
}

.nuke/parameters.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./build.schema.json",
3+
"Solution": "src/WGet.Net.sln"
4+
}

src/WGet.Net.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WGet.NET", "WGet.NET\WGet.N
1212
EndProject
1313
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WGetTestLegacySupport", "WGetTestLegacySupport\WGetTestLegacySupport.csproj", "{E95FDAF2-A9E8-4BDF-94FF-0C72561E32E2}"
1414
EndProject
15+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{24811039-65CA-46B2-A324-422F5522CD05}"
16+
EndProject
1517
Global
1618
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1719
Debug|Any CPU = Debug|Any CPU
@@ -30,6 +32,10 @@ Global
3032
{E95FDAF2-A9E8-4BDF-94FF-0C72561E32E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
3133
{E95FDAF2-A9E8-4BDF-94FF-0C72561E32E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
3234
{E95FDAF2-A9E8-4BDF-94FF-0C72561E32E2}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{24811039-65CA-46B2-A324-422F5522CD05}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{24811039-65CA-46B2-A324-422F5522CD05}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{24811039-65CA-46B2-A324-422F5522CD05}.Release|Any CPU.ActiveCfg = Release|Any CPU
38+
{24811039-65CA-46B2-A324-422F5522CD05}.Release|Any CPU.Build.0 = Release|Any CPU
3339
EndGlobalSection
3440
GlobalSection(SolutionProperties) = preSolution
3541
HideSolutionNode = FALSE

src/build.cmd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:; set -eo pipefail
2+
:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
3+
:; ${SCRIPT_DIR}/build.sh "$@"
4+
:; exit $?
5+
6+
@ECHO OFF
7+
powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %*

src/build.ps1

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
[CmdletBinding()]
2+
Param(
3+
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
4+
[string[]]$BuildArguments
5+
)
6+
7+
Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)"
8+
9+
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 }
10+
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
11+
12+
###########################################################################
13+
# CONFIGURATION
14+
###########################################################################
15+
16+
$BuildProjectFile = "$PSScriptRoot\build\_build.csproj"
17+
$TempDirectory = "$PSScriptRoot\..\.nuke\temp"
18+
19+
$DotNetGlobalFile = "$PSScriptRoot\..\global.json"
20+
$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1"
21+
$DotNetChannel = "STS"
22+
23+
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
24+
$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
25+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
26+
27+
###########################################################################
28+
# EXECUTION
29+
###########################################################################
30+
31+
function ExecSafe([scriptblock] $cmd) {
32+
& $cmd
33+
if ($LASTEXITCODE) { exit $LASTEXITCODE }
34+
}
35+
36+
# If dotnet CLI is installed globally and it matches requested version, use for execution
37+
if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and `
38+
$(dotnet --version) -and $LASTEXITCODE -eq 0) {
39+
$env:DOTNET_EXE = (Get-Command "dotnet").Path
40+
}
41+
else {
42+
# Download install script
43+
$DotNetInstallFile = "$TempDirectory\dotnet-install.ps1"
44+
New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null
45+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
46+
(New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile)
47+
48+
# If global.json exists, load expected version
49+
if (Test-Path $DotNetGlobalFile) {
50+
$DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json)
51+
if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) {
52+
$DotNetVersion = $DotNetGlobal.sdk.version
53+
}
54+
}
55+
56+
# Install by channel or version
57+
$DotNetDirectory = "$TempDirectory\dotnet-win"
58+
if (!(Test-Path variable:DotNetVersion)) {
59+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath }
60+
} else {
61+
ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath }
62+
}
63+
$env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe"
64+
}
65+
66+
Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)"
67+
68+
if (Test-Path env:NUKE_ENTERPRISE_TOKEN) {
69+
& $env:DOTNET_EXE nuget remove source "nuke-enterprise" > $null
70+
& $env:DOTNET_EXE nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password $env:NUKE_ENTERPRISE_TOKEN > $null
71+
}
72+
73+
ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet }
74+
ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments }

src/build.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
bash --version 2>&1 | head -n 1
4+
5+
set -eo pipefail
6+
SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
7+
8+
###########################################################################
9+
# CONFIGURATION
10+
###########################################################################
11+
12+
BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
13+
TEMP_DIRECTORY="$SCRIPT_DIR/../.nuke/temp"
14+
15+
DOTNET_GLOBAL_FILE="$SCRIPT_DIR/../global.json"
16+
DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
17+
DOTNET_CHANNEL="STS"
18+
19+
export DOTNET_CLI_TELEMETRY_OPTOUT=1
20+
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
21+
export DOTNET_MULTILEVEL_LOOKUP=0
22+
23+
###########################################################################
24+
# EXECUTION
25+
###########################################################################
26+
27+
function FirstJsonValue {
28+
perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
29+
}
30+
31+
# If dotnet CLI is installed globally and it matches requested version, use for execution
32+
if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
33+
export DOTNET_EXE="$(command -v dotnet)"
34+
else
35+
# Download install script
36+
DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
37+
mkdir -p "$TEMP_DIRECTORY"
38+
curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
39+
chmod +x "$DOTNET_INSTALL_FILE"
40+
41+
# If global.json exists, load expected version
42+
if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
43+
DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
44+
if [[ "$DOTNET_VERSION" == "" ]]; then
45+
unset DOTNET_VERSION
46+
fi
47+
fi
48+
49+
# Install by channel or version
50+
DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
51+
if [[ -z ${DOTNET_VERSION+x} ]]; then
52+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
53+
else
54+
"$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
55+
fi
56+
export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
57+
fi
58+
59+
echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"
60+
61+
if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then
62+
"$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true
63+
"$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true
64+
fi
65+
66+
"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
67+
"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"

src/build/.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[*.cs]
2+
dotnet_style_qualification_for_field = false:warning
3+
dotnet_style_qualification_for_property = false:warning
4+
dotnet_style_qualification_for_method = false:warning
5+
dotnet_style_qualification_for_event = false:warning
6+
dotnet_style_require_accessibility_modifiers = never:warning
7+
8+
csharp_style_expression_bodied_methods = true:silent
9+
csharp_style_expression_bodied_properties = true:warning
10+
csharp_style_expression_bodied_indexers = true:warning
11+
csharp_style_expression_bodied_accessors = true:warning

src/build/Build.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Nuke.Common;
2+
using Nuke.Common.IO;
3+
using Nuke.Common.ProjectModel;
4+
using Nuke.Common.Tools.DotNet;
5+
using Serilog;
6+
//using System.Collections.Generic;
7+
8+
namespace BuildTool
9+
{
10+
11+
class Build : NukeBuild
12+
{
13+
public static int Main() => Execute<Build>(x => x.Pack);
14+
15+
[Parameter("Version of the package")]
16+
public readonly string Version = "0.0.0";
17+
18+
[Solution]
19+
public readonly Solution Solution;
20+
21+
// Allways set config to release, because build is intended for creating ready to ship packages
22+
private readonly Configuration _configuration = Configuration.Release;
23+
24+
private static AbsolutePath _packages => RootDirectory / "nuget" / "packages";
25+
private static AbsolutePath _sourceDirectory => RootDirectory / "src";
26+
27+
Target Info => _ => _
28+
.Unlisted()
29+
//.Before(Clean)
30+
.Before(Restore)
31+
.Before(Compile)
32+
.Before(Pack)
33+
.Executes(() =>
34+
{
35+
Log.Information("Creating \"WGet.NET\" nuget package");
36+
Log.Information("Version: {version}", Version);
37+
Log.Information("Output directory: {dir}", _packages);
38+
});
39+
40+
/*Target Clean => _ => _
41+
.Unlisted()
42+
.Before(Restore)
43+
.Executes(() =>
44+
{*/
45+
//IReadOnlyCollection<AbsolutePath> directories = _sourceDirectory.GlobDirectories("**/bin", "**/obj");
46+
47+
/*foreach (AbsolutePath directory in directories)
48+
{
49+
Log.Information($"{directory}");
50+
directory.DeleteDirectory();
51+
}
52+
});*/
53+
54+
Target Restore => _ => _
55+
.Unlisted()
56+
.Executes(() =>
57+
{
58+
DotNetTasks.DotNetRestore(s => s
59+
.SetProjectFile(Solution.GetProject("WGet.NET")));
60+
});
61+
62+
Target Compile => _ => _
63+
//.DependsOn(Clean)
64+
.DependsOn(Restore)
65+
.Executes(() =>
66+
{
67+
DotNetTasks.DotNetBuild(s => s
68+
.SetProjectFile(Solution.GetProject("WGet.NET"))
69+
.SetConfiguration(_configuration)
70+
.EnableNoRestore());
71+
});
72+
73+
Target Pack => _ => _
74+
.DependsOn(Info)
75+
.DependsOn(Compile)
76+
.Executes(() =>
77+
{
78+
DotNetTasks.DotNetPack(s => s
79+
.SetProject(Solution.GetProject("WGet.NET"))
80+
.SetOutputDirectory(_packages)
81+
.SetVersion(Version)
82+
.SetFileVersion(Version)
83+
.SetAssemblyVersion(Version)
84+
.SetProperty("PackageReleaseNotes", "https://github.com/basicx-StrgV/WGet.NET/releases/tag/" + Version));
85+
});
86+
}
87+
}

0 commit comments

Comments
 (0)