diff --git a/.gitattributes b/.gitattributes index 2125666..1312090 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -* text=auto \ No newline at end of file +* text=auto +*.sh text eol=lf \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 800fa90..dc19cab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: csharp sudo: required dist: trusty -dotnet: 2.1.4 +dotnet: 2.1.400 mono: - 4.6.1 - 4.8.1 @@ -16,6 +16,7 @@ before_install: - curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list - sudo apt-get update - sudo apt-get install -y powershell + - sudo pwsh ./install-dotnet.ps1 script: - export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/ diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 7763210..279afc9 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,11 @@ Release Notes ============= +## 1.0.0 + +- Updated Giraffe to version `2.0.0`. +- Removed all other (redundant) dependencies. + ## 0.1.0-beta-110 - Updated Giraffe to version `1.1.0`. diff --git a/appveyor.yml b/appveyor.yml index ed18806..dccdf9e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,6 +4,8 @@ environment: DOTNET_CLI_TELEMETRY_OPTOUT: 1 init: - git config --global core.autocrlf true +install: + - ps: .\install-dotnet.ps1 build: off build_script: - ps: .\build.ps1 -Release -Pack diff --git a/build.ps1 b/build.ps1 index 4025913..48387dd 100644 --- a/build.ps1 +++ b/build.ps1 @@ -29,13 +29,6 @@ function Invoke-Cmd ($cmd) if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$cmd'."; return } } -function dotnet-info { Invoke-Cmd "dotnet --info" } -function dotnet-version { Invoke-Cmd "dotnet --version" } -function dotnet-build ($project, $argv) { Invoke-Cmd "dotnet build $project $argv" } -function dotnet-run ($project, $argv) { Invoke-Cmd "dotnet run --project $project $argv" } -function dotnet-test ($project, $argv) { Invoke-Cmd "dotnet test $project $argv" } -function dotnet-pack ($project, $argv) { Invoke-Cmd "dotnet pack $project $argv" } - function Get-DotNetRuntimeVersion { $info = dotnet-info @@ -44,12 +37,52 @@ function Get-DotNetRuntimeVersion $version.Split(":")[1].Trim() } -function dotnet-xunit ($project, $argv) +function Get-TargetFrameworks ($projFile) +{ + [xml]$proj = Get-Content $projFile + + if ($proj.Project.PropertyGroup.TargetFrameworks -ne $null) { + ($proj.Project.PropertyGroup.TargetFrameworks).Split(";") + } + else { + @($proj.Project.PropertyGroup.TargetFramework) + } +} + +function Get-NetCoreTargetFramework ($projFile) +{ + Get-TargetFrameworks $projFile | where { $_ -like "netstandard*" -or $_ -like "netcoreapp*" } +} + +function dotnet-info { Invoke-Cmd "dotnet --info" } +function dotnet-version { Invoke-Cmd "dotnet --version" } +function dotnet-run ($project, $argv) { Invoke-Cmd "dotnet run --project $project $argv" } +function dotnet-pack ($project, $argv) { Invoke-Cmd "dotnet pack $project $argv" } + +function dotnet-build ($project, $argv) +{ + if ($OnlyNetStandard.IsPresent) { + $fw = Get-NetCoreTargetFramework $project + $argv = "-f $fw " + $argv + } + + Invoke-Cmd "dotnet build $project $argv" +} + +function dotnet-test ($project, $argv) { - $fxversion = Get-DotNetRuntimeVersion - Push-Location (Get-Item $project).Directory.FullName - Invoke-Cmd "dotnet xunit -fxversion $fxversion $argv" - Pop-Location + # Currently dotnet test does not work for net461 on Linux/Mac + # See: https://github.com/Microsoft/vstest/issues/1318 + # + # Previously dotnet-xunit was a great alternative, however after + # issues with the maintenance dotnet xunit has been discontinued + # after xunit 2.4: https://xunit.github.io/releases/2.4 + if(!(Test-IsWindows) -or $OnlyNetStandard.IsPresent) { + $fw = Get-NetCoreTargetFramework $project; + $argv = "-f $fw " + $argv + } + + Invoke-Cmd "dotnet test $project $argv" } function Write-DotnetVersion @@ -108,26 +141,6 @@ function Remove-OldBuildArtifacts Remove-Item $_ -Recurse -Force } } -function Get-TargetFrameworks ($projFile) -{ - [xml]$proj = Get-Content $projFile - ($proj.Project.PropertyGroup.TargetFrameworks).Split(";") -} - -function Get-NetCoreTargetFramework ($projFile) -{ - Get-TargetFrameworks $projFile | where { $_ -like "netstandard*" -or $_ -like "netcoreapp*" } -} - -function Get-FrameworkArg ($projFile) -{ - if ($OnlyNetStandard.IsPresent) { - $fw = Get-NetCoreTargetFramework $projFile - "-f $fw" - } - else { "" } -} - # ---------------------------------------------- # Main # ---------------------------------------------- @@ -149,19 +162,13 @@ Remove-OldBuildArtifacts $configuration = if ($Release.IsPresent) { "Release" } else { "Debug" } Write-Host "Building Giraffe.TokenRouter..." -ForegroundColor Magenta -$framework = Get-FrameworkArg $src -dotnet-build $src "-c $configuration $framework" +dotnet-build $src "-c $configuration" if (!$ExcludeTests.IsPresent -and !$Run.IsPresent) { Write-Host "Building and running tests..." -ForegroundColor Magenta - $framework = Get-FrameworkArg $tests - - dotnet-build $tests $framework - - $xunitArgs = "" - if(!(Test-IsWindows)) { $tfw = Get-NetCoreTargetFramework $tests; $xunitArgs = "-framework $tfw" } - dotnet-xunit $tests $xunitArgs + dotnet-build $tests + dotnet-test $tests } if ($Pack.IsPresent) diff --git a/global.json b/global.json index a09404e..b11d921 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "projects": [ "src", "tests" ], "sdk": { - "version": "2.1.4" + "version": "2.1.400" } } \ No newline at end of file diff --git a/install-dotnet.ps1 b/install-dotnet.ps1 new file mode 100644 index 0000000..7f3770e --- /dev/null +++ b/install-dotnet.ps1 @@ -0,0 +1,88 @@ +# ---------------------------------------------------------- +# Install script to check and download the correct .NET SDK +# ---------------------------------------------------------- + +function Test-IsWindows +{ + [environment]::OSVersion.Platform -ne "Unix" +} + +function Invoke-Cmd ($cmd) +{ + Write-Host $cmd -ForegroundColor DarkCyan + if (Test-IsWindows) { $cmd = "cmd.exe /C $cmd" } + Invoke-Expression -Command $cmd + if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$cmd'."; return } +} + +function dotnet-version { Invoke-Cmd "dotnet --version" } + +function Get-DesiredSdk +{ + Get-Content "global.json" | ConvertFrom-Json | % { $_.sdk.version.ToString() } +} + +function Get-NetCoreSdk ($version) +{ + $os = if (Test-IsWindows) { "windows" } else { "linux" } + + $response = Invoke-WebRequest ` + -Uri "https://www.microsoft.com/net/download/thank-you/dotnet-sdk-$version-$os-x64-binaries" ` + -Method Get ` + -MaximumRedirection 0 ` + + $downloadLink = + $response.Links ` + | Where-Object { $_.onclick -eq "recordManualDownload()" } ` + | Select-Object -Expand href + + $tempFile = [System.IO.Path]::GetTempFileName() + $webClient = New-Object System.Net.WebClient + $webClient.DownloadFile($downloadLink, $tempFile) + return $tempFile +} + +function Install-NetCoreSdk ($sdkZipPath) +{ + $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetsdk" + New-Item $env:DOTNET_INSTALL_DIR -ItemType Directory -Force + + Add-Type -AssemblyName System.IO.Compression.FileSystem; + [System.IO.Compression.ZipFile]::ExtractToDirectory($sdkZipPath, $env:DOTNET_INSTALL_DIR) + $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" +} + +# ---------------------------------------------- +# Install .NET Core SDK +# ---------------------------------------------- + +$ErrorActionPreference = "Stop" + +# Rename the global.json before making the dotnet --version call +# This will prevent AppVeyor to fail because it might not find +# the desired SDK specified in the global.json +$globalJson = Get-Item "global.json" +Rename-Item -Path $globalJson.FullName -NewName "global.json.bak" -Force + +# Get the current .NET Core SDK version +$currentSdk = dotnet-version + +# After we established the current installed .NET SDK we can put the global.json back +Rename-Item -Path ($globalJson.FullName + ".bak") -NewName "global.json" -Force + +$desiredSdk = Get-DesiredSdk + +if ($desiredSdk -eq $currentSdk) +{ + Write-Host "The current .NET SDK matches the project's desired .NET SDK: $desiredSDK" -ForegroundColor Green + return +} + +Write-Host "The current .NET SDK ($currentSdk) doesn't match the project's desired .NET SDK ($desiredSdk)." -ForegroundColor Yellow +Write-Host "Attempting to download and install the correct .NET SDK..." + +$sdkZipPath = Get-NetCoreSdk $desiredSdk +Install-NetCoreSdk $sdkZipPath + +Write-Host ".NET SDK installation complete." -ForegroundColor Green +dotnet-version \ No newline at end of file diff --git a/src/Giraffe.TokenRouter/Giraffe.TokenRouter.fsproj b/src/Giraffe.TokenRouter/Giraffe.TokenRouter.fsproj index 82ae08a..d6d594b 100755 --- a/src/Giraffe.TokenRouter/Giraffe.TokenRouter.fsproj +++ b/src/Giraffe.TokenRouter/Giraffe.TokenRouter.fsproj @@ -1,16 +1,24 @@  Giraffe.TokenRouter - 0.1.0-beta-110 + 1.0.0 + net461;netstandard2.0 + + Alternative routing API for Giraffe web applications which is aimed at maximum performance. Copyright 2018 Dustin Moris Gorski - en-GB Dustin Moris Gorski and contributors - net461;netstandard2.0 + en-GB + + portable - 1 True Library + true + false + true + + Giraffe.TokenRouter Giraffe;TokenRouter;Routing;ASP.NET Core;FSharp;Functional;Http;Web;Framework;Micro;Service https://github.com/raw/giraffe-fsharp/Giraffe.TokenRouter/master/RELEASE_NOTES.md @@ -21,17 +29,10 @@ git https://github.com/giraffe-fsharp/Giraffe.TokenRouter true - 2.0 - false - - - - - - + diff --git a/tests/Giraffe.TokenRouter.Tests/Giraffe.TokenRouter.Tests.fsproj b/tests/Giraffe.TokenRouter.Tests/Giraffe.TokenRouter.Tests.fsproj index 1f010dd..0c32f29 100644 --- a/tests/Giraffe.TokenRouter.Tests/Giraffe.TokenRouter.Tests.fsproj +++ b/tests/Giraffe.TokenRouter.Tests/Giraffe.TokenRouter.Tests.fsproj @@ -1,31 +1,20 @@ - net461;netcoreapp2.0 + net461;netcoreapp2.1 Giraffe.TokenRouter.Tests portable - - - + + + - - - - - + + - - - - - - - - - + diff --git a/tests/Giraffe.TokenRouter.Tests/TokenRouterTests.fs b/tests/Giraffe.TokenRouter.Tests/TokenRouterTests.fs index adf04ae..78ea447 100644 --- a/tests/Giraffe.TokenRouter.Tests/TokenRouterTests.fs +++ b/tests/Giraffe.TokenRouter.Tests/TokenRouterTests.fs @@ -1496,6 +1496,7 @@ type DebugTests(output:ITestOutputHelper) = Assert.Equal(expected, body) } + [] member __.``Test routePorts function`` () = let ctx = Substitute.For() let notFound = (setStatusCode 404 >=> text "Not Found") @@ -1522,9 +1523,8 @@ type DebugTests(output:ITestOutputHelper) = let expected = "newpassword2" ctx.Request.Method.ReturnsForAnyArgs "POST" |> ignore - ctx.Request.Path.ReturnsForAnyArgs (PathString("/api/newpassword2")) |> ignore - ctx.Request.Host.Port.HasValue.ReturnsForAnyArgs true |> ignore - ctx.Request.Host.Port.Value.ReturnsForAnyArgs 9002 |> ignore + ctx.Request.Path.ReturnsForAnyArgs (PathString("/api2/newpassword2")) |> ignore + ctx.Request.Host.ReturnsForAnyArgs (HostString("", 9002)) |> ignore ctx.Response.Body <- new MemoryStream() task {