Skip to content

Commit

Permalink
enable using github actions for building
Browse files Browse the repository at this point in the history
+ publish to github package repository
  • Loading branch information
tocsoft committed Dec 11, 2019
1 parent 8cd937c commit 2ef3b90
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 22 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,5 @@ artifacts/
# Tests
**/Images/ActualOutput
**/Images/ReferenceOutput
/tests/CodeCoverage/opencover.zip
/tests/CodeCoverage/OpenCover.4.6.519
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PropertyGroup>
<BaseArtifactsPath>$(MSBuildThisFileDirectory)artifacts/</BaseArtifactsPath>
<BaseArtifactsPathSuffix>$(ImageSharpProjectCategory)/$(MSBuildProjectName)</BaseArtifactsPathSuffix>
<RepositoryUrl>https://github.com/SixLabors/ImageSharp/</RepositoryUrl>
<RepositoryUrl Condition="'$(RepositoryUrl)' == ''">https://github.com/SixLabors/ImageSharp/</RepositoryUrl>
</PropertyGroup>

<!-- Default settings that explicitly differ from the Sdk.props defaults -->
Expand Down
100 changes: 90 additions & 10 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down Expand Up @@ -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"

Expand All @@ -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"
}

Expand All @@ -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 }

Expand All @@ -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 }
7 changes: 4 additions & 3 deletions run-tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
param(
[string]$targetFramework,
[string]$is32Bit = "False"
[string]$is32Bit = "False",
[string]$skipCodeCov = $false
)

if (!$targetFramework){
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/ImageSharp/ImageSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Expand All @@ -10,7 +10,8 @@
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix>
<VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix>

<TargetFrameworks>netcoreapp2.1;netstandard1.3;netstandard2.0;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netstandard1.3;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net472</TargetFrameworks>

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
11 changes: 11 additions & 0 deletions tests/CodeCoverage/CodeCoverage.ps1
Original file line number Diff line number Diff line change
@@ -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 }
5 changes: 3 additions & 2 deletions tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>ImageSharp.Benchmarks</AssemblyName>
<OutputType>Exe</OutputType>
<RootNamespace>SixLabors.ImageSharp.Benchmarks</RootNamespace>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net472</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
Expand Down
7 changes: 5 additions & 2 deletions tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Expand All @@ -8,7 +8,9 @@
<Prefer32Bit>false</Prefer32Bit>
<RootNamespace>SixLabors.ImageSharp.Sandbox46</RootNamespace>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<TargetFramework>net472</TargetFramework>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net472</TargetFrameworks>
<StartupObject>SixLabors.ImageSharp.Sandbox46.Program</StartupObject>
</PropertyGroup>

<ItemGroup>
Expand All @@ -18,6 +20,7 @@
<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" />
<PackageReference Include="Moq" />
<PackageReference Include="System.Drawing.Common" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions tests/ImageSharp.Tests/ImageSharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net462;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net462;net472</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<DebugType Condition="$(codecov) != ''">full</DebugType>
Expand Down

0 comments on commit 2ef3b90

Please sign in to comment.