Skip to content

Commit

Permalink
Merge pull request #109 from SEEK-Jobs/cross-platform
Browse files Browse the repository at this point in the history
Cross platform
  • Loading branch information
neilcampbell authored Aug 20, 2017
2 parents 08638b5 + b85e07e commit 102d3d4
Show file tree
Hide file tree
Showing 41 changed files with 421 additions and 85 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/
Binary file modified .nuget/NuGet.exe
Binary file not shown.
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"
47 changes: 47 additions & 0 deletions Build/Publish-StandaloneCore-Releases.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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
$ReleaseSource = $StandaloneCoreRelease.Replace('PactNet-', '').ToLower()
$ProjectPath = Join-Path -Path $SolutionRoot -ChildPath "Build\$ReleaseSource\$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
21 changes: 21 additions & 0 deletions Build/linux-x64/PactNet-Linux-x64.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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. This package contains the 64-bit Linux specific core engine.</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="config.json" target="tools\pact-linux-x86_64\config.json" />
<file src="PactNet-Linux-x64.targets" target="build\PactNet-Linux-x64.targets" />
</files>
</package>
18 changes: 18 additions & 0 deletions Build/linux-x64/PactNet-Linux-x64.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="FixFilePermissions" BeforeTargets="BeforeBuild">
<!-- Ensure the various files are executable. See https://github.com/NuGet/Home/issues/4424 -->
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86_64/bin/pact-mock-service" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86_64/bin/pact-provider-verifier" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86_64/lib/ruby/bin/ruby" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86_64/lib/ruby/bin/ruby_environment" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86_64/lib/ruby/bin.real/ruby" />
</Target>
<ItemGroup>
<CoreLibs Include="$(MSBuildThisFileDirectory)../tools/**" />
<None Include="@(CoreLibs)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Build/linux-x64/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fileName": "{pactCoreDir}/bin/{script}"
}
21 changes: 21 additions & 0 deletions Build/linux-x86/PactNet-Linux-x86.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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. This package contains the 32-bit Linux specific core engine.</description>
<dependencies>
<dependency id="PactNet" version="$version$" />
</dependencies>
</metadata>
<files>
<file src="..\tools\pact-linux-x86\**" target="tools\pact-linux-x86\" />
<file src="config.json" target="tools\pact-linux-x86\config.json" />
<file src="PactNet-Linux-x86.targets" target="build\PactNet-Linux-x86.targets" />
</files>
</package>
18 changes: 18 additions & 0 deletions Build/linux-x86/PactNet-Linux-x86.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="FixFilePermissions" BeforeTargets="BeforeBuild">
<!-- Ensure the various files are executable. See https://github.com/NuGet/Home/issues/4424 -->
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86/bin/pact-mock-service" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86/bin/pact-provider-verifier" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86/lib/ruby/bin/ruby" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86/lib/ruby/bin/ruby_environment" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-linux-x86/lib/ruby/bin.real/ruby" />
</Target>
<ItemGroup>
<CoreLibs Include="$(MSBuildThisFileDirectory)../tools/**" />
<None Include="@(CoreLibs)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Build/linux-x86/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fileName": "{pactCoreDir}/bin/{script}"
}
21 changes: 21 additions & 0 deletions Build/osx/PactNet-OSX.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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. This package contains the Mac OSX specific core engine.</description>
<dependencies>
<dependency id="PactNet" version="$version$" />
</dependencies>
</metadata>
<files>
<file src="..\tools\pact-osx\**" target="tools\pact-osx\" />
<file src="config.json" target="tools\pact-osx\config.json" />
<file src="PactNet-OSX.targets" target="build\PactNet-OSX.targets" />
</files>
</package>
18 changes: 18 additions & 0 deletions Build/osx/PactNet-OSX.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="FixFilePermissions" BeforeTargets="BeforeBuild">
<!-- Ensure the various files are executable. See https://github.com/NuGet/Home/issues/4424 -->
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-osx/bin/pact-mock-service" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-osx/bin/pact-provider-verifier" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-osx/lib/ruby/bin/ruby" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-osx/lib/ruby/bin/ruby_environment" />
<Exec Command="chmod u+x $(MSBuildThisFileDirectory)../tools/pact-osx/lib/ruby/bin.real/ruby" />
</Target>
<ItemGroup>
<CoreLibs Include="$(MSBuildThisFileDirectory)../tools/**" />
<None Include="@(CoreLibs)">
<Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</None>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Build/osx/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"fileName": "{pactCoreDir}/bin/{script}"
}
21 changes: 21 additions & 0 deletions Build/windows/PactNet-Windows.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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. This package contains the Windows specific core engine.</description>
<dependencies>
<dependency id="PactNet" version="$version$" />
</dependencies>
</metadata>
<files>
<file src="..\tools\pact-win32\**" target="tools\pact-win32\" />
<file src="config.json" target="tools\pact-win32\config.json" />
<file src="PactNet-Windows.targets" target="build\PactNet-Windows.targets" />
</files>
</package>
File renamed without changes.
11 changes: 11 additions & 0 deletions Build/windows/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"fileName": "{pactCoreDir}\\lib\\ruby\\bin.real\\ruby.exe",
"arguments": "-rbundler/setup -I\"{pactCoreDir}\\lib\\app\\lib\" \"{pactCoreDir}\\lib\\app\\{script}.rb\"",
"environment": {
"ROOT_PATH": "{pactCoreDir}",
"RUNNING_PATH": "{pactCoreDir}\\bin\\",
"BUNDLE_GEMFILE": "{pactCoreDir}\\lib\\vendor\\Gemfile",
"RUBYLIB": "{pactCoreDir}\\lib\\ruby\\lib\\ruby\\site_ruby\\2.2.0;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\site_ruby\\2.2.0\\i386-mingw32;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\site_ruby;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\vendor_ruby\\2.2.0;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\vendor_ruby\\2.2.0\\i386-mingw32;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\vendor_ruby;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\2.2.0;{pactCoreDir}\\lib\\ruby\\lib\\ruby\\2.2.0\\i386-mingw32",
"SSL_CERT_FILE": "{pactCoreDir}\\lib\\ruby\\lib\\ca-bundle.crt"
}
}
2 changes: 1 addition & 1 deletion PactNet.Tests/Core/MockProviderHostConfigTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Ctor_WhenCalled_SetsTheCorrectScript()
{
var config = GetSubject();

Assert.Equal("pact-mock-service.rb", config.Script);
Assert.Equal("pact-mock-service", config.Script);
}

[Fact]
Expand Down
4 changes: 2 additions & 2 deletions PactNet.Tests/Core/PactCoreHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private IPactCoreHost GetSubject(string script)
[Fact]
public void Start_WhenStdOutIsWrittendTo_LinesAreWrittenToTheOutputters()
{
var pactCoreHost = GetSubject("write-to-stdout.rb");
var pactCoreHost = GetSubject("write-to-stdout");

pactCoreHost.Start();

Expand All @@ -56,7 +56,7 @@ public void Start_WhenStdOutIsWrittendTo_LinesAreWrittenToTheOutputters()
[Fact]
public void Start_WhenStdErrIsWrittendTo_LinesAreWrittenToTheOutputters()
{
var pactCoreHost = GetSubject("write-to-stderr.rb");
var pactCoreHost = GetSubject("write-to-stderr");

pactCoreHost.Start();

Expand Down
Loading

0 comments on commit 102d3d4

Please sign in to comment.