diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..b6cadaf --- /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/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..b1b8a1a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: devlead \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..66a98f9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,37 @@ +name: Build +on: + pull_request: + push: + branches: + - main + - develop + - hotfix/* + +jobs: + build: + name: Build + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-2019, ubuntu-latest, macos-latest] + steps: + - name: Get the sources + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install .NET Core SDK + uses: actions/setup-dotnet@v1 + + - name: Run Cake script + uses: cake-build/cake-action@v1 + env: + GH_PACKAGES_NUGET_SOURCE: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json + GH_PACKAGES_NUGET_APIKEY: ${{ secrets.GITHUB_TOKEN }} + NUGET_SOURCE: ${{ secrets.NUGET_API_URL }} + NUGET_APIKEY: ${{ secrets.NUGET_API_KEY }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + cake-version: tool-manifest + target: GitHub-Actions \ No newline at end of file diff --git a/README.md b/README.md index c409f81..4017a90 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Notation) strings. | Bitrise | MacOS | [![Build Status](https://app.bitrise.io/app/5975a00ca2666fb1/status.svg?token=OZnv4YWRw71IVax38Wi50Q&branch=develop)](https://app.bitrise.io/app/5975a00ca2666fb1) | | Bitrise | Linux | [![Build Status](https://app.bitrise.io/app/4c9ee62c6ba13630/status.svg?token=RBH8UKw-68lQYjageT8VoQ&branch=develop)](https://app.bitrise.io/app/4c9ee62c6ba13630)| | Travis | Linux / MacOS | [![Travis build status](https://travis-ci.org/LitJSON/litjson.svg?branch=develop)](https://travis-ci.org/LitJSON/litjson) | - +| Azure Pipelines | Linux / MacOS / Windows | [![Azure Pipelines Build Status](https://dev.azure.com/LitJSON/litjson/_apis/build/status/LitJSON.litjson?branchName=develop)](https://dev.azure.com/LitJSON/litjson/_build/latest?definitionId=3&branchName=develop) | ## Compiling diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml new file mode 100644 index 0000000..fa1e91c --- /dev/null +++ b/azure-pipelines.yaml @@ -0,0 +1,31 @@ +strategy: + matrix: + linux: + imageName: 'ubuntu-20.04' + mac: + imageName: 'macos-10.15' + windows: + imageName: 'windows-2019' + +pool: + vmImage: $(imageName) + +steps: +- task: UseDotNet@2 + displayName: 'Use .NET Core sdk' + inputs: + useGlobalJson: true + +- task: Bash@3 + displayName: 'Bash Script' + condition: ne( variables['Agent.OS'], 'Windows_NT' ) + inputs: + targetType: filePath + filePath: ./build.sh + +- task: PowerShell@2 + displayName: 'PowerShell Script' + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + inputs: + targetType: filePath + filePath: ./build.ps1 diff --git a/build.cake b/build.cake index 3330845..523a4a0 100644 --- a/build.cake +++ b/build.cake @@ -1,11 +1,8 @@ -// Install modules -#module nuget:?package=Cake.DotNetTool.Module&version=0.3.0 - // Install tools #tool nuget:?package=NUnit.ConsoleRunner&version=3.4.0 // Install .NET Core Global tools. -#tool "dotnet:https://api.nuget.org/v3/index.json?package=GitVersion.Tool&version=5.0.1" +#tool "dotnet:?package=GitVersion.Tool&version=5.9.0" /////////////////////////////////////////////////////////////////////////////// // ARGUMENTS @@ -18,7 +15,7 @@ var configuration = Argument("configuration", "Release"); // PARAMETERS ////////////////////////////////////////////////////////////////////// -DotNetCoreMSBuildSettings msBuildSettings = null; +DotNetMSBuildSettings msBuildSettings = null; string version = null, semVersion = null, milestone = null; @@ -54,10 +51,12 @@ Setup(ctx => Information("Calculated Semantic Version: {0}", semVersion); - msBuildSettings = new DotNetCoreMSBuildSettings() + msBuildSettings = new DotNetMSBuildSettings() .WithProperty("Version", semVersion) .WithProperty("AssemblyVersion", version) - .WithProperty("FileVersion", version); + .WithProperty("FileVersion", version) + .WithProperty("ContinuousIntegrationBuild", BuildSystem.IsLocalBuild ? bool.FalseString : bool.TrueString); + if(!IsRunningOnWindows()) { @@ -107,16 +106,16 @@ Task("Clean") Task("Restore") .IsDependentOn("Clean") .Does(() => { - DotNetCoreRestore("./LitJSON.sln", - new DotNetCoreRestoreSettings { MSBuildSettings = msBuildSettings } + DotNetRestore("./LitJSON.sln", + new DotNetRestoreSettings { MSBuildSettings = msBuildSettings } ); }); Task("Build") .IsDependentOn("Restore") .Does(() => { - DotNetCoreBuild("./LitJSON.sln", - new DotNetCoreBuildSettings { + DotNetBuild("./LitJSON.sln", + new DotNetBuildSettings { Configuration = configuration, MSBuildSettings = msBuildSettings, ArgumentCustomization = args => args.Append("--no-restore") @@ -127,10 +126,10 @@ Task("Build") Task("Test") .IsDependentOn("Build") .Does(() => { - DotNetCoreTest("./test/LitJSON.Tests.csproj", - new DotNetCoreTestSettings { + DotNetTest("./test/LitJSON.Tests.csproj", + new DotNetTestSettings { Configuration = configuration, - Framework = "netcoreapp2.0", + Framework = "net6.0", NoBuild = true, ArgumentCustomization = args => args.Append("--no-restore") } @@ -143,11 +142,11 @@ Task("Test") Task("Test-SourceLink") .IsDependentOn("Build") - .WithCriteria(IsRunningOnWindows()) + .WithCriteria(IsRunningOnWindows() && AppVeyor.IsRunningOnAppVeyor) .Does(() => { foreach(var asssembly in GetFiles("./src/LitJson/bin/" + configuration + "/**/*.dll")) { - DotNetCoreTool(litjsonProjectPath.FullPath, "sourcelink", $"test {asssembly}"); + DotNetTool(litjsonProjectPath.FullPath, "sourcelink", $"test {asssembly}"); } }); @@ -155,8 +154,8 @@ Task("Package") .IsDependentOn("Test") .IsDependentOn("Test-SourceLink") .Does(() => { - DotNetCorePack(litjsonProjectPath.FullPath, - new DotNetCorePackSettings { + DotNetPack(litjsonProjectPath.FullPath, + new DotNetPackSettings { Configuration = configuration, NoBuild = true, IncludeSymbols = true, @@ -197,8 +196,8 @@ Task("Publish-MyGet") foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg"))) { - DotNetCoreNuGetPush(package.FullPath, - new DotNetCoreNuGetPushSettings { + DotNetNuGetPush(package.FullPath, + new DotNetNuGetPushSettings { ApiKey = apiKey, Source = apiUrl } @@ -215,19 +214,50 @@ Task("Publish-NuGet") // Resolve the API key. var apiKey = EnvironmentVariable("NUGET_API_KEY"); if(string.IsNullOrEmpty(apiKey)) { - throw new InvalidOperationException("Could not resolve MyGet API key."); + throw new InvalidOperationException("Could not resolve NuGet API key."); } // Resolve the API url. var apiUrl = EnvironmentVariable("NUGET_API_URL"); if(string.IsNullOrEmpty(apiUrl)) { - throw new InvalidOperationException("Could not resolve MyGet API url."); + throw new InvalidOperationException("Could not resolve NuGet API url."); + } + + foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg"))) + { + DotNetNuGetPush(package.FullPath, + new DotNetNuGetPushSettings { + ApiKey = apiKey, + Source = apiUrl + } + ); + } +}); + +Task("Push-GitHub-Packages") + .IsDependentOn("Package") + .WithCriteria( + GitHubActions.IsRunningOnGitHubActions && + !GitHubActions.Environment.PullRequest.IsPullRequest && + IsRunningOnWindows()) + .Does(() => { + + // Resolve the API key. + var apiKey = EnvironmentVariable("GH_PACKAGES_NUGET_APIKEY"); + if(string.IsNullOrEmpty(apiKey)) { + throw new InvalidOperationException("Could not resolve GitHub API key."); + } + + // Resolve the API url. + var apiUrl = EnvironmentVariable("GH_PACKAGES_NUGET_SOURCE"); + if(string.IsNullOrEmpty(apiUrl)) { + throw new InvalidOperationException("Could not resolve GitHub API url."); } foreach(var package in (GetFiles("./artifacts/nuget/*.nupkg") - GetFiles("./artifacts/nuget/*.symbols.nupkg"))) { - DotNetCoreNuGetPush(package.FullPath, - new DotNetCoreNuGetPushSettings { + DotNetNuGetPush(package.FullPath, + new DotNetNuGetPushSettings { ApiKey = apiKey, Source = apiUrl } @@ -240,6 +270,9 @@ Task("AppVeyor") .IsDependentOn("Publish-MyGet") .IsDependentOn("Publish-NuGet"); +Task("GitHub-Actions") + .IsDependentOn("Push-GitHub-Packages"); + Task("Default") .IsDependentOn("Package"); diff --git a/build.config b/build.config deleted file mode 100644 index 71d7b94..0000000 --- a/build.config +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -CAKE_VERSION=0.36.0 -DOTNET_VERSION=3.0.101 diff --git a/build.ps1 b/build.ps1 index 781a1ec..b8737c0 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 06bcee8..0759a8b 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 diff --git a/global.json b/global.json index c890fe9..74a295d 100644 --- a/global.json +++ b/global.json @@ -3,6 +3,8 @@ "src" ], "sdk": { - "version": "3.0.101" + "version": "6.0.201", + "allowPrerelease": false, + "rollForward": "feature" } } \ No newline at end of file diff --git a/src/LitJson/LitJSON.csproj b/src/LitJson/LitJSON.csproj index 759de5b..f8484f8 100644 --- a/src/LitJson/LitJSON.csproj +++ b/src/LitJson/LitJSON.csproj @@ -1,17 +1,19 @@ - netstandard2.0;net45;netstandard1.5;net40;net35;net20 + netstandard2.1;netstandard2.0;net45;netstandard1.5;net40;net35;net20;net6.0 false embedded + true + true true - + diff --git a/test/LitJSON.Tests.csproj b/test/LitJSON.Tests.csproj index c4ecb8b..e959852 100644 --- a/test/LitJSON.Tests.csproj +++ b/test/LitJSON.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0;net45 + net6.0;net45 false