Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Aug 19, 2018
2 parents abd6573 + 06be900 commit 6c5df57
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 77 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
* text=auto
*.sh text eol=lf
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 48 additions & 41 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
# ----------------------------------------------
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"projects": [ "src", "tests" ],
"sdk": {
"version": "2.1.4"
"version": "2.1.400"
}
}
88 changes: 88 additions & 0 deletions install-dotnet.ps1
Original file line number Diff line number Diff line change
@@ -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
25 changes: 13 additions & 12 deletions src/Giraffe.TokenRouter/Giraffe.TokenRouter.fsproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Giraffe.TokenRouter</AssemblyName>
<Version>0.1.0-beta-110</Version>
<Version>1.0.0</Version>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>

<!-- General info -->
<Description>Alternative routing API for Giraffe web applications which is aimed at maximum performance.</Description>
<Copyright>Copyright 2018 Dustin Moris Gorski</Copyright>
<NeutralLanguage>en-GB</NeutralLanguage>
<Authors>Dustin Moris Gorski and contributors</Authors>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<NeutralLanguage>en-GB</NeutralLanguage>

<!-- Build config -->
<DebugType>portable</DebugType>
<WarningsAsErrors>1</WarningsAsErrors>
<Optimize>True</Optimize>
<OutputType>Library</OutputType>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<!-- NuGet package config -->
<PackageId>Giraffe.TokenRouter</PackageId>
<PackageTags>Giraffe;TokenRouter;Routing;ASP.NET Core;FSharp;Functional;Http;Web;Framework;Micro;Service</PackageTags>
<PackageReleaseNotes>https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.TokenRouter/master/RELEASE_NOTES.md</PackageReleaseNotes>
Expand All @@ -21,17 +29,10 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/giraffe-fsharp/Giraffe.TokenRouter</RepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<NetStandardImplicitPackageVersion>2.0</NetStandardImplicitPackageVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="2.0.*" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.0.*" />
<PackageReference Include="Giraffe" Version="1.1.*" />
<PackageReference Include="Giraffe" Version="2.0.*" />
</ItemGroup>

<ItemGroup>
Expand Down
25 changes: 7 additions & 18 deletions tests/Giraffe.TokenRouter.Tests/Giraffe.TokenRouter.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp2.1</TargetFrameworks>
<AssemblyName>Giraffe.TokenRouter.Tests</AssemblyName>
<DebugType>portable</DebugType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.*" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.*" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.*" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.*" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.*" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.*" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.*" />
<PackageReference Include="System.Net.Http" Version="4.3.*" />
<PackageReference Include="xunit" Version="2.3.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.*" />
<PackageReference Include="xunit" Version="2.4.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.*" />
<PackageReference Include="NSubstitute" Version="3.1.*" />
<PackageReference Include="FsCheck" Version="3.0.0-*" />
<PackageReference Include="FsCheck.Xunit" Version="3.0.0-*" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.*" />
<PackageReference Include="Giraffe" Version="1.1.*" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.*" />
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.*" />
<PackageReference Include="Giraffe" Version="2.0.*" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions tests/Giraffe.TokenRouter.Tests/TokenRouterTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,7 @@ type DebugTests(output:ITestOutputHelper) =
Assert.Equal(expected, body)
}

[<Fact>]
member __.``Test routePorts function`` () =
let ctx = Substitute.For<HttpContext>()
let notFound = (setStatusCode 404 >=> text "Not Found")
Expand All @@ -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 {
Expand Down

0 comments on commit 6c5df57

Please sign in to comment.