From 4a832d9497bbb90e2dce12d8e6c3aaa794a41296 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Mon, 14 Sep 2020 18:10:30 +0200 Subject: [PATCH] (build) Update to latest edition of cake.recipe --- .appveyor.yml | 37 +-------- .build/sonarcloud.cake | 4 +- .config/dotnet-tools.json | 12 +++ .github/workflows/build.yml | 65 +++++++++++++++ .travis.yml | 33 -------- build.config | 2 - build.ps1 | 152 +++--------------------------------- build.sh | 89 +-------------------- setup.cake | 33 ++------ 9 files changed, 108 insertions(+), 319 deletions(-) create mode 100644 .config/dotnet-tools.json create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml delete mode 100644 build.config diff --git a/.appveyor.yml b/.appveyor.yml index 6381c8e..3a513d1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,44 +1,16 @@ -image: - # - macos - - Ubuntu - - Visual Studio 2017 +image: Visual Studio 2019 matrix: fast_finish: true environment: APPVEYOR_YML_DISABLE_PS_LINUX: true branches: except: - - ci/travis - /dependabot\/.*/ skip_commits: files: - "*.md" - "LICENSE" - - ".travis.yml" - -for: -- - matrix: - only: - - image: Ubuntu - environment: - AZURE_SOURCE: - GITHUB_PASSWORD: - GITTER_TOKEN: - GPR_SOURCE: - MYGET_API_KEY: - NUGET_API_KEY: - SLACK_TOKEN: - TWITTER_ACCESS_TOKEN: - TWITTER_CONSUMER_KEY: - WYAM_ACCESS_TOKEN: - - skip_tags: true - install: - - git submodule update --init - - sudo -H pip install transifex-client - - sudo apt-get update || echo "Update failed, ignoring..." - - sudo apt-get install -y libgit2-dev + - ".github/**/*.yml" install: - git submodule update --init @@ -50,8 +22,7 @@ build: off test: off build_script: - - pwsh: ./build.ps1 --target=ContinuousIntegration --verbosity=Diagnostic + - pwsh: ./build.ps1 --target=CI --verbosity=Diagnostic cache: - - "tools -> build.config,setup.cake,.build/sonarcloud.cake" - - ".dotnet -> build.config" + - "tools -> .build/dotnet-tools.json,setup.cake,.build/sonarcloud.cake" diff --git a/.build/sonarcloud.cake b/.build/sonarcloud.cake index 6ceb8b1..558c5a6 100644 --- a/.build/sonarcloud.cake +++ b/.build/sonarcloud.cake @@ -8,7 +8,7 @@ Task("SonarCloud-Begin") .WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_TOKEN"), "Missing sonar cloud token environment variable") .WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_ORGANIZATION"), "Missing sonar cloud organization environment variable") .WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_PROJECT_KEY"), "Missing sonar cloud project key environment variable") - .Does(() => RequireTool(SonarQubeTool, + .Does((version) => RequireTool(SonarQubeTool, () => { Information("Starting SonarCloud analysing"); @@ -31,7 +31,7 @@ Task("SonarCloud-Begin") { "TEMP_ORGANIZATION", EnvironmentVariable("SONARCLOUD_ORGANIZATION") }, { "TEMP_OPENCOVER_FILTER", BuildParameters.Paths.Files.TestCoverageOutputFilePath.ToString().Replace(".xml", "*.xml") }, { "TEMP_TOKEN", EnvironmentVariable("SONARCLOUD_TOKEN") }, - { "TEMP_VERSION", BuildParameters.Version.SemVersion }, + { "TEMP_VERSION", version.SemVersion }, { "TEMP_TEST_RESULTS", BuildParameters.Paths.Directories.TestResults.CombineWithFilePath("TestResults.xml").ToString() }, }); })); diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..38bd0ea --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "0.38.4", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3bb4102 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,65 @@ +name: Build + +on: + push: + branches: + - master + - develop + - "release/**" + - "hotfix/**" + - "feature/**" + pull_request: + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + env: + AZURE_PASSWORD: ${{ secrets.AZURE_PASSWORD }} + AZURE_SOURCE: ${{ secrets.AZURE_SOURCE }} + AZURE_USER: ${{ secrets.AZURE_USER }} + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GITTER_ROOM_ID: ${{ secrets.GITTER_ROOM_ID }} + GITTER_TOKEN: ${{ secrets.GITTER_TOKEN }} + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + NUGET_SOURCE: "https://api.nuget.org/v3/index.json" + TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} + TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} + TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }} + TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }} + WYAM_ACCESS_TOKEN: ${{ secrets.WYAM_ACCESS_TOKEN }} + WYAM_DEPLOY_BRANCH: "gh-pages" + WYAM_DEPLOY_REMOTE: ${{ github.event.repository.html_url }} + + steps: + - uses: actions/checkout@v2.3.2 + with: + sumbodules: true + - name: Fetch all tags and branches + run: git fetch --prune --unshallow + - name: Install Transifex Client + if: ${{ runner.os }} == 'ubuntu-latest' # We do not need it for anything else + run: sudo apt-get install transifex-client -y + - name: Cache Tools + uses: actions/cache@v2.1.1 + with: + path: tools + key: ${{ runner.os }}-tools-${{ hashFiles('setup.cake') }} + - name: Build Addin + uses: cake-build/cake-action@v1 + with: + script-path: setup.cake + target: CI + verbosity: Diagnostic + cake-version: 0.38.4 + cake-bootstrap: true + - name: Upload artifacts + uses: actions/upload-artifact@v2.1.4 + with: + name: ${{ matrix.os }}-artifacts + path: | + BuildArtifacts/report.html + BuildArtifacts/packages/**/*.nupkg + BuildArtifacts/**/coverlet/*.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3a63ec9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: csharp -dist: xenial -os: - - linux - - osx -mono: latest - -cache: - directories: - - tools - -addons: - apt: - packages: - - transifex-client - homebrew: - packages: - - python - -env: - global: - - DOTNET_CLI_TELEMETRY_OPTOUT: 1 - - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true -git: - depth: false - -branches: - except: - - ci/appveyor - - /^dependabot\/.*/ - -script: - - ./build.sh --target=ContinuousIntegration --verbosity=Diagnostic diff --git a/build.config b/build.config deleted file mode 100644 index d817d24..0000000 --- a/build.config +++ /dev/null @@ -1,2 +0,0 @@ -DOTNET_SDKS=3.1.301,2.1.807 -CAKE_VERSION=0.38.4 diff --git a/build.ps1 b/build.ps1 index fed7e45..b7f5374 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,146 +1,20 @@ -$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition -$TOOLS_DIR = "$SCRIPT_DIR/tools" -if ($IsMacOS -or $IsLinux) { - $CAKE_EXE = "$TOOLS_DIR/dotnet-cake" -} -else { - $CAKE_EXE = "$TOOLS_DIR/dotnet-cake.exe" -} - -$DOTNET_EXE = "$(Get-Command dotnet -ea 0 | select -Expand Source)" -$INSTALL_NETCORE = $false -[string[]]$DOTNET_SDKS = "" -[string]$CAKE_VERSION = "" -foreach ($line in Get-Content "$SCRIPT_DIR/build.config" -Encoding utf8) { - if ($line -like "CAKE_VERSION=*") { - $CAKE_VERSION = $line.Substring($line.IndexOf('=') + 1) - } - elseif ($line -like "DOTNET_SDKS=*") { - $DOTNET_SDKS = $line.Substring($line.IndexOf('=') + 1) -split ',' - } -} - -if ([string]::IsNullOrWhiteSpace($CAKE_VERSION) -or !$DOTNET_SDKS) { - "An errer occured while parsing Cake / .NET Core SDK version." - return 1 -} - -if ($IsMacOS -or $IsLinux) { - $PathSep = ":" -} -else { - $PathSep = ";" -} - -if (Test-Path "$SCRIPT_DIR/.dotnet") { - $env:PATH = "$SCRIPT_DIR/.dotnet${PathSep}${env:PATH}" - $env:DOTNET_ROOT = "$SCRIPT_DIR/.dotnet" - $DOTNET_EXE = Get-ChildItem -Path "$SCRIPT_DIR/.dotnet/dotnet*" -Exclude "*.ps1" | select -First 1 -Expand FullName -} - -if ([string]::IsNullOrWhiteSpace($DOTNET_EXE)) { - $INSTALL_NETCORE = $true -} -elseif (($DOTNET_SDKS | ? { $_ -ne 'ANY' })) { - foreach ($sdk in $DOTNET_SDKS) { - $re = "^\s*$([regex]::Escape($sdk))\s+" - $DOTNET_INSTALLED_VERSION = . $DOTNET_EXE --list-sdks 2>&1 | ? { $_ -match $re } - if (!$DOTNET_INSTALLED_VERSION) { - $INSTALL_NETCORE = $true - break - } - } -} +$ErrorActionPreference = 'Stop' -if ($true -eq $INSTALL_NETCORE) { - if (!(Test-Path "$SCRIPT_DIR/.dotnet")) { - New-Item -Path "$SCRIPT_DIR/.dotnet" -ItemType Directory -Force | Out-Null - } +function Run([string[]]$arguments) { + $proc = Start-Process "dotnet" $arguments -PassThru -NoNewWindow + Wait-Process -InputObject $proc - $ScriptPath = "" - $LaunchUrl = "" - $ScriptUrl = "" - - if ($IsMacOS -or $IsLinux) { - $ScriptPath = "$SCRIPT_DIR/.dotnet/dotnet-install.sh" - $ScriptUrl = "https://dot.net/v1/dotnet-install.sh" - $LaunchUrl = "$(Get-Command bash)" - } - else { - $ScriptPath = "$SCRIPT_DIR/.dotnet/dotnet-install.ps1" - $ScriptUrl = "https://dot.net/v1/dotnet-install.ps1" - $LaunchUrl = "$ScriptPath" - } - (New-Object System.Net.WebClient).DownloadFile($ScriptUrl, $ScriptPath) - - foreach ($DOTNET_VERSION in $DOTNET_SDKS) { - $arguments = @() - if ($IsMacOS -or $IsLinux) { - $arguments = @( - $ScriptPath - "--install-dir" - "$SCRIPT_DIR/.dotnet" - "--no-path" - ) - if ($DOTNET_VERSION -ne "ANY") { - $arguments += @( - "--version" - "$DOTNET_VERSION" - ) - } - } - else { - $arguments = @{ - InstallDir = "$SCRIPT_DIR/.dotnet" - NoPath = $true - Version = "$DOTNET_VERSION" - } - } - - & $LaunchUrl @arguments - } - - $env:PATH = "$SCRIPT_DIR/.dotnet${PathSep}${env:PATH}" - $env:DOTNET_ROOT = "$SCRIPT_DIR/.dotnet" - - $DOTNET_EXE = Get-ChildItem -Path "$SCRIPT_DIR/.dotnet/dotnet*" -Exclude "*.ps1" | select -First 1 -Expand FullName - -} -elseif (Test-Path "/opt/dotnet/sdk" -ea 0) { - $env:DOTNET_ROOT = "/opt/dotnet/sdk" + if ($proc.ExitCode -ne 0) { + "Non-Zero exit code ($($proc.ExitCode)), exiting..." + exit $proc.ExitCode + } } -$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 -$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 -$env:DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER = 0 +Run tool, restore -$CAKE_INSTALLED_VERSION = Get-Command dotnet-cake -ea 0 | % { & $_.Source --version } +Run cake, setup.cake, --bootstrap -if ($CAKE_INSTALLED_VERSION -eq $CAKE_VERSION) { - $CAKE_EXE = Get-Command dotnet-cake | % Source -} -else { - $CakePath = "$TOOLS_DIR/.store/cake.tool/$CAKE_VERSION" - $CAKE_EXE = (Get-ChildItem -Path $TOOLS_DIR -Filter "dotnet-cake*" -File -ea 0 | select -First 1 -Expand FullName) - - if (!(Test-Path -Path $CakePath -PathType Container) -or !(Test-Path $CAKE_EXE -PathType Leaf)) { - if (!([string]::IsNullOrWhiteSpace($CAKE_EXE)) -and (Test-Path $CAKE_EXE -PathType Leaf)) { - & $DOTNET_EXE tool uninstall --tool-path $TOOLS_DIR Cake.Tool - } - - & $DOTNET_EXE tool install --tool-path $TOOLS_DIR --version $CAKE_VERSION Cake.Tool - if ($LASTEXITCODE -ne 0) { - "An error occured while installing Cake." - return 1 - } - - $CAKE_EXE = (Get-ChildItem -Path $TOOLS_DIR -Filter "dotnet-cake*" -File | select -First 1 -Expand FullName) - } -} - -& "$CAKE_EXE" "$SCRIPT_DIR/setup.cake" --bootstrap -if ($LASTEXITCODE -eq 0) { - & "$CAKE_EXE" "$SCRIPT_DIR/setup.cake" $args -} +$arguments = @("cake"; "setup.cake") +$arguments += @($args) -return $LASTEXITCODE +Run $arguments diff --git a/build.sh b/build.sh index 9bd2ba5..c16bb9e 100755 --- a/build.sh +++ b/build.sh @@ -1,87 +1,6 @@ -#!/usr/bin/env bash +#!/bin/bash +dotnet tool restore -# Define variables -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 -DOTNET_EXE=$(which dotnet 2>/dev/null) -INSTALL_NETCORE=0 +dotnet cake setup.cake --bootstrap -if [ "$CAKE_VERSION" = "" ] || [ "$DOTNET_SDKS" = "" ]; then - echo "An error occured while parsing Cake / .NET Core SDK version." - exit 1 -fi - -if [ -d "$SCRIPT_DIR/.dotnet" ]; then - DOTNET_EXE="$SCRIPT_DIR/.dotnet/dotnet" - export PATH="$SCRIPT_DIR/.dotnet:$PATH" - export DOTNET_ROOT="$SCRIPT_DIR/.dotnet" -fi - -if [ "$DOTNET_EXE" = "" ]; then - INSTALL_NETCORE=1 -elif [ "$DOTNET_SDKS" != "" ]; then - for sdk in $(echo $DOTNET_SDKS | sed "s/,/ /g") - do - DOTNET_INSTALLED_VERSION=$($DOTNET_EXE --list-sdks 2>/dev/null | grep "^\s*$sdk\+") - if [ "$DOTNET_INSTALLED_VERSION" == "" ]; then - INSTALL_NETCORE=1 - break - fi - done -fi - -if [ "$INSTALL_NETCORE" = "1" ]; then - 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 - - for sdk in $(echo $DOTNET_SDKS | sed "s/,/ /g") - do - bash "$SCRIPT_DIR/.dotnet/dotnet-install.sh" --version $sdk --install-dir "$SCRIPT_DIR/.dotnet" --no-path - done - - DOTNET_EXE="$SCRIPT_DIR/.dotnet/dotnet" - export PATH="$SCRIPT_DIR/.dotnet:$PATH" - export DOTNET_ROOT="$SCRIPT_DIR/.dotnet" -elif [ -d "/opt/dotnet/sdk" ]; then # Fix for dotnet-cake not finding sdk version - export DOTNET_ROOT="/opt/dotnet" -fi - -export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 -export DOTNET_CLI_TELEMETRY_OPTOUT=1 - -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_EXE tool uninstall --tool-path $TOOLS_DIR Cake.Tool - fi - - echo "Installing Cake $CAKE_VERSION..." - $DOTNET_EXE 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 - -########################################################################### -# RUN BUILD SCRIPT -########################################################################### - -# Start Cake -(exec "$CAKE_EXE" setup.cake --bootstrap) && (exec "$CAKE_EXE" setup.cake "$@") +dotnet cake setup.cake "$@" diff --git a/setup.cake b/setup.cake index bd3e2f4..7a751bc 100644 --- a/setup.cake +++ b/setup.cake @@ -1,9 +1,7 @@ -#load "nuget:https://f.feedz.io/wormiecorp/packages/nuget?package=Cake.Recipe&version=2.0.0-unstable0247&prerelease" +#load nuget:https://ci.appveyor.com/nuget/cake-recipe?package=Cake.Recipe&version=2.0.0-alpha0456&prerelease #load "./.build/*.cake" -Environment.SetVariableNames( - coverallsRepoTokenVariable: "_WE_DO_NOT_WANT_COVERALLS_TO_RUN" -); +Environment.SetVariableNames(); BuildParameters.SetParameters( context: Context, @@ -17,28 +15,13 @@ BuildParameters.SetParameters( solutionFilePath: "./Cake.Transifex.sln", testFilePattern: "/**/*.Tests.csproj", shouldRunCodecov: true, - shouldRunGitVersion: true -); + shouldRunCoveralls: false, + shouldUseDeterministicBuilds: true, + shouldUseTargetFrameworkPath: false, + preferredBuildAgentOperatingSystem: PlatformFamily.Linux, + preferredBuildProviderType: BuildProviderType.GitHubActions); -ToolSettings.SetToolSettings( - context: Context, - dupFinderExcludePattern: new string[] { - BuildParameters.RootDirectoryPath + "/src/*.Tests/**/*.cs" - }, - dupFinderExcludeFilesByStartingCommentSubstring: new string[] { - "" - }, - testCoverageFilter: "+[Cake.Transifex*]* -[*.Tests]*", - testCoverageExcludeByAttribute: "*.ExcludeFromCodeCoverage*", - testCoverageExcludeByFile: "*Designer.cs;*.g.cs;*.g.i.cs" -); - -if (BuildParameters.IsRunningOnAppVeyor && EnvironmentVariable("APPVEYOR_BUILD_WORKER_IMAGE") == "Visual Studio 2017" && - BuildParameters.IsMainRepository && BuildParameters.BranchType == BranchType.Master && !BuildParameters.IsTagged) { - BuildParameters.Tasks.ContinuousIntegrationTask.IsDependentOn("Create-Release-Notes"); -} - -BuildParameters.Tasks.TransifexPushSourceResource.WithCriteria(() => EnvironmentVariable("APPVEYOR_BUILD_WORKER_IMAGE") == "Visual Studio 2017"); +ToolSettings.SetToolSettings(context: Context); BuildParameters.PrintParameters(Context);