diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c6eac55 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,83 @@ +name: .NET Core +on: + push: + pull_request: + release: + types: + - published +env: + PROJECT_NAME: Giraffe.Razor + GITHUB_SOURCE: https://nuget.pkg.github.com/giraffe-fsharp/ + GITHUB_USER: dustinmoris + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NUGET_KEY: ${{ secrets.NUGET_KEY }} +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.301 + - name: Restore + run: dotnet restore + - name: Build + run: dotnet build --configuration Release --no-restore + - name: Test + run: dotnet test --configuration Release + - name: Pack + if: matrix.os == 'ubuntu-latest' + run: dotnet pack --configuration Release --no-restore --verbosity normal --include-symbols --include-source -p:PackageVersion=$GITHUB_RUN_ID src/$PROJECT_NAME/$PROJECT_NAME.*proj + - name: Upload Artifact + if: matrix.os == 'ubuntu-latest' + uses: actions/upload-artifact@v2 + with: + name: nupkg + path: ./src/${{ env.PROJECT_NAME }}/bin/Release/*.nupkg + prerelease: + needs: build + if: github.ref == 'refs/heads/develop' + runs-on: ubuntu-latest + steps: + - name: Download Artifact + uses: actions/download-artifact@v1 + with: + name: nupkg + - name: Push Pre-Release NuGet + run: | + for f in ./nupkg/*.nupkg + do + curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_SOURCE + done + shell: bash + deploy: + needs: build + if: github.event_name == 'release' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 3.1.301 + - name: Create Release NuGet package + run: | + arrTag=(${GITHUB_REF//\// }) + VERSION="${arrTag[2]}" + echo Version: $VERSION + VERSION="${VERSION//v}" + echo Clean Version: $VERSION + dotnet pack --configuration Release --verbosity normal --include-symbols --include-source -p:PackageVersion=$VERSION -o nupkg src/$PROJECT_NAME/$PROJECT_NAME.*proj + - name: Push to GitHub Feed + run: | + for f in ./nupkg/*.nupkg + do + curl -vX PUT -u "$GITHUB_USER:$GITHUB_TOKEN" -F package=@$f $GITHUB_SOURCE + done + shell: bash + - name: Push to NuGet Feed + run: dotnet nuget push nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --skip-duplicate --api-key $NUGET_KEY \ No newline at end of file diff --git a/.psscripts/build-functions.ps1 b/.psscripts/build-functions.ps1 deleted file mode 100644 index c6bc517..0000000 --- a/.psscripts/build-functions.ps1 +++ /dev/null @@ -1,405 +0,0 @@ -# ---------------------------------------------- -# Generic functions -# ---------------------------------------------- - -function Test-IsWindows -{ - <# - .DESCRIPTION - Checks to see whether the current environment is Windows or not. - - .EXAMPLE - if (Test-IsWindows) { Write-Host "Hello Windows" } - #> - - [environment]::OSVersion.Platform -ne "Unix" -} - -function Test-IsMonoInstalled -{ - <# - .DESCRIPTION - Checks to see whether the current environment has the Mono framework installed. - - .EXAMPLE - if (Test-IsMonoInstalled) { Write-Host "Mono is available." } - #> - - try - { - $result = Invoke-Cmd "mono --version" -Silent - return $result.StartsWith("Mono JIT compiler version") - } - catch { return false } -} - -function Get-UbuntuVersion -{ - <# - .DESCRIPTION - Gets the Ubuntu version. - - .EXAMPLE - $ubuntuVersion = Get-UbuntuVersion - #> - - $version = Invoke-Cmd "lsb_release -r -s" -Silent - return $version -} - -function Invoke-UnsafeCmd ( - [string] $Cmd, - [switch] $Silent) -{ - <# - .DESCRIPTION - Runs a shell or bash command, but doesn't throw an error if the command didn't exit with 0. - - .PARAMETER cmd - The command to be executed. - - .EXAMPLE - Invoke-Cmd -Cmd "dotnet new classlib" - - .NOTES - Use this PowerShell command to execute any CLI commands which might not exit with 0 on a success. - #> - - if (!($Silent.IsPresent)) { Write-Host $cmd -ForegroundColor DarkCyan } - if (Test-IsWindows) { $cmd = "cmd.exe /C $cmd" } - Invoke-Expression -Command $cmd -} - -function Invoke-Cmd ( - [string] $Cmd, - [switch] $Silent) -{ - <# - .DESCRIPTION - Runs a shell or bash command and throws an error if the command didn't exit with 0. - - .PARAMETER cmd - The command to be executed. - - .EXAMPLE - Invoke-Cmd -Cmd "dotnet new classlib" - - .NOTES - Use this PowerShell command to execute any dotnet CLI commands in order to ensure that they behave the same way in the case of an error across different environments (Windows, OSX and Linux). - #> - - if ($Silent.IsPresent) { Invoke-UnsafeCmd $cmd -Silent } else { Invoke-UnsafeCmd $cmd } - if ($LastExitCode -ne 0) { Write-Error "An error occured when executing '$Cmd'."; return } -} - -function Remove-OldBuildArtifacts -{ - <# - .DESCRIPTION - Deletes all the bin and obj folders from the current- and all sub directories. - #> - - 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-ProjectVersion ($projFile) -{ - <# - .DESCRIPTION - Gets the value of a .NET Core *.csproj, *.fsproj or *.vbproj file. - - .PARAMETER cmd - The relative or absolute path to the .NET Core project file. - #> - - [xml]$xml = Get-Content $projFile - [string] $version = $xml.Project.PropertyGroup.Version - $version -} - -function Get-NuspecVersion ($nuspecFile) -{ - <# - .DESCRIPTION - Gets the value of a .nuspec file. - - .PARAMETER cmd - The relative or absolute path to the .nuspec file. - #> - - [xml] $xml = Get-Content $nuspecFile - [string] $version = $xml.package.metadata.version - $version -} - -function Test-CompareVersions ($version, [string]$gitTag) -{ - Write-Host "Matching version against git tag..." -ForegroundColor Magenta - 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 Add-ToPathVariable ($path) -{ - if (Test-IsWindows) - { - $updatedPath = "$path;$env:Path" - [Environment]::SetEnvironmentVariable("Path", $updatedPath, "Process") - [Environment]::SetEnvironmentVariable("Path", $updatedPath, "User") - [Environment]::SetEnvironmentVariable("Path", $updatedPath, "Machine") - } - else - { - $updatedPath = "$path`:$env:PATH" - [Environment]::SetEnvironmentVariable("PATH", $updatedPath, "Process") - [Environment]::SetEnvironmentVariable("PATH", $updatedPath, "User") - [Environment]::SetEnvironmentVariable("PATH", $updatedPath, "Machine") - } -} - -# ---------------------------------------------- -# .NET Core functions -# ---------------------------------------------- - -function Get-TargetFrameworks ($projFile) -{ - <# - .DESCRIPTION - Returns all target frameworks set up inside a specific .NET Core project file. - - .PARAMETER projFile - The full or relative path to a .NET Core project file (*.csproj, *.fsproj, *.vbproj). - - .EXAMPLE - Get-TargetFrameworks "MyProject.csproj" - - .NOTES - This function will always return an array of target frameworks, even if only a single target framework was found in the project file. - #> - - [xml]$proj = Get-Content $projFile - - if ($null -ne $proj.Project.PropertyGroup.TargetFrameworks) { - ($proj.Project.PropertyGroup.TargetFrameworks).Split(";") - } - else { @($proj.Project.PropertyGroup.TargetFramework) } -} - -function Get-NetCoreTargetFramework ($projFile) -{ - <# - .DESCRIPTION - Returns a single .NET Core framework which could be found among all configured target frameworks of a given .NET Core project file. - - .PARAMETER projFile - The full or relative path to a .NET Core project file (*.csproj, *.fsproj, *.vbproj). - - .EXAMPLE - Get-NetCoreTargetFramework "MyProject.csproj" - - .NOTES - This function will always return the only netstandard*/netcoreapp* target framework which is set up as a target framework. - #> - - Get-TargetFrameworks $projFile | Where-Object { $_ -like "netstandard*" -or $_ -like "netcoreapp*" } -} - -function Invoke-DotNetCli ($cmd, $proj, $argv) -{ - # Currently dotnet test does not work for net461 on Linux/Mac - # See: https://github.com/Microsoft/vstest/issues/1318 - - if((!(Test-IsWindows) -and !(Test-IsMonoInstalled)) ` - -or (!(Test-IsWindows) -and ($cmd -eq "test"))) - { - $fw = Get-NetCoreTargetFramework($proj) - $argv = "-f $fw " + $argv - } - Invoke-Cmd "dotnet $cmd $proj $argv" -} - -function dotnet-info { Invoke-Cmd "dotnet --info" -Silent } -function dotnet-version { Invoke-Cmd "dotnet --version" -Silent } -function dotnet-restore ($project, $argv) { Invoke-Cmd "dotnet restore $project $argv" } -function dotnet-build ($project, $argv) { Invoke-DotNetCli -Cmd "build" -Proj $project -Argv $argv } -function dotnet-test ($project, $argv) { Invoke-DotNetCli -Cmd "test" -Proj $project -Argv $argv } -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-publish ($project, $argv) { Invoke-Cmd "dotnet publish $project $argv" } - -function Get-DotNetRuntimeVersion -{ - <# - .DESCRIPTION - Runs the dotnet --info command and extracts the .NET Core Runtime version number. - - .NOTES - The .NET Core Runtime version can sometimes be useful for other dotnet CLI commands (e.g. dotnet xunit -fxversion ".NET Core Runtime version"). - #> - - $info = dotnet-info - [System.Array]::Reverse($info) - $version = $info | Where-Object { $_.Contains("Version") } | Select-Object -First 1 - $version.Split(":")[1].Trim() -} - -function Write-DotnetCoreVersions -{ - <# - .DESCRIPTION - Writes the .NET Core SDK and Runtime version to the current host. - #> - - $sdkVersion = dotnet-version - $runtimeVersion = Get-DotNetRuntimeVersion - Write-Host ".NET Core SDK version: $sdkVersion" -ForegroundColor Cyan - Write-Host ".NET Core Runtime version: $runtimeVersion" -ForegroundColor Cyan -} - -function Get-DesiredSdk -{ - <# - .DESCRIPTION - Gets the desired .NET Core SDK version from the global.json file. - #> - - Get-Content "global.json" ` - | ConvertFrom-Json ` - | ForEach-Object { $_.sdk.version.ToString() } -} - -function Get-NetCoreSdkFromWeb ($version) -{ - <# - .DESCRIPTION - Downloads the desired .NET Core SDK version from the internet and saves it under a temporary file name which will be returned by the function. - - .PARAMETER version - The SDK version which should be downloaded. - #> - - Write-Host "Downloading .NET Core SDK $version..." - - $os = if (Test-IsWindows) { "windows" } else { "linux" } - $ext = if (Test-IsWindows) { ".zip" } else { ".tar.gz" } - $uri = "https://www.microsoft.com/net/download/thank-you/dotnet-sdk-$version-$os-x64-binaries" - Write-Host "Finding download link..." - - $response = Invoke-WebRequest -Uri $uri - - $downloadLink = - $response.Links ` - | Where-Object { $_.onclick -eq "recordManualDownload()" } ` - | Select-Object -Expand href - - Write-Host "Creating temporary file..." - - $tempFile = [System.IO.Path]::GetTempFileName() + $ext - - $webClient = New-Object System.Net.WebClient - $webClient.DownloadFile($downloadLink, $tempFile) - - Write-Host "Download finished. SDK has been saved to '$tempFile'." - - return $tempFile -} - -function Install-NetCoreSdkFromArchive ($sdkArchivePath) -{ - <# - .DESCRIPTION - Extracts the zip archive which contains the .NET Core SDK and installs it in the current working directory under .dotnetsdk. - - .PARAMETER version - The zip archive which contains the .NET Core SDK. - #> - - if (Test-IsWindows) - { - $dotnetInstallDir = [System.IO.Path]::Combine($pwd, ".dotnetsdk") - New-Item $dotnetInstallDir -ItemType Directory -Force | Out-Null - Write-Host "Created folder '$dotnetInstallDir'." - Expand-Archive -LiteralPath $sdkArchivePath -DestinationPath $dotnetInstallDir -Force - Write-Host "Extracted '$sdkArchivePath' to folder '$dotnetInstallDir'." - } - else - { - $dotnetInstallDir = "$env:HOME/.dotnetsdk" - Invoke-Cmd "mkdir -p $dotnetInstallDir" - Write-Host "Created folder '$dotnetInstallDir'." - Invoke-Cmd "tar -xf $sdkArchivePath -C $dotnetInstallDir" - Write-Host "Extracted '$sdkArchivePath' to folder '$dotnetInstallDir'." - } - - Add-ToPathVariable $dotnetInstallDir - Write-Host "Added '$dotnetInstallDir' to the PATH environment variable:" - Write-Host $env:PATH -} - -function Install-NetCoreSdkForUbuntu ($ubuntuVersion, $sdkVersion) -{ - Invoke-Cmd "wget -q https://packages.microsoft.com/config/ubuntu/$ubuntuVersion/packages-microsoft-prod.deb" - Invoke-Cmd "sudo dpkg -i packages-microsoft-prod.deb" - Invoke-Cmd "sudo apt-get install apt-transport-https" - Invoke-Cmd "sudo apt-get update" - Invoke-Cmd "sudo apt-get -y install dotnet-sdk-$sdkVersion" -} - -# ---------------------------------------------- -# AppVeyor functions -# ---------------------------------------------- - -function Test-IsAppVeyorBuild { return ($env:APPVEYOR -eq $true) } -function Test-IsAppVeyorBuildTriggeredByGitTag { return ($env:APPVEYOR_REPO_TAG -eq $true) } -function Get-AppVeyorGitTag { return $env:APPVEYOR_REPO_TAG_NAME } - -function Update-AppVeyorBuildVersion ($version) -{ - if (Test-IsAppVeyorBuild) - { - Write-Host "Updating AppVeyor build version..." -ForegroundColor Magenta - $buildVersion = "$version-$env:APPVEYOR_BUILD_NUMBER" - Write-Host "Setting AppVeyor build version to $buildVersion." - Update-AppveyorBuild -Version $buildVersion - } -} - -# ---------------------------------------------- -# Host Writing functions -# ---------------------------------------------- - -function Write-BuildHeader ($projectTitle) -{ - $header = " $projectTitle "; - $bar = "" - for ($i = 0; $i -lt $header.Length; $i++) { $bar += "-" } - - Write-Host "" - Write-Host $bar -ForegroundColor DarkYellow - Write-Host $header -ForegroundColor DarkYellow - Write-Host $bar -ForegroundColor DarkYellow - Write-Host "" -} - -function Write-SuccessFooter ($msg) -{ - $footer = " $msg "; - $bar = "" - for ($i = 0; $i -lt $footer.Length; $i++) { $bar += "-" } - - Write-Host "" - Write-Host $bar -ForegroundColor Green - Write-Host $footer -ForegroundColor Green - Write-Host $bar -ForegroundColor Green - Write-Host "" -} \ No newline at end of file diff --git a/.psscripts/install-dotnet.ps1 b/.psscripts/install-dotnet.ps1 deleted file mode 100644 index c43c50f..0000000 --- a/.psscripts/install-dotnet.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -# ---------------------------------------------- -# Install .NET Core SDK -# ---------------------------------------------- - -param -( - [switch] $ForceUbuntuInstall -) - -$ErrorActionPreference = "Stop" - -Import-module "$PSScriptRoot\build-functions.ps1" -Force - -if ($ForceUbuntuInstall.IsPresent) -{ - $desiredSdk = Get-DesiredSdk - $versionParts = $desiredSdk.Split(".") - $majorMinorVer = $versionParts[0] + "." + $versionParts[1] - $ubuntuVersion = Get-UbuntuVersion - - Write-Host "Ubuntu version: $ubuntuVersion" - Install-NetCoreSdkForUbuntu $ubuntuVersion $majorMinorVer - return -} - -# 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 "$PSScriptRoot\..\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-NetCoreSdkFromWeb $desiredSdk -Install-NetCoreSdkFromArchive $sdkZipPath - -Write-Host ".NET SDK installation complete." -ForegroundColor Green -dotnet-version \ No newline at end of file diff --git a/.psscripts/nuget-updates.ps1 b/.psscripts/nuget-updates.ps1 deleted file mode 100644 index c00e69a..0000000 --- a/.psscripts/nuget-updates.ps1 +++ /dev/null @@ -1,61 +0,0 @@ -# ---------------------------------------------- -# Helper script to find NuGet package upgrades -# ---------------------------------------------- - -function Get-NuGetPackageInfo ($nugetPackageId, $currentVersion) -{ - $url = "https://api-v2v3search-0.nuget.org/query?q=$nugetPackageId&prerelease=false" - $result = Invoke-RestMethod -Uri $url -Method Get - $latestVersion = $result.data[0].version - $upgradeAvailable = $currentVersion -and !$latestVersion.StartsWith($currentVersion.Replace("*", "")) - - [PSCustomObject]@{ - PackageName = $nugetPackageId; - Current = $currentVersion; - Latest = $latestVersion; - UpgradeAvailable = $upgradeAvailable - } -} - -filter Highlight-Upgrades -{ - $lines = $_.Split([Environment]::NewLine) - foreach ($line in $lines) { - if ($line.Trim().EndsWith("True")) { - Write-Host $line -ForegroundColor DarkGreen - } else { - Write-Host $line -ForegroundColor Gray - } - } -} - -Write-Host "" -Write-Host "" -Write-Host "--------------------------------------------------" -ForegroundColor DarkYellow -Write-Host " Scanning all projects for NuGet package upgrades " -ForegroundColor DarkYellow -Write-Host "--------------------------------------------------" -ForegroundColor DarkYellow -Write-Host "" - -$projects = Get-ChildItem "$PSScriptRoot\..\**\*.*proj" -Recurse | % { $_.FullName } - -foreach ($project in $projects) -{ - $projName = Split-Path $project -Leaf - Write-Host $projName -ForegroundColor Magenta - - [xml]$proj = Get-Content $project - $references = $proj.Project.ItemGroup.PackageReference | Where-Object { $_.Include -ne $null } - $packages = @() - - foreach ($reference in $references) - { - $id = $reference.Include - $version = $reference.Version - $packages += Get-NuGetPackageInfo $id $version - } - - $packages ` - | Format-Table -Property PackageName, Current, Latest, UpgradeAvailable -AutoSize ` - | Out-String ` - | Highlight-Upgrades -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1e96f5f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: csharp -sudo: required -dist: trusty - -dotnet: 2.2.105 -mono: - - 4.6.1 - - 4.8.1 - - 5.18.0 -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 - - sudo pwsh ./.psscripts/install-dotnet.ps1 - -script: - - export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/ - - pwsh ./build.ps1 -Release \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..d2ecab7 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at giraffe@dusted.codes. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/Giraffe.Razor.sln b/Giraffe.Razor.sln new file mode 100644 index 0000000..077aa62 --- /dev/null +++ b/Giraffe.Razor.sln @@ -0,0 +1,68 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{03CCBA43-B6F5-4FA7-8C18-432BB07225FC}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Giraffe.Razor", "src\Giraffe.Razor\Giraffe.Razor.fsproj", "{9B52367B-CC80-452E-9062-7583995BFAC0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E067A6B8-538E-4362-83C2-9ECBC486AC31}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "GiraffeRazorSample", "samples\GiraffeRazorSample\GiraffeRazorSample.fsproj", "{14818084-9969-4F42-8A66-394FC6670B50}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_root", "_root", "{73E09F74-F64D-4C42-92FC-19731C0C5553}" +ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + .gitattributes = .gitattributes + LICENSE = LICENSE + NuGet.config = NuGet.config + README.md = README.md + RELEASE_NOTES.md = RELEASE_NOTES.md + giraffe-64x64.png = giraffe-64x64.png + CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md +EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {9B52367B-CC80-452E-9062-7583995BFAC0} = {03CCBA43-B6F5-4FA7-8C18-432BB07225FC} + {14818084-9969-4F42-8A66-394FC6670B50} = {E067A6B8-538E-4362-83C2-9ECBC486AC31} + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|x64.ActiveCfg = Debug|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|x64.Build.0 = Debug|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|x86.ActiveCfg = Debug|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Debug|x86.Build.0 = Debug|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Release|Any CPU.Build.0 = Release|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Release|x64.ActiveCfg = Release|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Release|x64.Build.0 = Release|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Release|x86.ActiveCfg = Release|Any CPU + {9B52367B-CC80-452E-9062-7583995BFAC0}.Release|x86.Build.0 = Release|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Debug|x64.ActiveCfg = Debug|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Debug|x64.Build.0 = Debug|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Debug|x86.ActiveCfg = Debug|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Debug|x86.Build.0 = Debug|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Release|Any CPU.Build.0 = Release|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Release|x64.ActiveCfg = Release|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Release|x64.Build.0 = Release|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Release|x86.ActiveCfg = Release|Any CPU + {14818084-9969-4F42-8A66-394FC6670B50}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md index 359f298..93629da 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ Razor view engine support for the [Giraffe](https://github.com/giraffe-fsharp/Gi [![NuGet Info](https://buildstats.info/nuget/Giraffe.Razor?includePreReleases=true)](https://www.nuget.org/packages/Giraffe.Razor/) -### Windows and Linux Builds +### Linux, macOS and Windows Build Status -[![Windows Build status](https://ci.appveyor.com/api/projects/status/914030ec0lrc0vti/branch/develop?svg=true)](https://ci.appveyor.com/project/dustinmoris/giraffe-razor/branch/develop) +![.NET Core](https://github.com/giraffe-fsharp/Giraffe.Razor/workflows/.NET%20Core/badge.svg?branch=develop) -[![Windows Build history](https://buildstats.info/appveyor/chart/dustinmoris/giraffe-razor?branch=develop&includeBuildsFromPullRequest=false&buildCount=40)](https://ci.appveyor.com/project/dustinmoris/giraffe-razor/history?branch=develop) +[![Build history](https://buildstats.info/github/chart/giraffe-fsharp/Giraffe.Razor?branch=develop&includeBuildsFromPullRequest=false)](https://github.com/giraffe-fsharp/Giraffe.Razor/actions?query=branch%3Adevelop++) ## Table of contents @@ -153,15 +153,13 @@ Please find a fully functioning sample application under [./samples/GiraffeRazor ## Nightly builds and NuGet feed -All official Giraffe packages are published to the official and public NuGet feed. +All official release packages are published to the official and public NuGet feed. -Unofficial builds (such as pre-release builds from the `develop` branch and pull requests) produce unofficial pre-release NuGet packages which can be pulled from the project's public NuGet feed on AppVeyor: +Nightly builds (builds from the `develop` branch) produce unofficial pre-release packages which can be pulled from the [project's NuGet feed on GitHub](https://github.com/orgs/giraffe-fsharp/packages). -``` -https://ci.appveyor.com/nuget/giraffe-razor -``` +These packages are being tagged with the Workflow's run number as the package version. -If you add this source to your NuGet CLI or project settings then you can pull unofficial NuGet packages for quick feature testing or urgent hot fixes. +All other builds, such as builds triggered by pull requests produce a NuGet package which can be downloaded as an artifact from the individual GitHub action. ## More information diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 9d814bf..5ee9ba4 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,11 @@ Release Notes ============= +## 5.0.0 + +- Dropped support for all .NET framework monikers except .NET Core 3.1 (in preparation for the .NET 5 release) +- Added support for `IModelMetadataProvider` + ## 4.0.0 #### Breaking changes & Bug fixes diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index d264aed..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: 0.1.0-{build} -image: - - Visual Studio 2017 - - Ubuntu -environment: - DOTNET_CLI_TELEMETRY_OPTOUT: 1 -init: - - git config --global core.autocrlf true -install: - - sh: export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/ - - ps: .\.psscripts\install-dotnet.ps1 -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: true -deploy: - provider: NuGet - api_key: - secure: +XDgIu4Tmln7LKedNmQgMFnyKTxxuCKFRK3V5oKEfwZiakPXRd5C7OueEGBL50oh - skip_symbols: false - artifact: /.*\.nupkg/ - on: - appveyor_repo_tag: true \ No newline at end of file diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index d03b084..0000000 --- a/build.ps1 +++ /dev/null @@ -1,64 +0,0 @@ -# ---------------------------------------------- -# Build script -# ---------------------------------------------- - -param -( - [switch] $Release, - [switch] $ExcludeSamples, - [switch] $Pack, - [switch] $Run, - [switch] $OnlyNetStandard -) - -# ---------------------------------------------- -# Main -# ---------------------------------------------- - -$ErrorActionPreference = "Stop" - -Import-module "$PSScriptRoot/.psscripts/build-functions.ps1" -Force - -Write-BuildHeader "Starting Giraffe.Razor build script" - -$giraffeRazor = "./src/Giraffe.Razor/Giraffe.Razor.fsproj" -$sampleApp = "./samples/GiraffeRazorSample/GiraffeRazorSample.fsproj" - -$version = Get-ProjectVersion $giraffeRazor -Update-AppVeyorBuildVersion $version - -if (Test-IsAppVeyorBuildTriggeredByGitTag) -{ - $gitTag = Get-AppVeyorGitTag - Test-CompareVersions $version $gitTag -} - -Write-DotnetCoreVersions - -Remove-OldBuildArtifacts - -$configuration = if ($Release.IsPresent) { "Release" } else { "Debug" } - -Write-Host "Building Giraffe.Razor..." -ForegroundColor Magenta -dotnet-build $giraffeRazor "-c $configuration" - -if (!$ExcludeSamples.IsPresent -and !$Run.IsPresent) -{ - Write-Host "Building and testing samples..." -ForegroundColor Magenta - dotnet-build $sampleApp -} - -if ($Run.IsPresent) -{ - Write-Host "Launching sample application..." -ForegroundColor Magenta - dotnet-build $sampleApp - dotnet-run $sampleApp -} - -if ($Pack.IsPresent) -{ - Write-Host "Packaging all NuGet packages..." -ForegroundColor Magenta - dotnet-pack $giraffeRazor "-c $configuration" -} - -Write-SuccessFooter "Giraffe.Razor build completed successfully!" \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100755 index b8e46ef..0000000 --- a/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -export FrameworkPathOverride=$(dirname $(which mono))/../lib/mono/4.5/ -pwsh ./build.ps1 \ No newline at end of file diff --git a/giraffe-64x64.png b/giraffe-64x64.png new file mode 100644 index 0000000..40ed5e3 Binary files /dev/null and b/giraffe-64x64.png differ diff --git a/global.json b/global.json deleted file mode 100644 index be85bb7..0000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ "src", "tests" ], - "sdk": { - "version": "2.2.105" - } -} \ No newline at end of file diff --git a/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj b/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj index 1613c2d..e2c5ad8 100644 --- a/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj +++ b/samples/GiraffeRazorSample/GiraffeRazorSample.fsproj @@ -1,19 +1,13 @@ - netcoreapp2.2 - portable + netcoreapp3.1 GiraffeRazorSample - Exe GiraffeRazorSample false $(MSBuildThisFileDirectory) - - - - diff --git a/samples/GiraffeRazorSample/Program.fs b/samples/GiraffeRazorSample/Program.fs index 61d487e..b33bc38 100644 --- a/samples/GiraffeRazorSample/Program.fs +++ b/samples/GiraffeRazorSample/Program.fs @@ -37,7 +37,7 @@ type CreatePerson = // --------------------------------- let antiforgeryTokenHandler = - text "Bad antiforgery token" + text "Bad antiforgery token" |> RequestErrors.badRequest |> validateAntiforgeryToken @@ -146,7 +146,8 @@ let configureApp (app : IApplicationBuilder) = let configureServices (services : IServiceCollection) = let sp = services.BuildServiceProvider() - let env = sp.GetService() + let env = sp.GetService() + services.AddGiraffe() |> ignore Path.Combine(env.ContentRootPath, "Views") |> services.AddRazorEngine |> ignore diff --git a/src/Giraffe.Razor/Giraffe.Razor.fsproj b/src/Giraffe.Razor/Giraffe.Razor.fsproj index af594ca..557c5ac 100755 --- a/src/Giraffe.Razor/Giraffe.Razor.fsproj +++ b/src/Giraffe.Razor/Giraffe.Razor.fsproj @@ -2,14 +2,13 @@ Giraffe.Razor - 4.0.0 Razor view engine support for the Giraffe web framework. - Copyright 2018 Dustin Moris Gorski + Copyright 2020 Dustin Moris Gorski Dustin Moris Gorski and contributors en-GB - netstandard2.0;net461 + netcoreapp3.1 portable Library true @@ -21,9 +20,9 @@ Giraffe.Razor Giraffe;Razor;ASP.NET Core;Lambda;FSharp;Functional;Http;Web;Framework;Micro;Service https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.Razor/master/RELEASE_NOTES.md - https://raw.githubusercontent.com/giraffe-fsharp/Giraffe/master/giraffe-64x64.png + giraffe-64x64.png https://github.com/giraffe-fsharp/Giraffe.Razor - https://raw.githubusercontent.com/giraffe-fsharp/Giraffe.Razor/master/LICENSE + Apache-2.0 true git https://github.com/giraffe-fsharp/Giraffe.Razor @@ -36,13 +35,15 @@ - - - - - - - + + true + $(PackageIconUrl) + + + + + + diff --git a/src/Giraffe.Razor/HttpHandlers.fs b/src/Giraffe.Razor/HttpHandlers.fs index a5f5ec1..bd3c20b 100644 --- a/src/Giraffe.Razor/HttpHandlers.fs +++ b/src/Giraffe.Razor/HttpHandlers.fs @@ -25,9 +25,10 @@ module HttpHandlers = (modelState : ModelStateDictionary option) : HttpHandler = fun (next : HttpFunc) (ctx : HttpContext) -> task { + let metadataProvider = ctx.RequestServices.GetService() let engine = ctx.RequestServices.GetService() let tempDataDict = ctx.RequestServices.GetService().GetTempData ctx - let! result = renderView engine tempDataDict ctx viewName model viewData modelState + let! result = renderView engine metadataProvider tempDataDict ctx viewName model viewData modelState match result with | Error msg -> return (failwith msg) | Ok output -> diff --git a/src/Giraffe.Razor/Middleware.fs b/src/Giraffe.Razor/Middleware.fs index 59cc473..c587e03 100644 --- a/src/Giraffe.Razor/Middleware.fs +++ b/src/Giraffe.Razor/Middleware.fs @@ -3,20 +3,19 @@ namespace Giraffe.Razor [] module Middleware = - open Microsoft.AspNetCore.Mvc.Razor + open Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.FileProviders type IServiceCollection with - member this.AddRazorEngine (viewsFolderPath : string) = - this.Configure( - fun (options : RazorViewEngineOptions) -> - options.FileProviders.Clear() - options.FileProviders.Add(new PhysicalFileProvider(viewsFolderPath))) - .AddMvc() + + member this.AddRazorEngine(viewsFolderPath: string) = + this.Configure(fun (options: MvcRazorRuntimeCompilationOptions) -> + options.FileProviders.Clear() + options.FileProviders.Add(new PhysicalFileProvider(viewsFolderPath))).AddMvc().AddRazorRuntimeCompilation() |> ignore this.AddAntiforgery() member this.AddRazorEngine() = - this.AddMvc() |> ignore + this.AddMvc().AddRazorRuntimeCompilation() |> ignore this.AddAntiforgery() diff --git a/src/Giraffe.Razor/RazorEngine.fs b/src/Giraffe.Razor/RazorEngine.fs index 18492ce..d3dfc9c 100644 --- a/src/Giraffe.Razor/RazorEngine.fs +++ b/src/Giraffe.Razor/RazorEngine.fs @@ -44,6 +44,7 @@ module RazorEngine = routeData let renderView (razorViewEngine : IRazorViewEngine) + (modelMetadataProvider: IModelMetadataProvider) (tempDataDict : ITempDataDictionary) (httpContext : HttpContext) (viewName : string) @@ -67,7 +68,7 @@ module RazorEngine = let viewModelState = defaultArg modelState (ModelStateDictionary()) let viewDataDict = ViewDataDictionary<'T>( - EmptyModelMetadataProvider(), + modelMetadataProvider, viewModelState, Model = viewModel) if (viewData.IsSome) then