Skip to content

Commit

Permalink
First cut at adding multi platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
neilcampbell committed Aug 10, 2017
1 parent 08638b5 commit fc4a4a3
Show file tree
Hide file tree
Showing 22 changed files with 283 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ Build/PactNet*.nupkg
*.DotSettings
PactNet/Files/pact/
.vs/
tools/
tools/
build/tools/
File renamed without changes.
4 changes: 4 additions & 0 deletions .nuget/download-standalone-core/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="7Zip4Powershell" version="1.8.0" />
</packages>
92 changes: 79 additions & 13 deletions Build/Download-Standalone-Core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,92 @@ function Unzip
$PSScriptFilePath = (Get-Item $MyInvocation.MyCommand.Path).FullName
$BuildRoot = Split-Path -Path $PSScriptFilePath -Parent
$SolutionRoot = Split-Path -Path $BuildRoot -Parent
$OutputPath = Join-Path $SolutionRoot -ChildPath 'tools'
$OutputPath = Join-Path $BuildRoot -ChildPath 'tools'
$NuGetExe = Join-Path $BuildRoot -ChildPath '..\.nuget\nuget.exe'
$7ZipSnapIn = Join-Path $BuildRoot -ChildPath '..\packages\7Zip4PowerShell.1.8.0\tools\7Zip4PowerShell.psd1'

If (Test-Path $OutputPath)
If(Test-Path $OutputPath)
{
Write-Output "Standalone Core has already been downloaded"
exit
Remove-Item $OutputPath -Recurse | Out-Null
}
New-Item -ItemType directory -Path $OutputPath | Out-Null

& $NuGetExe install "$SolutionRoot\.nuget\download-standalone-core\packages.config" -outputdirectory "$SolutionRoot\packages"

Import-Module -Name $7ZipSnapIn

$StandaloneCoreVersion = '1.1.2'
$StandaloneCoreFileName = "pact-$StandaloneCoreVersion-win32"
$StandaloneCoreFilePath = "$OutputPath\$StandaloneCoreFileName.zip"
$StandaloneCoreDownload = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v$StandaloneCoreVersion/$StandaloneCoreFileName.zip";
$StandaloneCoreDownloadBaseUri = "https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v$StandaloneCoreVersion"

New-Item -ItemType directory -Path $OutputPath | Out-Null
Write-Output "Downloading the Standalone Core from '$StandaloneCoreDownload'..."
# Download and extract the Windows core
$WindowsStandaloneCoreFileName = "pact-$StandaloneCoreVersion-win32.zip"
$WindowsStandaloneCoreFilePath = "$OutputPath\$WindowsStandaloneCoreFileName"
$WindowsStandaloneCoreDownload = "$StandaloneCoreDownloadBaseUri/$WindowsStandaloneCoreFileName";

Write-Output "Downloading the Windows Standalone Core from '$WindowsStandaloneCoreDownload'..."
$Client = New-Object System.Net.WebClient
$Client.DownloadFile($WindowsStandaloneCoreDownload, $WindowsStandaloneCoreFilePath)
Write-Output "Done"

Write-Output "Extracting the Windows Standalone Core..."
Expand-7Zip -ArchiveFileName $WindowsStandaloneCoreFilePath -TargetPath $OutputPath
Remove-Item $WindowsStandaloneCoreFilePath
Rename-Item "$OutputPath\pact" "pact-win32"
Write-Output "Done"

# Download and extract the OSX core
$OsxCompressionExtension = '.gz'
$OsxStandaloneCoreFileName = "pact-$StandaloneCoreVersion-osx.tar"
$OsxStandaloneCoreFilePath = "$OutputPath\$OsxStandaloneCoreFileName"
$OsxStandaloneCoreDownload = "$StandaloneCoreDownloadBaseUri/$OsxStandaloneCoreFileName$OsxCompressionExtension";

Write-Output "Downloading the OSX Standalone Core from '$OsxStandaloneCoreDownload'..."
$Client = New-Object System.Net.WebClient
$Client.DownloadFile($OsxStandaloneCoreDownload, "$OsxStandaloneCoreFilePath$OsxCompressionExtension")
Write-Output "Done"

