From b56b633232f8bf1ce3af244e5f13ff69746a69b9 Mon Sep 17 00:00:00 2001 From: Robert Marshall Date: Sat, 18 Feb 2023 13:23:54 +0000 Subject: [PATCH] Update all the things --- .drone.yml | 2 +- .gitignore | 3 +- .nuke | 1 - .nuke/build.schema.json | 122 ++++++++++++++++++ .nuke/parameters.json | 4 + build.cmd | 5 +- build.ps1 | 42 +++--- build.sh | 36 +++--- build/Build.cs | 3 +- build/Configuration.cs | 16 +++ build/_build.csproj | 5 +- .../ApiClientTests.cs | 4 +- .../Robware.Lib.ApiClient.Tests.csproj | 14 +- .../Robware.Lib.ApiClient.csproj | 10 +- 14 files changed, 205 insertions(+), 62 deletions(-) delete mode 100644 .nuke create mode 100644 .nuke/build.schema.json create mode 100644 .nuke/parameters.json create mode 100644 build/Configuration.cs diff --git a/.drone.yml b/.drone.yml index 4a70979..ec37bd3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,7 +6,7 @@ clone: steps: - name: build and publish - image: mcr.microsoft.com/dotnet/core/sdk:3.1 + image: mcr.microsoft.com/dotnet/sdk:7.0 environment: NugetEndpoint: from_secret: NugetEndpoint diff --git a/.gitignore b/.gitignore index 76b6e3f..724ce58 100644 --- a/.gitignore +++ b/.gitignore @@ -52,4 +52,5 @@ output .tmp *.ncrunchsolution _NCrunch_Website -*.DotSettings \ No newline at end of file +*.DotSettings +.nuke/temp \ No newline at end of file diff --git a/.nuke b/.nuke deleted file mode 100644 index 6df922d..0000000 --- a/.nuke +++ /dev/null @@ -1 +0,0 @@ -src/Robware.Lib.ApiClient.sln \ No newline at end of file diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json new file mode 100644 index 0000000..b2ba503 --- /dev/null +++ b/.nuke/build.schema.json @@ -0,0 +1,122 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Build Schema", + "$ref": "#/definitions/build", + "definitions": { + "build": { + "type": "object", + "properties": { + "Configuration": { + "type": "string", + "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", + "enum": [ + "Debug", + "Release" + ] + }, + "Continue": { + "type": "boolean", + "description": "Indicates to continue a previously failed build attempt" + }, + "Help": { + "type": "boolean", + "description": "Shows the help text for this build assembly" + }, + "Host": { + "type": "string", + "description": "Host for execution. Default is 'automatic'", + "enum": [ + "AppVeyor", + "AzurePipelines", + "Bamboo", + "Bitbucket", + "Bitrise", + "GitHubActions", + "GitLab", + "Jenkins", + "Rider", + "SpaceAutomation", + "TeamCity", + "Terminal", + "TravisCI", + "VisualStudio", + "VSCode" + ] + }, + "NoLogo": { + "type": "boolean", + "description": "Disables displaying the NUKE logo" + }, + "NugetApiKey": { + "type": "string" + }, + "NugetEndpoint": { + "type": "string" + }, + "Partition": { + "type": "string", + "description": "Partition to use on CI" + }, + "Plan": { + "type": "boolean", + "description": "Shows the execution plan (HTML)" + }, + "Profile": { + "type": "array", + "description": "Defines the profiles to load", + "items": { + "type": "string" + } + }, + "Root": { + "type": "string", + "description": "Root directory during build execution" + }, + "Skip": { + "type": "array", + "description": "List of targets to be skipped. Empty list skips all dependencies", + "items": { + "type": "string", + "enum": [ + "Clean", + "Compile", + "Package", + "Publish", + "Restore", + "Test" + ] + } + }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" + }, + "Target": { + "type": "array", + "description": "List of targets to be invoked. Default is '{default_target}'", + "items": { + "type": "string", + "enum": [ + "Clean", + "Compile", + "Package", + "Publish", + "Restore", + "Test" + ] + } + }, + "Verbosity": { + "type": "string", + "description": "Logging verbosity during build execution. Default is 'Normal'", + "enum": [ + "Minimal", + "Normal", + "Quiet", + "Verbose" + ] + } + } + } + } +} \ No newline at end of file diff --git a/.nuke/parameters.json b/.nuke/parameters.json new file mode 100644 index 0000000..2024c9d --- /dev/null +++ b/.nuke/parameters.json @@ -0,0 +1,4 @@ +{ + "$schema": "./build.schema.json", + "Solution": "src/Robware.Lib.ApiClient.sln" +} \ No newline at end of file diff --git a/build.cmd b/build.cmd index f9683e7..b08cc59 100755 --- a/build.cmd +++ b/build.cmd @@ -1,6 +1,7 @@ :; set -eo pipefail -:; ./build.sh "$@" +:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) +:; ${SCRIPT_DIR}/build.sh "$@" :; exit $? @ECHO OFF -powershell -ExecutionPolicy ByPass -NoProfile %0\..\build.ps1 %* +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* diff --git a/build.ps1 b/build.ps1 index 2e6b4ae..8c52d63 100644 --- a/build.ps1 +++ b/build.ps1 @@ -14,7 +14,7 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent ########################################################################### $BuildProjectFile = "$PSScriptRoot\build\_build.csproj" -$TempDirectory = "$PSScriptRoot\\.tmp" +$TempDirectory = "$PSScriptRoot\\.nuke\temp" $DotNetGlobalFile = "$PSScriptRoot\\global.json" $DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" @@ -22,6 +22,7 @@ $DotNetChannel = "Current" $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 +$env:DOTNET_MULTILEVEL_LOOKUP = 0 ########################################################################### # EXECUTION @@ -32,38 +33,37 @@ function ExecSafe([scriptblock] $cmd) { if ($LASTEXITCODE) { exit $LASTEXITCODE } } -# If global.json exists, load expected version -if (Test-Path $DotNetGlobalFile) { - $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) - if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { - $DotNetVersion = $DotNetGlobal.sdk.version - } -} - -# If dotnet is installed locally, and expected version is not set or installation matches the expected version +# If dotnet CLI is installed globally and it matches requested version, use for execution if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and ` - (!(Test-Path variable:DotNetVersion) -or $(& dotnet --version) -eq $DotNetVersion)) { + $(dotnet --version) -and $LASTEXITCODE -eq 0) { $env:DOTNET_EXE = (Get-Command "dotnet").Path } else { - $DotNetDirectory = "$TempDirectory\dotnet-win" - $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" - # Download install script $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) - # Install by channel or version - if (!(Test-Path variable:DotNetVersion)) { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } - } else { - ExecSafe { & $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + # If global.json exists, load expected version + if (Test-Path $DotNetGlobalFile) { + $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) + if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { + $DotNetVersion = $DotNetGlobal.sdk.version + } } + + # Install by channel or version + $DotNetDirectory = "$TempDirectory\dotnet-win" + if (!(Test-Path variable:DotNetVersion)) { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } + } else { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + } + $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" } -Write-Output "Microsoft (R) .NET Core SDK version $(& $env:DOTNET_EXE --version)" +Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)" -ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false -nologo -clp:NoSummary --verbosity quiet } +ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet } ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments } diff --git a/build.sh b/build.sh index 94ae8bd..1f3ba09 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -echo $(bash --version 2>&1 | head -n 1) +bash --version 2>&1 | head -n 1 set -eo pipefail SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) @@ -10,7 +10,7 @@ SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) ########################################################################### BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj" -TEMP_DIRECTORY="$SCRIPT_DIR//.tmp" +TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" @@ -18,45 +18,45 @@ DOTNET_CHANNEL="Current" export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_MULTILEVEL_LOOKUP=0 ########################################################################### # EXECUTION ########################################################################### function FirstJsonValue { - perl -nle 'print $1 if m{"'$1'": "([^"]+)",?}' <<< ${@:2} + perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}" } -# If global.json exists, load expected version -if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then - DOTNET_VERSION=$(FirstJsonValue "version" $(cat "$DOTNET_GLOBAL_FILE")) - if [[ "$DOTNET_VERSION" == "" ]]; then - unset DOTNET_VERSION - fi -fi - -# If dotnet is installed locally, and expected version is not set or installation matches the expected version -if [[ -x "$(command -v dotnet)" && (-z ${DOTNET_VERSION+x} || $(dotnet --version 2>&1) == "$DOTNET_VERSION") ]]; then +# 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)" else - DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" - export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" - # Download install script DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" mkdir -p "$TEMP_DIRECTORY" curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" chmod +x "$DOTNET_INSTALL_FILE" + # If global.json exists, load expected version + if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then + DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")") + if [[ "$DOTNET_VERSION" == "" ]]; then + unset DOTNET_VERSION + fi + fi + # Install by channel or version + DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" if [[ -z ${DOTNET_VERSION+x} ]]; then "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path else "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path fi + export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" fi -echo "Microsoft (R) .NET Core SDK version $("$DOTNET_EXE" --version)" +echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" -"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false -nologo -clp:NoSummary --verbosity quiet +"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@" diff --git a/build/Build.cs b/build/Build.cs index ae65eed..a743902 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -9,7 +9,6 @@ using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.PathConstruction; using static Nuke.Common.Tools.DotNet.DotNetTasks; -[CheckBuildProjectConfigurations] [UnsetVisualStudioEnvironmentVariables] class Build : NukeBuild { @@ -60,7 +59,7 @@ class Build : NukeBuild { .DependsOn(Test) .Executes(() => { DotNetPack(s => s - .SetProject(Solution) + .SetProject(Solution.Projects.SingleOrError(project => project.Name == "Robware.Lib.ApiClient", "ERROR FINDING API CLIENT PROJECT")) .SetIncludeSymbols(true) .SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg) .SetOutputDirectory(OutputDirectory)); diff --git a/build/Configuration.cs b/build/Configuration.cs new file mode 100644 index 0000000..9c08b1a --- /dev/null +++ b/build/Configuration.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel; +using System.Linq; +using Nuke.Common.Tooling; + +[TypeConverter(typeof(TypeConverter))] +public class Configuration : Enumeration +{ + public static Configuration Debug = new Configuration { Value = nameof(Debug) }; + public static Configuration Release = new Configuration { Value = nameof(Release) }; + + public static implicit operator string(Configuration configuration) + { + return configuration.Value; + } +} diff --git a/build/_build.csproj b/build/_build.csproj index aca8950..ae21513 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -2,15 +2,16 @@ Exe - netcoreapp3.0 + net7.0 CS0649;CS0169 .. .. + 1 - + diff --git a/src/Robware.Lib.ApiClient.Tests/ApiClientTests.cs b/src/Robware.Lib.ApiClient.Tests/ApiClientTests.cs index ba803ab..8b7b2ee 100644 --- a/src/Robware.Lib.ApiClient.Tests/ApiClientTests.cs +++ b/src/Robware.Lib.ApiClient.Tests/ApiClientTests.cs @@ -60,7 +60,7 @@ namespace Robware.Lib.ApiClient.Tests { } [Fact] - public void Get_WithUrlThatReturnsError_ThrowsException() { + public async void Get_WithUrlThatReturnsError_ThrowsException() { var httpClient = new HttpClientBuilder() .WithMethod(HttpMethod.Get) .WithUrl("/test") @@ -72,7 +72,7 @@ namespace Robware.Lib.ApiClient.Tests { var client = new TestApiClient(httpClient, cache); - client.Invoking(apiClient => apiClient.Get("404")).Should().Throw() + await client.Invoking(apiClient => apiClient.Get("404")).Should().ThrowAsync() .WithMessage("Error calling API http://example.com/404: 404, Not Found"); } diff --git a/src/Robware.Lib.ApiClient.Tests/Robware.Lib.ApiClient.Tests.csproj b/src/Robware.Lib.ApiClient.Tests/Robware.Lib.ApiClient.Tests.csproj index 7b86eaa..ad1334b 100644 --- a/src/Robware.Lib.ApiClient.Tests/Robware.Lib.ApiClient.Tests.csproj +++ b/src/Robware.Lib.ApiClient.Tests/Robware.Lib.ApiClient.Tests.csproj @@ -1,19 +1,19 @@ - netcoreapp3.1 + net7.0 false - - - + + + - - - + + + diff --git a/src/Robware.Lib.ApiClient/Robware.Lib.ApiClient.csproj b/src/Robware.Lib.ApiClient/Robware.Lib.ApiClient.csproj index dab36fc..dc3afd1 100644 --- a/src/Robware.Lib.ApiClient/Robware.Lib.ApiClient.csproj +++ b/src/Robware.Lib.ApiClient/Robware.Lib.ApiClient.csproj @@ -1,17 +1,17 @@ - netcoreapp3.1 + net7.0 - 1.2.0 + 1.3.0 - - - + + +