Skip to content

Commit f7dfb48

Browse files
authored
Build the binaries (#1504)
Build the few types that Pester uses in binaries that are compatible with Windows PowerShell 3+ and PowerShell 6+. Move build to Azure pipelines.
1 parent 41a9a36 commit f7dfb48

15 files changed

+202
-149
lines changed

.appveyor.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.artifactignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
src/csharp/bin/
2+
src/csharp/obj/
3+
src/csharp/.vs/
4+
publish/
5+
.git
6+
.gitignore
7+
.gitattributes
8+
.artifactignore
9+
azure-pipelines.yml
10+
.github
11+
.vscode
12+
LICENSE
13+
README.MD
14+
VERIFICATION.txt
15+

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

azure-pipelines.yml

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,105 @@
11
trigger:
2-
- master
32
- v5.0
43
pr:
5-
- master
64
- v5.0
75

86
resources:
97
- repo: self
108
clean: true
119
fetchDepth: 1
1210

13-
jobs:
14-
- job: ps3
15-
displayName: PowerShell 3
16-
continueOnError: false
17-
pool:
18-
name: Default
19-
demands:
20-
- ps3
21-
workspace:
22-
clean: all
23-
timeoutInMinutes: 3
24-
steps:
25-
- powershell: ./test.ps1 -ci -passThru
11+
variables:
12+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
2613

14+
stages:
15+
- stage: Build
16+
jobs:
17+
- job: build
18+
pool:
19+
name: Default
20+
demands:
21+
- net452
22+
- netcoreapp3.1
23+
timeoutInMinutes: 3
24+
steps:
25+
- powershell: ./build.ps1
26+
- publish: $(Build.SourcesDirectory)
27+
artifact: all
28+
29+
- stage: Test
30+
jobs:
31+
- job:
32+
strategy:
33+
matrix:
34+
PS7_Ubuntu_16_04:
35+
vmImage: ubuntu-16.04
36+
pwsh: true
37+
PS7_Ubuntu_18_04:
38+
vmImage: ubuntu-18.04
39+
pwsh: true
40+
PS7_macOS_10_14_Mojave:
41+
vmImage: macOS-10.14
42+
pwsh: true
43+
PS7_macOS_10_15_Catalina:
44+
vmImage: macOS-10.15
45+
pwsh: true
46+
PS7_Windows_Server2016:
47+
vmImage: vs2017-win2016
48+
pwsh: true
49+
PS7_Windows_Server2019:
50+
vmImage: windows-2019
51+
pwsh: true
52+
PS_5_1_Windows_Server2016:
53+
vmImage: vs2017-win2016
54+
pwsh: false
55+
PS_5_1_Windows_Server2019:
56+
vmImage: windows-2019
57+
pwsh: false
58+
pool:
59+
vmImage: $[ variables['vmImage'] ]
60+
steps:
61+
- checkout: none
62+
- task: DownloadPipelineArtifact@2
63+
inputs:
64+
buildType: 'current'
65+
artifactName: 'all'
66+
targetPath: '$(Build.SourcesDirectory)'
67+
- task: PowerShell@2
68+
displayName: 'Test Pester'
69+
inputs:
70+
targetType: inline
71+
pwsh: $(pwsh)
72+
script: |
73+
& ./test.ps1 -CI -PassThru -NoBuild
74+
workingDirectory: '$(Build.SourcesDirectory)'
75+
- job:
76+
strategy:
77+
matrix:
78+
PS3:
79+
agent: 'ps3'
80+
pwsh: false
81+
PS4:
82+
agent: 'ps4'
83+
pwsh: false
84+
PS6_2:
85+
agent: 'ps6'
86+
pwsh: true
87+
pool:
88+
name: Default
89+
demands:
90+
- agent.name -equals $(agent)
91+
steps:
92+
- checkout: none
93+
- task: DownloadPipelineArtifact@2
94+
inputs:
95+
buildType: 'current'
96+
artifactName: 'all'
97+
targetPath: '$(Build.SourcesDirectory)'
98+
- task: PowerShell@2
99+
displayName: 'Test Pester'
100+
inputs:
101+
targetType: 'inline'
102+
pwsh: $(pwsh)
103+
script: |
104+
& ./test.ps1 -CI -PassThru -NoBuild
105+
workingDirectory: '$(Build.SourcesDirectory)'

build.ps1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#! /usr/bin/pwsh
2+
13
param ([switch]$Debug)
24

35
$ErrorActionPreference = 'Stop'
@@ -22,8 +24,6 @@ $script = @(
2224
"$PSScriptRoot/src/functions/*"
2325

2426
"$PSScriptRoot/src/Pester.psm1"
25-
# "$PSScriptRoot/src/"
26-
# "$PSScriptRoot/src/"
2727
)
2828

2929
$sb = [System.Text.StringBuilder]""
@@ -70,13 +70,20 @@ foreach ($s in $script) {
7070

7171
$sb.ToString() | Set-Content $PSScriptRoot/bin/Pester.psm1 -Encoding UTF8
7272

73+
dotnet build "$PSScriptRoot/src/csharp/Pester.sln" --configuration Release $framework
74+
if (0 -ne $LASTEXITCODE) {
75+
throw "build failed!"
76+
}
7377

7478
$content = @(
75-
,("$PSScriptRoot/src/csharp/*.cs","$PSScriptRoot/bin/csharp/")
7679
,("$PSScriptRoot/src/en-US/*.txt","$PSScriptRoot/bin/en-US/")
7780
,("$PSScriptRoot/src/nunit_schema_2.5.xsd", "$PSScriptRoot/bin/")
7881
,("$PSScriptRoot/src/report.dtd", "$PSScriptRoot/bin/")
7982
,("$PSScriptRoot/src/Pester.psd1", "$PSScriptRoot/bin/")
83+
,("$PSScriptRoot/src/csharp/bin/Release/net452/Pester.dll","$PSScriptRoot/bin/bin/net452/")
84+
,("$PSScriptRoot/src/csharp/bin/Release/net452/Pester.pdb","$PSScriptRoot/bin/bin/net452/")
85+
,("$PSScriptRoot/src/csharp/bin/Release/netstandard2.0/Pester.dll","$PSScriptRoot/bin/bin/netstandard2.0/")
86+
,("$PSScriptRoot/src/csharp/bin/Release/netstandard2.0/Pester.pdb","$PSScriptRoot/bin/bin/netstandard2.0/")
8087
)
8188

8289
foreach ($c in $content) {
@@ -88,4 +95,9 @@ foreach ($c in $content) {
8895
}
8996

9097

91-
Import-Module $PSScriptRoot/bin/Pester.psm1 -ErrorAction Stop
98+
$powershell = Get-Process -id $PID | Select-Object -ExpandProperty Path
99+
100+
& $powershell -c "'Load: ' + (Measure-Command { Import-Module $PSScriptRoot/bin/Pester.psm1 -ErrorAction Stop}).TotalMilliseconds"
101+
if (0 -ne $LASTEXITCODE) {
102+
throw "load failed!"
103+
}

publish/release.ps1

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ param (
99
)
1010

1111
$ErrorActionPreference = 'Stop'
12+
if (-not $IsWindows -or $PSVersionTable.PSVersion.Major -gt 6) {
13+
throw "this must run on powershell 6+ on windows to build all the right binaries"
14+
}
1215
# run this in seperate instance otherwise Pester.dll is loaded and the subsequent build will fail
1316
# $process = Start-Process powershell -ArgumentList "-c", ".\testRelease.ps1 -LocalBuild" -NoNewWindow -Wait -PassThru
1417

@@ -19,6 +22,7 @@ $ErrorActionPreference = 'Stop'
1922
#.\getNugetExe.ps1
2023
#.\cleanUpBeforeBuild.ps1
2124
# & "$PSSCriptRoot/../test.ps1"
25+
& "$PSScriptRoot/../build.ps1"
2226
& "$PSScriptRoot/signModule.ps1" -Thumbprint $CertificateThumbprint -Path "$PSScriptRoot/../bin"
2327

2428
$psGalleryDir = "$PSScriptRoot/../tmp/PSGallery/Pester/"
@@ -28,9 +32,41 @@ if (Test-Path $psGalleryDir) {
2832
}
2933

3034
$null = New-Item -ItemType Directory -Path $psGalleryDir
31-
Copy-Item "$PSScriptRoot/../bin/*" $psGalleryDir -Recurse -Verbose
35+
Copy-Item "$PSScriptRoot/../bin/*" $psGalleryDir -Recurse
36+
37+
$files = @(
38+
"nunit_schema_2.5.xsd"
39+
"Pester.psd1"
40+
"Pester.psm1"
41+
"report.dtd"
42+
"bin\net452\Pester.dll"
43+
"bin\net452\Pester.pdb"
44+
"bin\netstandard2.0\Pester.dll"
45+
"bin\netstandard2.0\Pester.pdb"
46+
"en-US\about_BeforeEach_AfterEach.help.txt"
47+
"en-US\about_Mocking.help.txt"
48+
"en-US\about_Pester.help.txt"
49+
"en-US\about_Should.help.txt"
50+
"en-US\about_TestDrive.help.txt"
51+
)
52+
53+
$notFound = @()
54+
foreach ($f in $files) {
55+
if (-not (Test-Path "$psGalleryDir/$f")) {
56+
$notFound += $f
57+
}
58+
}
59+
60+
if (0 -lt $notFound.Count) {
61+
throw "Did not find files:`n$($notFound -join "`n")"
62+
}
63+
else {
64+
"Found all files!"
65+
}
66+
67+
3268

33-
Publish-Module -Path $psGalleryDir -NuGetApiKey $PsGalleryApiKey -Verbose
69+
# Publish-Module -Path $psGalleryDir -NuGetApiKey $PsGalleryApiKey -Verbose
3470
#.\buildNugetPackage.ps1
3571
# .\buildPSGalleryPackage.ps1
3672

src/Pester.Runtime.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# if -not build
22
. "$PSScriptRoot/Pester.Utility.ps1"
33
. "$PSScriptRoot/functions/Pester.SafeCommands.ps1"
4-
. "$PSScriptRoot/Pester.Types.ps1"
4+
# . "$PSScriptRoot/Pester.Types.ps1"
55
# endif
66

77
# instances

src/Pester.Types.ps1

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,6 @@
1-
$Paths = @(
2-
"$PSScriptRoot/csharp/Configuration.cs"
3-
"$PSScriptRoot/csharp/Factory.cs"
4-
"$PSScriptRoot/csharp/Test.cs"
5-
)
6-
7-
foreach ($path in $Paths) {
8-
Add-Type -TypeDefinition (Get-Content -Raw $path) -ErrorAction Stop
1+
if ($PSVersionTable.PSVersion.Major -ge 6) {
2+
Add-Type -Path "$PSScriptRoot/bin/netstandard2.0/Pester.dll"
93
}
10-
11-
Add-Type -TypeDefinition @"
12-
using System;
13-
namespace Pester
14-
{
15-
[Flags]
16-
public enum OutputTypes
17-
{
18-
None = 0,
19-
Default = 1,
20-
Passed = 2,
21-
Failed = 4,
22-
Pending = 8,
23-
Skipped = 16,
24-
Inconclusive = 32,
25-
Describe = 64,
26-
Context = 128,
27-
Summary = 256,
28-
Header = 512,
29-
All = Default | Passed | Failed | Pending | Skipped | Inconclusive | Describe | Context | Summary | Header,
30-
Fails = Default | Failed | Pending | Skipped | Inconclusive | Describe | Context | Summary | Header
31-
}
4+
else {
5+
Add-Type -Path "$PSScriptRoot/bin/net452/Pester.dll"
326
}
33-
"@

src/csharp/Configuration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Pester;
2-
using System;
32
using System.Collections;
4-
using System.Collections.Generic;
53
using System.Linq;
64
using System.Management.Automation;
75

src/csharp/ConversionTests.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)