Write-Output "Extracting the OSX Standalone Core..."
Expand-7Zip -ArchiveFileName "$OsxStandaloneCoreFilePath$OsxCompressionExtension" -TargetPath $OutputPath
Remove-Item "$OsxStandaloneCoreFilePath$OsxCompressionExtension"
Expand-7Zip -ArchiveFileName $OsxStandaloneCoreFilePath -TargetPath $OutputPath
Remove-Item $OsxStandaloneCoreFilePath
Rename-Item "$OutputPath\pact" "pact-osx"
Write-Output "Done"

# Download and extract the 32-bit Linux core
$Linux32CompressionExtension = '.gz'
$Linux32StandaloneCoreFileName = "pact-$StandaloneCoreVersion-linux-x86.tar"
$Linux32StandaloneCoreFilePath = "$OutputPath\$Linux32StandaloneCoreFileName"
$Linux32StandaloneCoreDownload = "$StandaloneCoreDownloadBaseUri/$Linux32StandaloneCoreFileName$Linux32CompressionExtension";

Write-Output "Downloading the Linux 32-bit Standalone Core from '$Linux32StandaloneCoreDownload'..."
$Client = New-Object System.Net.WebClient
$Client.DownloadFile($Linux32StandaloneCoreDownload, "$Linux32StandaloneCoreFilePath$Linux32CompressionExtension")
Write-Output "Done"

Write-Output "Extracting the Linux 32-bit Standalone Core..."
Expand-7Zip -ArchiveFileName "$Linux32StandaloneCoreFilePath$Linux32CompressionExtension" -TargetPath $OutputPath
Remove-Item "$Linux32StandaloneCoreFilePath$Linux32CompressionExtension"
Expand-7Zip -ArchiveFileName $Linux32StandaloneCoreFilePath -TargetPath $OutputPath
Remove-Item $Linux32StandaloneCoreFilePath
Rename-Item "$OutputPath\pact" "pact-linux-x86"
Write-Output "Done"

# Download and extract the 64-bit Linux core
$Linux64CompressionExtension = '.gz'
$Linux64StandaloneCoreFileName = "pact-$StandaloneCoreVersion-linux-x86_64.tar"
$Linux64StandaloneCoreFilePath = "$OutputPath\$Linux64StandaloneCoreFileName"
$Linux64StandaloneCoreDownload = "$StandaloneCoreDownloadBaseUri/$Linux64StandaloneCoreFileName$Linux64CompressionExtension";

Write-Output "Downloading the Linux 64-bit Standalone Core from '$Linux64StandaloneCoreDownload'..."
$Client = New-Object System.Net.WebClient
$Client.DownloadFile($StandaloneCoreDownload, $StandaloneCoreFilePath)
$Client.DownloadFile($Linux64StandaloneCoreDownload, "$Linux64StandaloneCoreFilePath$Linux64CompressionExtension")
Write-Output "Done"

