From 0b2774be1aae78496bc0ddb05cf2f1a3960f0b17 Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Sun, 27 Mar 2022 21:10:27 +0200 Subject: [PATCH 1/2] Switch to new bootstrappers --- .config/dotnet-tools.json | 12 +++++ build.config | 3 -- build.ps1 | 102 ++++++++------------------------------ build.sh | 52 +++---------------- 4 files changed, 42 insertions(+), 127 deletions(-) create mode 100644 .config/dotnet-tools.json delete mode 100644 build.config diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..b6cadaf6 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "2.1.0", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/build.config b/build.config deleted file mode 100644 index 9524c38c..00000000 --- a/build.config +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -CAKE_VERSION=2.1.0 -DOTNET_VERSION=6.0.201 diff --git a/build.ps1 b/build.ps1 index 781a1ece..b8737c00 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,27 +1,8 @@ #!/usr/bin/env pwsh $DotNetInstallerUri = 'https://dot.net/v1/dotnet-install.ps1'; $DotNetUnixInstallerUri = 'https://dot.net/v1/dotnet-install.sh' -$DotNetChannel = 'LTS' $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent -[string] $CakeVersion = '' -[string] $DotNetVersion= '' -foreach($line in Get-Content (Join-Path $PSScriptRoot 'build.config')) -{ - if ($line -like 'CAKE_VERSION=*') { - $CakeVersion = $line.SubString(13) - } - elseif ($line -like 'DOTNET_VERSION=*') { - $DotNetVersion =$line.SubString(15) - } -} - - -if ([string]::IsNullOrEmpty($CakeVersion) -or [string]::IsNullOrEmpty($DotNetVersion)) { - 'Failed to parse Cake / .NET Core SDK Version' - exit 1 -} - # Make sure tools folder exists $ToolPath = Join-Path $PSScriptRoot "tools" if (!(Test-Path $ToolPath)) { @@ -52,7 +33,7 @@ if ($PSVersionTable.PSEdition -ne 'Core') { $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 $env:DOTNET_CLI_TELEMETRY_OPTOUT=1 -$env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=1 +$env:DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2 Function Remove-PathVariable([string]$VariableToRemove) @@ -77,78 +58,39 @@ Function Remove-PathVariable([string]$VariableToRemove) } } -# Get .NET Core CLI path if installed. -$FoundDotNetCliVersion = $null; -if (Get-Command dotnet -ErrorAction SilentlyContinue) { - $FoundDotNetCliVersion = dotnet --version; +$InstallPath = Join-Path $PSScriptRoot ".dotnet" +$GlobalJsonPath = Join-Path $PSScriptRoot "global.json" +if (!(Test-Path $InstallPath)) { + New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null; } -if($FoundDotNetCliVersion -ne $DotNetVersion) { - $InstallPath = Join-Path $PSScriptRoot ".dotnet" - if (!(Test-Path $InstallPath)) { - New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null; - } +if ($IsMacOS -or $IsLinux) { + $ScriptPath = Join-Path $InstallPath 'dotnet-install.sh' + (New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath); + & bash $ScriptPath --jsonfile "$GlobalJsonPath" --install-dir "$InstallPath" --no-path - if ($IsMacOS -or $IsLinux) { - $ScriptPath = Join-Path $InstallPath 'dotnet-install.sh' - (New-Object System.Net.WebClient).DownloadFile($DotNetUnixInstallerUri, $ScriptPath); - & bash $ScriptPath --version "$DotNetVersion" --install-dir "$InstallPath" --channel "$DotNetChannel" --no-path - - Remove-PathVariable "$InstallPath" - $env:PATH = "$($InstallPath):$env:PATH" - } - else { - $ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1' - (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath); - & $ScriptPath -Channel $DotNetChannel -Version $DotNetVersion -InstallDir $InstallPath; + Remove-PathVariable "$InstallPath" + $env:PATH = "$($InstallPath):$env:PATH" +} +else { + $ScriptPath = Join-Path $InstallPath 'dotnet-install.ps1' + (New-Object System.Net.WebClient).DownloadFile($DotNetInstallerUri, $ScriptPath); + & $ScriptPath -JSonFile $GlobalJsonPath -InstallDir $InstallPath; - Remove-PathVariable "$InstallPath" - $env:PATH = "$InstallPath;$env:PATH" - } - $env:DOTNET_ROOT=$InstallPath + Remove-PathVariable "$InstallPath" + $env:PATH = "$InstallPath;$env:PATH" } +$env:DOTNET_ROOT=$InstallPath ########################################################################### # INSTALL CAKE ########################################################################### -# Make sure Cake has been installed. -[string] $CakeExePath = '' -[string] $CakeInstalledVersion = Get-Command dotnet-cake -ErrorAction SilentlyContinue | % {&$_.Source --version} - -if ($CakeInstalledVersion -eq $CakeVersion) { - # Cake found locally - $CakeExePath = (Get-Command dotnet-cake).Source -} -else { - $CakePath = [System.IO.Path]::Combine($ToolPath,'.store', 'cake.tool', $CakeVersion) # Old PowerShell versions Join-Path only supports one child path - - $CakeExePath = (Get-ChildItem -Path $ToolPath -Filter "dotnet-cake*" -File| ForEach-Object FullName | Select-Object -First 1) - - - if ((!(Test-Path -Path $CakePath -PathType Container)) -or (!(Test-Path $CakeExePath -PathType Leaf))) { - - if ((![string]::IsNullOrEmpty($CakeExePath)) -and (Test-Path $CakeExePath -PathType Leaf)) - { - & dotnet tool uninstall --tool-path $ToolPath Cake.Tool - } - - & dotnet tool install --tool-path $ToolPath --version $CakeVersion Cake.Tool - if ($LASTEXITCODE -ne 0) - { - 'Failed to install cake' - exit 1 - } - $CakeExePath = (Get-ChildItem -Path $ToolPath -Filter "dotnet-cake*" -File| ForEach-Object FullName | Select-Object -First 1) - } -} +& dotnet tool restore ########################################################################### # RUN BUILD SCRIPT ########################################################################### -& "$CakeExePath" ./build.cake --bootstrap -if ($LASTEXITCODE -eq 0) -{ - & "$CakeExePath" ./build.cake $args -} +& dotnet cake ./build.cake $args + exit $LASTEXITCODE \ No newline at end of file diff --git a/build.sh b/build.sh index 06bcee80..0759a8b4 100755 --- a/build.sh +++ b/build.sh @@ -1,15 +1,8 @@ #!/usr/bin/env bash # Define varibles SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -source $SCRIPT_DIR/build.config TOOLS_DIR=$SCRIPT_DIR/tools -CAKE_EXE=$TOOLS_DIR/dotnet-cake -CAKE_PATH=$TOOLS_DIR/.store/cake.tool/$CAKE_VERSION -if [ "$CAKE_VERSION" = "" ] || [ "$DOTNET_VERSION" = "" ]; then - echo "An error occured while parsing Cake / .NET Core SDK version." - exit 1 -fi # Make sure the tools folder exist. if [ ! -d "$TOOLS_DIR" ]; then @@ -25,51 +18,22 @@ export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=0 export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2 -DOTNET_INSTALLED_VERSION=$(dotnet --version 2>&1) - -if [ "$DOTNET_VERSION" != "$DOTNET_INSTALLED_VERSION" ]; then - echo "Installing .NET CLI..." - if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then - mkdir "$SCRIPT_DIR/.dotnet" - fi - curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh - bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $DOTNET_VERSION --install-dir .dotnet --no-path - export PATH="$SCRIPT_DIR/.dotnet":$PATH - export DOTNET_ROOT="$SCRIPT_DIR/.dotnet" +if [ ! -d "$SCRIPT_DIR/.dotnet" ]; then + mkdir "$SCRIPT_DIR/.dotnet" fi +curl -Lsfo "$SCRIPT_DIR/.dotnet/dotnet-install.sh" https://dot.net/v1/dotnet-install.sh +bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --jsonfile ./global.json --install-dir .dotnet --no-path +export PATH="$SCRIPT_DIR/.dotnet":$PATH +export DOTNET_ROOT="$SCRIPT_DIR/.dotnet" ########################################################################### # INSTALL CAKE ########################################################################### -CAKE_INSTALLED_VERSION=$(dotnet-cake --version 2>&1) - -if [ "$CAKE_VERSION" != "$CAKE_INSTALLED_VERSION" ]; then - if [ ! -f "$CAKE_EXE" ] || [ ! -d "$CAKE_PATH" ]; then - if [ -f "$CAKE_EXE" ]; then - dotnet tool uninstall --tool-path $TOOLS_DIR Cake.Tool - fi - - echo "Installing Cake $CAKE_VERSION..." - dotnet tool install --tool-path $TOOLS_DIR --version $CAKE_VERSION Cake.Tool - if [ $? -ne 0 ]; then - echo "An error occured while installing Cake." - exit 1 - fi - fi - - # Make sure that Cake has been installed. - if [ ! -f "$CAKE_EXE" ]; then - echo "Could not find Cake.exe at '$CAKE_EXE'." - exit 1 - fi -else - CAKE_EXE="dotnet-cake" -fi +dotnet tool restore ########################################################################### # RUN BUILD SCRIPT ########################################################################### -# Start Cake -(exec "$CAKE_EXE" build.cake --bootstrap) && (exec "$CAKE_EXE" build.cake "$@") \ No newline at end of file +dotnet cake "$@" \ No newline at end of file From fb194e85303df42ded6a1a04028bd430863b0a0f Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Sun, 27 Mar 2022 21:29:24 +0200 Subject: [PATCH 2/2] GitHub Actions use win2019 & only push package on Windows --- .github/workflows/build.yml | 2 +- build.cake | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cf881aa9..66a98f9c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-latest, ubuntu-latest, macos-latest] + os: [windows-2019, ubuntu-latest, macos-latest] steps: - name: Get the sources uses: actions/checkout@v2 diff --git a/build.cake b/build.cake index ae8a7e41..523a4a06 100644 --- a/build.cake +++ b/build.cake @@ -236,7 +236,10 @@ Task("Publish-NuGet") Task("Push-GitHub-Packages") .IsDependentOn("Package") - .WithCriteria(GitHubActions.IsRunningOnGitHubActions && !GitHubActions.Environment.PullRequest.IsPullRequest) + .WithCriteria( + GitHubActions.IsRunningOnGitHubActions && + !GitHubActions.Environment.PullRequest.IsPullRequest && + IsRunningOnWindows()) .Does(() => { // Resolve the API key.