Skip to content

Commit 8e3aa52

Browse files
authored
🚀 Run tests against built module (#363)
1 parent 286c5bb commit 8e3aa52

File tree

6 files changed

+216
-110
lines changed

6 files changed

+216
-110
lines changed

Build/Build-Module.ps1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Grab nuget bits, set build variables, start build.
22
Get-PackageProvider -Name NuGet -ForceBootstrap > $null
33

4+
Import-Module "$env:PROJECTROOT/PSKoans"
5+
46
Set-BuildEnvironment
57

68
$Lines = '-' * 70
@@ -31,8 +33,5 @@ catch {
3133
# Build external help files from Platyps MD files
3234
New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en-us"
3335

34-
$BuiltModuleFolder = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/Module/"
35-
Write-Host "##vso[task.setvariable variable=BuiltModuleFolder]$BuiltModuleFolder"
36-
37-
New-Item -Path $BuiltModuleFolder -ItemType Directory
38-
Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModuleFolder -Recurse -PassThru
36+
Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru |
37+
Where-Object { -not $_.PSIsContainer }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[CmdletBinding()]
2+
param(
3+
[Parameter(Mandatory)]
4+
[string]
5+
$Path,
6+
7+
[Parameter(Mandatory)]
8+
[string]
9+
$Name
10+
)
11+
12+
$RepositoryFolder = if (-not (Test-Path $Path)) {
13+
New-Item -ItemType Directory -Path $Path -Force
14+
}
15+
else {
16+
Get-Item -Path $Path
17+
}
18+
19+
$Params = @{
20+
Name = $Name
21+
SourceLocation = $RepositoryFolder.FullName
22+
ScriptSourceLocation = $RepositoryFolder.FullName
23+
InstallationPolicy = 'Trusted'
24+
}
25+
Register-PSRepository @Params

Deploy/Publish.ps1

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ param(
1313
$env:NugetApiKey = $Key
1414

1515
if ($OutputDirectory) {
16-
$Params = @{
17-
Name = 'FileSystem'
18-
SourceLocation = "$PSScriptRoot/FileSystem"
19-
ScriptSourceLocation = "$PSScriptRoot/FileSystem"
20-
InstallationPolicy = 'Trusted'
21-
}
22-
Register-PSRepository @Params
23-
2416
Import-Module "$PSScriptRoot/PSKoans"
2517
$Module = Get-Module -Name PSKoans
2618
$Dependencies = @(

azure-pipelines.yml

Lines changed: 132 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,50 @@ trigger:
1414
pr:
1515
- master
1616

17+
variables:
18+
NupkgArtifactName: 'PSKoans.nupkg'
19+
1720
stages:
18-
- stage: LinuxTests
19-
displayName: 'Linux'
21+
- stage: UploadChangelog
22+
displayName: 'Upload Changelog'
2023
dependsOn: []
24+
condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/master')
2125

2226
jobs:
23-
- job: Linux
24-
displayName: 'Pester Tests'
27+
- job: GenerateChangelog
28+
displayName: "Generate Changelog"
2529

2630
pool:
2731
vmImage: ubuntu-latest
2832

29-
steps:
30-
- template: templates/environment-setup.yml
31-
- template: templates/test-steps.yml
32-
33-
- stage: WindowsTests
34-
displayName: 'Windows'
35-
dependsOn: []
36-
37-
jobs:
38-
- job: Windows
39-
displayName: 'Pester Tests'
40-
41-
pool:
42-
vmImage: windows-latest
33+
variables:
34+
FilePath: '$(System.DefaultWorkingDirectory)/Changelog.md'
4335

4436
steps:
45-
- template: templates/environment-setup.yml
46-
- template: templates/test-steps.yml
47-
48-
- stage: MacOSTests
49-
displayName: 'MacOS'
50-
dependsOn: []
51-
52-
jobs:
53-
- job: MacOS
54-
displayName: 'Pester Tests'
37+
- task: PowerShell@2
38+
displayName: 'Create Changelog'
39+
inputs:
40+
targetType: 'filepath'
41+
filePath: ./Build/New-Changelog.ps1
42+
arguments: -Path '$(FilePath)' -ApiKey $(GithubApiKey) -Verbose
5543

56-
pool:
57-
vmImage: macOS-latest
44+
- task: PublishPipelineArtifact@1
45+
displayName: 'Publish Changelog'
46+
inputs:
47+
path: '$(FilePath)'
48+
artifact: Changelog
5849

59-
steps:
60-
- template: templates/environment-setup.yml
61-
- template: templates/test-steps.yml
50+
- stage: Build
51+
displayName: 'Build PSKoans'
52+
dependsOn: []
6253

63-
- stage: PublishModule
64-
displayName: 'Create Module'
65-
dependsOn:
66-
- LinuxTests
67-
- WindowsTests
68-
- MacOSTests
54+
variables:
55+
FileSystemDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/FileSystem'
56+
BuiltModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'
6957

7058
jobs:
71-
- job: BuildModule
72-
displayName: "Build PSKoans"
59+
- job: BuildNupkg
60+
displayName: 'Module Nupkg'
7361

7462
pool:
7563
vmImage: ubuntu-latest
@@ -78,7 +66,7 @@ stages:
7866
- template: templates/environment-setup.yml
7967

8068
- task: PowerShell@2
81-
displayName: 'Initialize Environment'
69+
displayName: 'Stage PSKoans Module'
8270

8371
inputs:
8472
targetType: 'filePath'
@@ -91,34 +79,19 @@ stages:
9179
- task: PublishPipelineArtifact@1
9280
displayName: 'Publish Built Module Artifact'
9381
inputs:
94-
path: '$(BuiltModuleFolder)/PSKoans'
82+
path: '$(BuiltModulePath)'
9583
artifact: PSKoans
9684

97-
- job: PublishFiles
98-
dependsOn: BuildModule
99-
displayName: "Publish Artifacts"
100-
101-
pool:
102-
vmImage: ubuntu-latest
103-
variables:
104-
builtModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'
105-
fileSystemDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/FileSystem'
106-
107-
steps:
108-
- template: templates/environment-setup.yml
109-
110-
- task: DownloadPipelineArtifact@2
111-
displayName: 'Download Built Module Artifact'
112-
inputs:
113-
artifact: PSKoans
114-
path: $(builtModulePath)
85+
- template: ./templates/register-local-repo.yml
86+
parameters:
87+
repositoryPath: '$(FileSystemDeploymentPath)'
11588

11689
- task: PowerShell@2
11790
displayName: 'Create Module Nupkg'
11891
inputs:
11992
targetType: 'filePath'
12093
filePath: ./Deploy/Publish.ps1
121-
arguments: -Key 'filesystem' -Path '$(fileSystemDeploymentPath)' -OutputDirectory '$(fileSystemDeploymentPath)'
94+
arguments: -Key 'filesystem' -Path '$(FileSystemDeploymentPath)' -OutputDirectory '$(FileSystemDeploymentPath)'
12295

12396
errorActionPreference: 'stop'
12497
failOnStderr: true
@@ -128,18 +101,107 @@ stages:
128101
displayName: 'Publish Nupkg Artifact'
129102
inputs:
130103
path: '$(NupkgPath)'
131-
artifact: PSKoans.nupkg
104+
artifact: '$(NupkgArtifactName)'
132105

106+
- stage: LinuxTests
107+
displayName: 'Linux'
108+
dependsOn:
109+
- Build
110+
111+
variables:
112+
PackageDownloadPath: '$(System.DefaultWorkingDirectory)/Module'
113+
PSRepositoryName: 'FileSystem'
114+
115+
jobs:
116+
- job: Linux
117+
displayName: 'Pester Tests'
118+
119+
pool:
120+
vmImage: ubuntu-latest
121+
122+
steps:
123+
- template: templates/environment-setup.yml
124+
125+
- template: ./templates/install-built-module.yml
126+
parameters:
127+
repositoryPath: '$(PackageDownloadPath)'
128+
repositoryName: '$(PSRepositoryName)'
129+
artifactName: '$(NupkgArtifactName)'
130+
131+
- template: templates/test-steps.yml
132+
133+
- stage: WindowsTests
134+
displayName: 'Windows'
135+
dependsOn:
136+
- Build
137+
138+
variables:
139+
PackageDownloadPath: '$(System.DefaultWorkingDirectory)/Module'
140+
PSRepositoryName: 'FileSystem'
141+
142+
jobs:
143+
- job: Windows
144+
displayName: 'Pester Tests'
145+
146+
pool:
147+
vmImage: windows-latest
148+
149+
steps:
150+
- template: templates/environment-setup.yml
151+
152+
- template: ./templates/install-built-module.yml
153+
parameters:
154+
repositoryPath: '$(PackageDownloadPath)'
155+
repositoryName: '$(PSRepositoryName)'
156+
artifactName: '$(NupkgArtifactName)'
157+
158+
- template: templates/test-steps.yml
159+
160+
- stage: MacOSTests
161+
displayName: 'MacOS'
162+
dependsOn:
163+
- Build
164+
165+
variables:
166+
PackageDownloadPath: '$(System.DefaultWorkingDirectory)/Module'
167+
PSRepositoryName: 'FileSystem'
168+
169+
jobs:
170+
- job: MacOS
171+
displayName: 'Pester Tests'
172+
173+
pool:
174+
vmImage: macOS-latest
175+
176+
steps:
177+
- template: templates/environment-setup.yml
178+
179+
- template: ./templates/install-built-module.yml
180+
parameters:
181+
repositoryPath: '$(PackageDownloadPath)'
182+
repositoryName: '$(PSRepositoryName)'
183+
artifactName: '$(NupkgArtifactName)'
184+
185+
- template: templates/test-steps.yml
186+
187+
- stage: PublishModule
188+
displayName: 'Publish Module'
189+
dependsOn:
190+
- LinuxTests
191+
- WindowsTests
192+
- MacOSTests
193+
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
194+
195+
jobs:
133196
- job: PublishToGallery
134-
displayName: 'Publish PSKoans to PSGallery'
135-
dependsOn: PublishFiles
136-
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
197+
displayName: 'PowerShell Gallery'
137198

138199
pool:
139200
vmImage: ubuntu-latest
201+
140202
variables:
141-
builtModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'
142-
galleryDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/PSGallery'
203+
BuiltModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'
204+
GalleryDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/PSGallery'
143205

144206
steps:
145207
- template: templates/environment-setup.yml
@@ -148,43 +210,16 @@ stages:
148210
displayName: 'Download Built Module Artifact'
149211
inputs:
150212
artifact: PSKoans
151-
path: $(builtModulePath)
213+
path: $(BuiltModulePath)
152214

153215
- task: PowerShell@2
154216
displayName: 'Publish Module to PSGallery'
155217

156218
inputs:
157219
targetType: 'filePath'
158-
arguments: -Key $(PSApiKey) -Path '$(galleryDeploymentPath)'
220+
arguments: -Key $(PSApiKey) -Path '$(GalleryDeploymentPath)'
159221
filePath: ./Deploy/Publish.ps1
160222

161223
errorActionPreference: 'stop'
162224
failOnStderr: true
163225
pwsh: true
164-
165-
- stage: CreateChangelog
166-
displayName: 'Upload Changelog'
167-
dependsOn: []
168-
condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/master')
169-
170-
jobs:
171-
- job: GenerateChangelog
172-
displayName: "Generate Changelog"
173-
pool:
174-
vmImage: ubuntu-latest
175-
variables:
176-
filePath: '$(System.DefaultWorkingDirectory)/Changelog.md'
177-
178-
steps:
179-
- task: PowerShell@2
180-
displayName: 'Create Changelog'
181-
inputs:
182-
targetType: 'filepath'
183-
filePath: ./Build/New-Changelog.ps1
184-
arguments: -Path '$(filePath)' -ApiKey $(GithubApiKey) -Verbose
185-
186-
- task: PublishPipelineArtifact@1
187-
displayName: 'Publish Changelog'
188-
inputs:
189-
path: '$(filePath)'
190-
artifact: Changelog

templates/install-built-module.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
parameters:
2+
- name: repositoryPath
3+
type: string
4+
default: '$(System.DefaultWorkingDirectory)'
5+
- name: repositoryName
6+
type: string
7+
default: 'FileSystem'
8+
- name: artifactName
9+
type: string
10+
default: 'PSKoans.nupkg'
11+
12+
steps:
13+
- template: ./register-local-repo.yml
14+
parameters:
15+
repositoryPath: ${{ parameters.repositoryPath }}
16+
repositoryName: ${{ parameters.repositoryName }}
17+
18+
- task: DownloadPipelineArtifact@2
19+
displayName: 'Download Built Module Artifact'
20+
inputs:
21+
artifact: ${{ parameters.artifactName }}
22+
path: ${{ parameters.repositoryPath }}
23+
24+
- task: PowerShell@2
25+
displayName: 'Install PSKoans from Nupkg'
26+
inputs:
27+
targetType: 'inline'
28+
script: |
29+
Register-PackageSource -Name PSGallery -ProviderName NuGet -Location https://www.powershellgallery.com/api/v2 -Force
30+
Save-Package -Name Pester -ProviderName NuGet -Path ${{ parameters.repositoryPath }} -Force -Source PSGallery |
31+
Select-Object -Property Name, Version, Status, Source
32+
Install-Module PSKoans -Repository ${{ parameters.repositoryName }} -Force -Scope CurrentUser
33+
34+
errorActionPreference: 'stop'
35+
failOnStderr: true
36+
pwsh: true

0 commit comments

Comments
 (0)