Write-Output "Unzipping the Standalone Core..."
Unzip "$StandaloneCoreFilePath" "$OutputPath"
Remove-Item $StandaloneCoreFilePath
Write-Output "Extracting the Linux 64-bit Standalone Core..."
Expand-7Zip -ArchiveFileName "$Linux64StandaloneCoreFilePath$Linux64CompressionExtension" -TargetPath $OutputPath
Remove-Item "$Linux64StandaloneCoreFilePath$Linux64CompressionExtension"
Expand-7Zip -ArchiveFileName $Linux64StandaloneCoreFilePath -TargetPath $OutputPath
Remove-Item $Linux64StandaloneCoreFilePath
Rename-Item "$OutputPath\pact" "pact-linux-x86_64"
Write-Output "Done"
20 changes: 20 additions & 0 deletions Build/PactNet-Linux-x64.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>PactNet-Linux-x64</id>
<version>$version$</version>
<authors>seek.com.au</authors>
<owners>seek.com.au</owners>
<licenseUrl>https://github.com/SEEK-Jobs/pact-net/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>https://github.com/SEEK-Jobs/pact-net</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A .NET version of Pact, which enables consumer driven contract testing.</description>
<dependencies>
<dependency id="PactNet" version="$version$" />
</dependencies>
</metadata>
<files>
<file src="tools\pact-linux-x86_64\**" target="tools\pact-linux-x86_64\" />
<file src="PactNet.targets" target="build" />
</files>
</package>
20 changes: 20 additions & 0 deletions Build/PactNet-Linux-x86.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>PactNet-Linux-x86</id>
<version>$version$</version>
<authors>seek.com.au</authors>
<owners>seek.com.au</owners>
<licenseUrl>https://github.com/SEEK-Jobs/pact-net/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>https://github.com/SEEK-Jobs/pact-net</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A .NET version of Pact, which enables consumer driven contract testing.</description>
<dependencies>
<dependency id="PactNet" version="$version$" />
</dependencies>
</metadata>
<files>
<file src="tools\pact-linux-x86\**" target="tools\pact-linux-x86\" />
<file src="PactNet.targets" target="build" />
</files>
</package>
20 changes: 20 additions & 0 deletions Build/PactNet-OSX.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>PactNet-OSX</id>
<version>$version$</version>
<authors>seek.com.au</authors>
<owners>seek.com.au</owners>
<licenseUrl>https://github.com/SEEK-Jobs/pact-net/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>https://github.com/SEEK-Jobs/pact-net</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A .NET version of Pact, which enables consumer driven contract testing.</description>
<dependencies>
<dependency id="PactNet" version="$version$" />
</dependencies>
</metadata>
<files>
<file src="tools\pact-osx\**" target="tools\pact-osx\" />
<file src="PactNet.targets" target="build" />
</files>
</package>
20 changes: 20 additions & 0 deletions Build/PactNet-Windows.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package>
<metadata>
<id>PactNet-Windows</id>
<version>$version$</version>
<authors>seek.com.au</authors>
<owners>seek.com.au</owners>
<licenseUrl>https://github.com/SEEK-Jobs/pact-net/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>https://github.com/SEEK-Jobs/pact-net</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A .NET version of Pact, which enables consumer driven contract testing.</description>
<dependencies>
<dependency id="PactNet" version="$version$" />
</dependencies>
</metadata>
<files>
<file src="tools\pact-win32\**" target="tools\pact-win32\" />
<file src="PactNet.targets" target="build\PactNet-Windows.targets" />
</files>
</package>
File renamed without changes.
46 changes: 46 additions & 0 deletions Build/Publish-StandaloneCore-Releases.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
param (
[Parameter(Mandatory=$true)]
[ValidatePattern('\d\.\d\.*')]
[string]
$ReleaseVersionNumber,

[switch]$Push,

[string]$ApiKey
)

$PSScriptFilePath = (Get-Item $MyInvocation.MyCommand.Path).FullName

$BuildRoot = Split-Path -Path $PSScriptFilePath -Parent
$SolutionRoot = Split-Path -Path $BuildRoot -Parent
$NuGetExe = Join-Path $BuildRoot -ChildPath '..\.nuget\nuget.exe'

$StandaloneCoreReleases = @('PactNet-Windows','PactNet-OSX','PactNet-Linux-x64','PactNet-Linux-x86')

foreach ($StandaloneCoreRelease in $StandaloneCoreReleases)
{
# Build the NuGet package
$ProjectPath = Join-Path -Path $SolutionRoot -ChildPath "Build\$StandaloneCoreRelease.nuspec"
& $NuGetExe pack $ProjectPath -Properties Configuration=Release -OutputDirectory $BuildRoot -Version $ReleaseVersionNumber -NoPackageAnalysis -NoDefaultExcludes
if (-not $?)
{
throw 'The NuGet process returned an error code.'
}

# Upload the NuGet package
if ($Push)
{
if($ApiKey)
{
& $NuGetExe setApiKey $ApiKey
}

$NuPkgPath = Join-Path -Path $BuildRoot -ChildPath "$StandaloneCoreRelease.$ReleaseVersionNumber.nupkg"
& $NuGetExe push $NuPkgPath
if (-not $?)
{
throw 'The NuGet process returned an error code.'
}
}
}

