Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Dec 12, 2017
2 parents 25da3b3 + 4ce61d1 commit bb90d81
Show file tree
Hide file tree
Showing 14 changed files with 1,296 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,6 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs

# macOS
.DS_Store
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: csharp
sudo: required
dist: trusty

dotnet: 2.0.3
mono:
- 4.6.1
- 4.8.1
- 5.0.1

os:
- linux

before_install:
- curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
- 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

script:
- export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
- pwsh ./build.ps1 -Release
7 changes: 7 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,55 @@
# Giraffe.Tasks
A task computation expression to work natively with .NET's Tasks from an F# application.

![Giraffe](https://raw.githubusercontent.com/giraffe-fsharp/Giraffe/master/giraffe.png)

A task computation expression which works natively with .NET's Task objects from an F# application.

[![NuGet Info](https://buildstats.info/nuget/Giraffe.Tasks?includePreReleases=true)](https://www.nuget.org/packages/Giraffe.Tasks/)

| Windows | Linux |
| :------ | :---- |
| [![Windows Build status](https://ci.appveyor.com/api/projects/status/914030ec0lrc0vti/branch/develop?svg=true)](https://ci.appveyor.com/project/dustinmoris/giraffe-tasks/branch/develop) | [![Linux Build status](https://travis-ci.org/giraffe-fsharp/Giraffe.Tasks.svg?branch=develop)](https://travis-ci.org/giraffe-fsharp/Giraffe.Tasks/builds?branch=develop) |
| [![Windows Build history](https://buildstats.info/appveyor/chart/dustinmoris/giraffe-tasks?branch=develop&includeBuildsFromPullRequest=false)](https://ci.appveyor.com/project/dustinmoris/giraffe-tasks/history?branch=develop) | [![Linux Build history](https://buildstats.info/travisci/chart/giraffe-fsharp/Giraffe.Tasks?branch=develop&includeBuildsFromPullRequest=false)](https://travis-ci.org/giraffe-fsharp/Giraffe.Tasks/builds?branch=develop) |

## Table of contents

- [Documentation](#documentation)
- [More information](#more-information)
- [License](#license)

## Documentation

The `Giraffe.Tasks` NuGet package adds native support for .NET's `Task` and `Task<'T>` objects to an F# application. By using the `Giraffe.Tasks` module an ASP.NET Core/Giraffe web application can benefit of significant performance boosts by removing the necessity of manually converting between .NET's tasks and F#'s async workflows.

After opening the `Giraffe` or `Giraffe.Tasks` module you can use the `task {}` computation expression to work natively with .NET's tasks objects. It works syntactically almost identical to F#'s `async {}` workflow.

The original code has been taken from [Robert Peele](https://github.com/rspeele)'s [TaskBuilder.fs](https://github.com/rspeele/TaskBuilder.fs) and gradually modified to better fit Giraffe's use case for highly scalable ASP.NET Core web applications.

### Example:

```fsharp
open System.IO
open Giraffe.Tasks
// This function will return an object of type Task<string> instead of Async<string>
let readFileAndDoSomething (filePath : string) =
task {
use stream = new FileStream(filePath, FileMode.Open)
use reader = new StreamReader(stream)
let! contents = reader.ReadToEndAsync()
// do something with contents
return contents
}
```

The `task {}` computation expression also allows you to await an `Async<'T>` workflow without having to convert it into a `Task<'T>` beforehand.

## More information

For more information about Giraffe, how to set up a development environment, contribution guidelines and more please visit the [main documentation](https://github.com/giraffe-fsharp/Giraffe#table-of-contents) page.

## License

[Apache 2.0](https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.Tasks/master/LICENSE)
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Release Notes
=============

## 0.1.0-beta-010

- Moved `Giraffe.Tasks` from the `Giraffe` Nuget package into this repository.
24 changes: 24 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: 0.1.0-{build}
image: Visual Studio 2017
environment:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
init:
- git config --global core.autocrlf true
build: off
build_script:
- ps: .\build.ps1 -Release -Pack
test: off
artifacts:
- path: '**\Giraffe.*.nupkg'
name: Giraffe NuGet packages
nuget:
account_feed: false
project_feed: false
deploy:
provider: NuGet
api_key:
secure: +XDgIu4Tmln7LKedNmQgMFnyKTxxuCKFRK3V5oKEfwZiakPXRd5C7OueEGBL50oh
skip_symbols: false
artifact: /.*\.nupkg/
on:
appveyor_repo_tag: true
153 changes: 153 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# ----------------------------------------------
# Build script
# ----------------------------------------------

param
(
[switch] $Release,
[switch] $ExcludeTests,
[switch] $Pack,
[switch] $OnlyNetStandard,
[switch] $ClearOnly
)

$ErrorActionPreference = "Stop"

# ----------------------------------------------
# Helper functions
# ----------------------------------------------

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 Write-DotnetVersion
{
$dotnetVersion = Invoke-Cmd "dotnet --version"
Write-Host ".NET Core runtime version: $dotnetVersion" -ForegroundColor Cyan
}

function dotnet-restore ($project, $argv) { Invoke-Cmd "dotnet restore $project $argv" }
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 Test-Version ($project)
{
if ($env:APPVEYOR_REPO_TAG -eq $true)
{
Write-Host "Matching version against git tag..." -ForegroundColor Magenta

[xml] $xml = Get-Content $project
[string] $version = $xml.Project.PropertyGroup.Version
[string] $gitTag = $env:APPVEYOR_REPO_TAG_NAME

Write-Host "Project version: $version" -ForegroundColor Cyan
Write-Host "Git tag version: $gitTag" -ForegroundColor Cyan

if (!$gitTag.EndsWith($version))
{
Write-Error "Version and Git tag do not match."
}
}
}

function Update-AppVeyorBuildVersion ($project)
{
if ($env:APPVEYOR -eq $true)
{
Write-Host "Updating AppVeyor build version..." -ForegroundColor Magenta

[xml]$xml = Get-Content $project
$version = $xml.Project.PropertyGroup.Version
$buildVersion = "$version-$env:APPVEYOR_BUILD_NUMBER"
Write-Host "Setting AppVeyor build version to $buildVersion."
Update-AppveyorBuild -Version $buildVersion
}
}

function Remove-OldBuildArtifacts
{
Write-Host "Deleting old build artifacts..." -ForegroundColor Magenta

Get-ChildItem -Include "bin", "obj" -Recurse -Directory `
| ForEach-Object {
Write-Host "Removing folder $_" -ForegroundColor DarkGray
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
# ----------------------------------------------

if ($ClearOnly.IsPresent) {
Remove-OldBuildArtifacts
return
}

$giraffeTasks = ".\src\Giraffe.Tasks\Giraffe.Tasks.fsproj"
$giraffeTasksTests = ".\tests\Giraffe.Tasks.Tests\Giraffe.Tasks.Tests.fsproj"

Update-AppVeyorBuildVersion $giraffeTasks
Test-Version $giraffeTasks
Write-DotnetVersion
Remove-OldBuildArtifacts

$configuration = if ($Release.IsPresent) { "Release" } else { "Debug" }

Write-Host "Building Giraffe.Tasks..." -ForegroundColor Magenta
$framework = Get-FrameworkArg $giraffeTasks
dotnet-restore $giraffeTasks
dotnet-build $giraffeTasks "-c $configuration $framework"

if (!$ExcludeTests.IsPresent)
{
Write-Host "Building and running tests..." -ForegroundColor Magenta
$framework = Get-FrameworkArg $giraffeTasksTests
# Currently dotnet test does not work for net461 on Linux/Mac
# See: https://github.com/Microsoft/vstest/issues/1318
if (!(Test-IsWindows)) {
Write-Warning "Running tests only for .NET Core build, because dotnet test does not support net4x tests on Linux/Mac at the moment (see: https://github.com/Microsoft/vstest/issues/1318)."
$fw = Get-NetCoreTargetFramework $giraffeTasksTests
$framework = "-f $fw"
}
dotnet-restore $giraffeTasksTests
dotnet-build $giraffeTasksTests $framework
dotnet-test $giraffeTasksTests $framework
}

if ($Pack.IsPresent)
{
Write-Host "Packaging all NuGet packages..." -ForegroundColor Magenta
dotnet-pack $giraffeTasks "-c $configuration"
}
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/
pwsh ./build.ps1
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "tests" ],
"sdk": {
"version": "2.0.3"
}
}
32 changes: 32 additions & 0 deletions src/Giraffe.Tasks/Giraffe.Tasks.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Giraffe.Tasks</AssemblyName>
<Version>0.1.0-beta-010</Version>
<Description>A task computation expression which works natively with .NET's Task objects from an F# application.</Description>
<Copyright>Copyright 2017 Dustin Moris Gorski</Copyright>
<NeutralLanguage>en-GB</NeutralLanguage>
<Authors>Dustin Moris Gorski and contributors</Authors>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<DebugType>portable</DebugType>
<WarningsAsErrors>1</WarningsAsErrors>
<Optimize>True</Optimize>
<OutputType>Library</OutputType>
<PackageId>Giraffe.Tasks</PackageId>
<PackageTags>Giraffe;Tasks;Async;FSharp;Computation;Expression;Asynchronous</PackageTags>
<PackageReleaseNotes>https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.Tasks/master/RELEASE_NOTES.md</PackageReleaseNotes>
<PackageIconUrl>https://raw.githubusercontent.com/giraffe-fsharp/Giraffe/master/giraffe-64x64.png</PackageIconUrl>
<PackageProjectUrl>https://github.com/giraffe-fsharp/Giraffe.Tasks</PackageProjectUrl>
<PackageLicenseUrl>https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.Tasks/master/LICENSE</PackageLicenseUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/giraffe-fsharp/Giraffe.Tasks</RepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<NetStandardImplicitPackageVersion>2.0</NetStandardImplicitPackageVersion>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
<Compile Include="Tasks.fs" />
</ItemGroup>

</Project>
Loading

0 comments on commit bb90d81

Please sign in to comment.