diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000000..b4a194bc58 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,116 @@ +name: Build + +on: + push: + branches: + - master + tags: + - 'v*' + pull_request: + branches: + - master + +jobs: + Coverage: + runs-on: windows-latest + needs: [Build] + steps: + - uses: actions/checkout@v1 + + - name: Enable long file paths + run: git config --global core.longpaths true + + - name: Update submodules + run: git submodule -q update --init + + - name: Generate Test Coverage + shell: pwsh + run: ./tests/CodeCoverage/CodeCoverage.ps1 + env: + CI : True + + - name: Update codecov + uses: iansu/codecov-action-node@v1.0.0 + with: + token: ${{secrets.CODECOV_TOKEN}} + file: "ImageSharp.Coverage.xml" + flags: unittests + + Build: + strategy: + matrix: + options: + - os : ubuntu-latest + framework: netcoreapp2.1 + is32Bit: False + - os : windows-latest + framework: netcoreapp2.1 + is32Bit: False + - os : windows-latest + framework: net472 + is32Bit: False + - os : windows-latest + framework: net472 + is32Bit: True + + runs-on: ${{ matrix.options.os }} + + steps: + - uses: actions/checkout@v1 + + - name: Enable long file paths + run: | + git config --global core.autocrlf false + git config --global core.longpaths true + + - name: Update submodules + run: git submodule -q update --init + + - name: Build + shell: pwsh + run: | + $DebugPreference = "Continue" + ./build.ps1 "${{matrix.options.framework}}" + + - name: Test + shell: pwsh + run: ./run-tests.ps1 "${{matrix.options.framework}}" "${{matrix.options.is32Bit}}" true + env: + CI : True + + Publish: + runs-on: windows-latest + needs: [Build] + if : github.event_name == 'push' + steps: + - uses: actions/checkout@v1 + + - name: Enable long file paths + run: git config --global core.longpaths true + + - name: Update submodules + run: git submodule -q update --init + + - name: Build + shell: pwsh + run: | + $DebugPreference = "Continue" + ./build.ps1 + + - name : install nuget + if: success() + uses: warrenbuckley/Setup-Nuget@v1 + + - name: Configure feed + if: success() + run: nuget.exe source Add -Name "GitHub" -Source "https://nuget.pkg.github.com/sixlabors/index.json" -UserName ${{github.actor}} -Password ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to nightly feed - github + if: success() + run: nuget.exe push -Source "GitHub" .\artifacts\*.nupkg + + - name: Publish to nightly feed -myget + if: success() + run: nuget.exe push .\artifacts\*.nupkg ${{secrets.MYGET_TOKEN}} -Source https://www.myget.org/F/sixlabors/api/v2/package + + # todo if github.ref starts with 'refs/tags' then it was tag push and we can optionally push out package to nuget.org \ No newline at end of file diff --git a/.gitignore b/.gitignore index d8f376a419..4007b1faba 100644 --- a/.gitignore +++ b/.gitignore @@ -221,3 +221,5 @@ artifacts/ # Tests **/Images/ActualOutput **/Images/ReferenceOutput +/tests/CodeCoverage/opencover.zip +/tests/CodeCoverage/OpenCover.4.6.519 diff --git a/Directory.Build.props b/Directory.Build.props index efe4cc9665..e865a83f85 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -14,7 +14,7 @@ $(MSBuildThisFileDirectory)artifacts/ $(ImageSharpProjectCategory)/$(MSBuildProjectName) - https://github.com/SixLabors/ImageSharp/ + https://github.com/SixLabors/ImageSharp/ diff --git a/build.ps1 b/build.ps1 index 215b551170..1bc7ff6cc1 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,20 +1,79 @@ +param( + [string]$targetFramework = 'ALL' +) # lets calulat the correct version here $fallbackVersion = "1.0.0"; $version = '' -$tagRegex = '^v?(\d+\.\d+\.\d+)(-([a-zA-Z]+)\.?(\d*))?$' +$tagRegex = '^v?(\d+\.\d+\.\d+)(?:-([a-zA-Z]+)\.?(\d*))?$' + +$skipFullFramework = 'false' + +# if we are trying to build only netcoreapp versions for testings then skip building the full framework targets +if("$targetFramework".StartsWith("netcoreapp")){ + $skipFullFramework = 'true' +} + +function ToBuildNumber { + param( $date ) + if("$date" -eq ""){ + $date = [System.DateTime]::Now + } + + if($date.GetType().fullname -ne 'System.DateTime'){ + $date = [System.DateTime]::Parse($date) + } + + + return $date.ToString("yyyyMMddhhmmss") +} + +# if($IsWindows){ +# $skipFullFramework = 'true' +# Write-Info "Building full framework targets - Running windows" +# }else{ +# if (Get-Command "mono" -ErrorAction SilentlyContinue) +# { +# Write-Info "Building full framework targets - mono installed" +# $skipFullFramework = 'true' +# } +# } # we are running on the build server $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex +if($isVersionTag -eq $false){ + $isVersionTag = "$env:GITHUB_REF".replace("refs/tags/", "") -match $tagRegex + if($isVersionTag){ + Write-Debug "Github tagged build" + } +}else{ + Write-Debug "Appveyor tagged build" +} + +if($isVersionTag -eq $false){ + if( "$(git diff --stat)" -eq '') + { + Write-Debug "Clean repo" + if("$(git tag --list)" -ne "") { + Write-Debug "Has tags" + $tagData = (git describe --tags HEAD) + $isVersionTag = $tagData -match $tagRegex + Write-Debug $tagData + } + }else{ + Write-Debug "Dirty repo" + } +} + if($isVersionTag) { Write-Debug "Building commit tagged with a compatable version number" $version = $matches[1] - $postTag = $matches[3] - $count = $matches[4] + $postTag = $matches[2] + $count = $matches[3] Write-Debug "version number: ${version} post tag: ${postTag} count: ${count}" if("$postTag" -ne ""){ $version = "${version}-${postTag}" @@ -53,8 +112,23 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex $buildNumber = $env:APPVEYOR_BUILD_NUMBER - # build number replacement is padded to 6 places - $buildNumber = "$buildNumber".Trim().Trim('0').PadLeft(6,"0"); + if("$buildNumber" -eq ""){ + # no counter availible in this environment + # let make one up based on time + + if( "$env:GITHUB_SHA" -ne ''){ + $buildNumber = ToBuildNumber (git show -s --format=%ci $env:GITHUB_SHA) + }elseif( "$(git diff --stat)" -eq ''){ + $buildNumber = ToBuildNumber (git show -s --format=%ci HEAD) + }else{ + $buildNumber = ToBuildNumber + } + $buildNumber = "$buildNumber".Trim().Trim('0').PadLeft(12,"0"); + }else{ + # build number replacement is padded to 6 places + $buildNumber = "$buildNumber".Trim().Trim('0').PadLeft(6,"0"); + } + if("$env:APPVEYOR_PULL_REQUEST_NUMBER" -ne ""){ Write-Debug "building a PR" @@ -77,7 +151,7 @@ $isVersionTag = $env:APPVEYOR_REPO_TAG_NAME -match $tagRegex $branch = $branch.Replace("/","-").ToLower() - if($branch.ToLower() -eq "master"){ + if($branch.ToLower() -eq "master" -or $branch.ToLower() -eq "head"){ $branch = "dev" } @@ -94,10 +168,16 @@ if("$env:APPVEYOR_API_URL" -ne ""){ } Write-Host "Building version '${version}'" -dotnet restore /p:packageversion=$version /p:DisableImplicitNuGetFallbackFolder=true +dotnet restore /p:packageversion=$version /p:DisableImplicitNuGetFallbackFolder=true /p:skipFullFramework=$skipFullFramework + +$repositoryUrl = "https://github.com/SixLabors/ImageSharp/" + +if("$env:GITHUB_REPOSITORY" -ne ""){ + $repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY" +} Write-Host "Building projects" -dotnet build -c Release /p:packageversion=$version +dotnet build -c Release /p:packageversion=$version /p:skipFullFramework=$skipFullFramework /p:RepositoryUrl=$repositoryUrl if ($LASTEXITCODE ){ Exit $LASTEXITCODE } @@ -115,8 +195,8 @@ if ($LASTEXITCODE ){ Exit $LASTEXITCODE } if ($LASTEXITCODE ){ Exit $LASTEXITCODE } Write-Host "Packaging projects" -dotnet pack ./src/ImageSharp/ -c Release --output ../../artifacts --no-build /p:packageversion=$version +dotnet pack ./src/ImageSharp/ -c Release --output "$PSScriptRoot/artifacts" --no-build /p:packageversion=$version /p:skipFullFramework=$skipFullFramework /p:RepositoryUrl=$repositoryUrl if ($LASTEXITCODE ){ Exit $LASTEXITCODE } -dotnet pack ./src/ImageSharp.Drawing/ -c Release --output ../../artifacts --no-build /p:packageversion=$version +dotnet pack ./src/ImageSharp.Drawing/ -c Release --output "$PSScriptRoot/artifacts" --no-build /p:packageversion=$version /p:skipFullFramework=$skipFullFramework /p:RepositoryUrl=$repositoryUrl if ($LASTEXITCODE ){ Exit $LASTEXITCODE } diff --git a/run-tests.ps1 b/run-tests.ps1 index 4aeaa14908..2d563c67e6 100644 --- a/run-tests.ps1 +++ b/run-tests.ps1 @@ -1,6 +1,7 @@ param( [string]$targetFramework, - [string]$is32Bit = "False" + [string]$is32Bit = "False", + [string]$skipCodeCov = $false ) if (!$targetFramework){ @@ -41,9 +42,9 @@ function CheckSubmoduleStatus() { } -if ( ($targetFramework -eq "netcoreapp2.1") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) { +if ( ($targetFramework -eq "netcoreapp2.1") -and ($env:CI -eq "True") -and ($is32Bit -ne "True") -and $skipCodeCov -ne $true) { # We execute CodeCoverage.cmd only for one specific job on CI (netcoreapp2.1 + 64bit ) - $testRunnerCmd = ".\tests\CodeCoverage\CodeCoverage.cmd" + $testRunnerCmd = "./tests/CodeCoverage/CodeCoverage.ps1" } elseif ($targetFramework -eq "mono") { $testDllPath = "$PSScriptRoot\tests\ImageSharp.Tests\bin\Release\net462\SixLabors.ImageSharp.Tests.dll" diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj index 86b0848663..e0d70193fe 100644 --- a/src/ImageSharp/ImageSharp.csproj +++ b/src/ImageSharp/ImageSharp.csproj @@ -1,4 +1,4 @@ - + @@ -10,7 +10,8 @@ $(packageversion) 0.0.1 - netcoreapp2.1;netstandard1.3;netstandard2.0;net472 + netcoreapp2.1;netstandard1.3;netstandard2.0 + $(TargetFrameworks);net472 true true diff --git a/tests/CodeCoverage/CodeCoverage.ps1 b/tests/CodeCoverage/CodeCoverage.ps1 new file mode 100644 index 0000000000..b7073998f9 --- /dev/null +++ b/tests/CodeCoverage/CodeCoverage.ps1 @@ -0,0 +1,11 @@ + +if((Test-Path("$PSScriptRoot\OpenCover.4.6.519")) -eq $false){ + Invoke-WebRequest https://www.nuget.org/api/v2/package/OpenCover/4.7.922 -OutFile "$PSScriptRoot\opencover.zip" + [IO.Compression.Zipfile]::ExtractToDirectory("$PSScriptRoot\opencover.zip","$PSScriptRoot\OpenCover.4.6.519") +} + +dotnet clean ImageSharp.sln -c Release + +& "$PSScriptRoot\OpenCover.4.6.519\tools\OpenCover.Console.exe" -target:"dotnet.exe" -targetargs:"test tests\ImageSharp.Tests\ImageSharp.Tests.csproj -c Release -f netcoreapp2.1 /p:skipFullFramework=true /p:codecov=true" -register:user -threshold:10 -oldStyle -safemode:off -output:.\ImageSharp.Coverage.xml -hideskipped:All -returntargetcode -filter:"+[SixLabors.ImageSharp*]*" + +if ($LASTEXITCODE ){ Exit $LASTEXITCODE } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj index a57d388a95..ee0b2985f0 100644 --- a/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj +++ b/tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj @@ -1,11 +1,12 @@ - + ImageSharp.Benchmarks Exe SixLabors.ImageSharp.Benchmarks - netcoreapp2.1;net472 + netcoreapp2.1 + $(TargetFrameworks);net472 false false diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index fc94668e11..b0826dcbed 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -1,4 +1,4 @@ - + @@ -8,7 +8,9 @@ false SixLabors.ImageSharp.Sandbox46 win7-x64 - net472 + netcoreapp2.1 + $(TargetFrameworks);net472 + SixLabors.ImageSharp.Sandbox46.Program @@ -18,6 +20,7 @@ + diff --git a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj index 1ac5f8085a..3bd5f6af2d 100644 --- a/tests/ImageSharp.Tests/ImageSharp.Tests.csproj +++ b/tests/ImageSharp.Tests/ImageSharp.Tests.csproj @@ -1,8 +1,9 @@ - + - netcoreapp2.1;net462;net472 + netcoreapp2.1 + $(TargetFrameworks);net462;net472 True latest full