2 changes: 1 addition & 1 deletion Build/Tests-Coverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $OpenCoverExe = Join-Path $BuildRoot -ChildPath '..\packages\OpenCover.4.6.519\t
$XUnitExe = Join-Path $BuildRoot -ChildPath '..\packages\xunit.runner.console.2.2.0\tools\xunit.console.exe'
$ReportGenExe = Join-Path $BuildRoot -ChildPath '..\packages\ReportGenerator.1.9.1.0\ReportGenerator.exe'

& $NuGetExe install "$SolutionRoot\.nuget\packages.config" -outputdirectory "$SolutionRoot\packages"
& $NuGetExe install "$SolutionRoot\.nuget\coverage\packages.config" -outputdirectory "$SolutionRoot\packages"

New-Item -ItemType directory -Path "$BuildRoot\coverage" -ErrorAction:ignore

Expand Down
18 changes: 9 additions & 9 deletions PactNet.Tests/PactNet.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="NSubstitute" Version="2.0.3" />
<PackageReference Include="PactNet-Windows" Version="2.0.22" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
<PackageReference Include="System.Net.Http" Version="4.3.1" />
</ItemGroup>
<ItemGroup>
<None Include="pact\lib\app\write-to-stderr.rb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="pact\lib\app\write-to-stdout.rb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="..\PactNet\PactNet.targets" />
<ItemGroup>
<ProjectReference Include="..\PactNet\PactNet.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<None Update="pact-win32\lib\app\write-to-stderr.rb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="pact-win32\lib\app\write-to-stdout.rb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
51 changes: 50 additions & 1 deletion PactNet/Core/PactCoreHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using PactNet.Models;

namespace PactNet.Core
{
Expand All @@ -19,7 +20,55 @@ public PactCoreHost(T config)
_config = config;

var currentDir = Directory.GetCurrentDirectory();
var pactCoreDir = $"{currentDir}\\pact";
var pactCoreDir = $"{currentDir}\\"; //OS specific version will be appended

var platform = Platform.Windows;

#if !USE_NET4X
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
platform = Platform.Windows;
}
else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
{
platform = Platform.Osx;
}
else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) &&
System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X86)
{
platform = Platform.LinuxX86;
}
else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux) &&
System.Runtime.InteropServices.RuntimeInformation.OSArchitecture == System.Runtime.InteropServices.Architecture.X64)
{
platform = Platform.LinuxX64;
}
else
{
throw new PactFailureException("Sorry your current OS platform or architecture is not supported");
}
#endif

switch (platform)
{
case Platform.Windows:
pactCoreDir += "pact-win32";
break;
case Platform.Osx:
pactCoreDir += "pact-osx";
break;
case Platform.LinuxX86:
pactCoreDir += "pact-linux-x86";
break;
case Platform.LinuxX64:
pactCoreDir += "pact-linux-x86_64";
break;
}

if (!Directory.Exists(pactCoreDir))
{
//TODO: Fall back to using the locally install ruby and packaged assets
}

var startInfo = new ProcessStartInfo
{
Expand Down
10 changes: 10 additions & 0 deletions PactNet/Models/Platform.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PactNet.Models
{
internal enum Platform
{
Windows,
Osx,
LinuxX86,
LinuxX64
}
}
1 change: 0 additions & 1 deletion PactNet/PactNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
</ItemGroup>
<Import Project="PactNet.targets" />
</Project>
2 changes: 0 additions & 2 deletions PactNet/PactNet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<file src="bin\Release\net45\PactNet.dll" target="lib\net45" />
<file src="bin\Release\net45\PactNet.pdb" target="lib\net45" />
<file src="bin\Release\net45\PactNet.xml" target="lib\net45" />
<file src="..\tools\**" target="tools\" />
<file src="PactNet.targets" target="build" />
<file src="readme.txt" target="" />
</files>
</package>
Loading

0 comments on commit fc4a4a3

Please sign in to comment.