From 17adbed7563989008eb7bf260c232d2d052aa0aa Mon Sep 17 00:00:00 2001 From: "C. Augusto Proiete" Date: Sat, 14 Aug 2021 22:46:45 -0300 Subject: [PATCH] Add build scripts --- .config/dotnet-tools.json | 18 +++++ .github/dependabot.yml | 14 ++++ .github/workflows/ci.yml | 60 +++++++++++++++ .github/workflows/dependabot-cake.yml | 13 ++++ build.cake | 107 ++++++++++++++++++++++++++ build.cmd | 11 +++ build.ps1 | 13 ++++ build.sh | 12 +++ cake.config | 12 +++ 9 files changed, 260 insertions(+) create mode 100644 .config/dotnet-tools.json create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/dependabot-cake.yml create mode 100644 build.cake create mode 100644 build.cmd create mode 100644 build.ps1 create mode 100755 build.sh create mode 100644 cake.config diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..e5fe4d7 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,18 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "1.1.0", + "commands": [ + "dotnet-cake" + ] + }, + "minver-cli": { + "version": "2.5.0", + "commands": [ + "minver" + ] + } + } +} \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b0f9f2e --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +version: 2 +updates: + - package-ecosystem: "nuget" + directory: "/src" + schedule: + interval: "daily" + target-branch: "master" + ignore: + - dependency-name: "Serilog" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + target-branch: "master" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e6182d2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,60 @@ +on: + push: + branches: + - master + - develop + - "feature/**" + - "release/**" + - "hotfix/**" + tags: + - "*.*.*" + paths-ignore: + - "README.md" + + pull_request: + + workflow_dispatch: + +env: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true + DOTNET_CLI_TELEMETRY_OPTOUT: true + DOTNET_NOLOGO: true + +jobs: + build: + strategy: + fail-fast: false + matrix: + job: + - os: ubuntu-20.04 + build: ./build.sh + push: true + - os: windows-2019 + build: ./build.cmd + - os: macos-11 + build: ./build.sh + name: ${{ matrix.job.os }} + runs-on: ${{ matrix.job.os }} + steps: + - name: Setup netcoreapp3.1 + uses: actions/setup-dotnet@v1.8.1 + with: + dotnet-version: "3.1.412" + - name: Setup net5.0 + uses: actions/setup-dotnet@v1.8.1 + with: + dotnet-version: "5.0.400" + - name: Run dotnet --info + run: dotnet --info + - uses: actions/checkout@v2.3.4 + with: + fetch-depth: 0 + - name: Build + run: ${{ matrix.job.build }} --verbosity=diagnostic --target=pack + - name: Publish artifacts + if: matrix.job.push && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) + uses: actions/upload-artifact@v2.2.4 + with: + if-no-files-found: warn + name: package + path: artifacts/nuget/**/* diff --git a/.github/workflows/dependabot-cake.yml b/.github/workflows/dependabot-cake.yml new file mode 100644 index 0000000..7813869 --- /dev/null +++ b/.github/workflows/dependabot-cake.yml @@ -0,0 +1,13 @@ +on: + schedule: + # every Sunday at 6am + - cron: '0 6 * * SUN' + + workflow_dispatch: + +jobs: + dependabot-cake: + runs-on: ubuntu-18.04 + steps: + - name: check/update cake dependencies + uses: augustoproiete-actions/nils-org--dependabot-cake-action@v1 diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..a270638 --- /dev/null +++ b/build.cake @@ -0,0 +1,107 @@ +#addin "nuget:?package=Cake.MinVer&version=1.0.1" +#addin "nuget:?package=Cake.Args&version=1.0.1" + +var target = ArgumentOrDefault("target") ?? "pack"; +var buildVersion = MinVer(s => s.WithTagPrefix("v").WithDefaultPreReleasePhase("preview")); + +Task("clean") + .Does(() => +{ + CleanDirectories("./artifacts/**"); + CleanDirectories("./**/^{bin,obj}"); +}); + +Task("restore") + .IsDependentOn("clean") + .Does(() => +{ + DotNetCoreRestore("./serilog-enrichers-globallogcontext.sln", new DotNetCoreRestoreSettings + { + LockedMode = true, + }); +}); + +Task("build") + .IsDependentOn("restore") + .DoesForEach(new[] { "Debug", "Release" }, (configuration) => +{ + DotNetCoreBuild("./serilog-enrichers-globallogcontext.sln", new DotNetCoreBuildSettings + { + Configuration = configuration, + NoRestore = true, + NoIncremental = false, + MSBuildSettings = new DotNetCoreMSBuildSettings() + .WithProperty("Version", buildVersion.Version) + .WithProperty("AssemblyVersion", buildVersion.AssemblyVersion) + .WithProperty("FileVersion", buildVersion.FileVersion) + .WithProperty("ContinuousIntegrationBuild", BuildSystem.IsLocalBuild ? "false" : "true") + }); +}); + +Task("test") + .IsDependentOn("build") + .Does(() => +{ + var settings = new DotNetCoreTestSettings + { + Configuration = "Release", + NoRestore = true, + NoBuild = true, + }; + + var projectFiles = GetFiles("./test/**/*.csproj"); + foreach (var file in projectFiles) + { + DotNetCoreTest(file.FullPath, settings); + } +}); + +Task("pack") + .IsDependentOn("test") + .Does(() => +{ + var releaseNotes = $"https://github.com/augustoproiete/serilog-enrichers-globallogcontext/releases/tag/v{buildVersion.Version}"; + + DotNetCorePack("./src/Serilog.Enrichers.GlobalLogContext/Serilog.Enrichers.GlobalLogContext.csproj", new DotNetCorePackSettings + { + Configuration = "Release", + NoRestore = true, + NoBuild = true, + OutputDirectory = "./artifacts/nuget", + MSBuildSettings = new DotNetCoreMSBuildSettings() + .WithProperty("Version", buildVersion.Version) + .WithProperty("PackageReleaseNotes", releaseNotes) + }); +}); + +Task("push") + .IsDependentOn("pack") + .Does(context => +{ + var url = context.EnvironmentVariable("NUGET_URL"); + if (string.IsNullOrWhiteSpace(url)) + { + context.Information("No NuGet URL specified. Skipping publishing of NuGet packages"); + return; + } + + var apiKey = context.EnvironmentVariable("NUGET_API_KEY"); + if (string.IsNullOrWhiteSpace(apiKey)) + { + context.Information("No NuGet API key specified. Skipping publishing of NuGet packages"); + return; + } + + var nugetPushSettings = new DotNetCoreNuGetPushSettings + { + Source = url, + ApiKey = apiKey, + }; + + foreach (var nugetPackageFile in GetFiles("./artifacts/nuget/*.nupkg")) + { + DotNetCoreNuGetPush(nugetPackageFile.FullPath, nugetPushSettings); + } +}); + +RunTarget(target); diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..d060b75 --- /dev/null +++ b/build.cmd @@ -0,0 +1,11 @@ +@echo on +@cd %~dp0 + +set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +set DOTNET_CLI_TELEMETRY_OPTOUT=1 +set DOTNET_NOLOGO=1 + +dotnet tool restore +@if %ERRORLEVEL% neq 0 goto :eof + +dotnet cake %* diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..21821d2 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,13 @@ +$ErrorActionPreference = 'Stop' + +Set-Location -LiteralPath $PSScriptRoot + +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1' +$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1' +$env:DOTNET_NOLOGO = '1' + +dotnet tool restore +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + +dotnet cake @args +if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..31be886 --- /dev/null +++ b/build.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euox pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")" + +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_NOLOGO=1 + +dotnet tool restore + +dotnet cake "$@" diff --git a/cake.config b/cake.config new file mode 100644 index 0000000..513b1e8 --- /dev/null +++ b/cake.config @@ -0,0 +1,12 @@ +[Nuget] +Source=https://api.nuget.org/v3/index.json +UseInProcessClient=true +LoadDependencies=false + +[Paths] +Tools=./.cake +Addins=./.cake/addins +Modules=./.cake/modules + +[Settings] +SkipVerification=false