Skip to content

Commit

Permalink
🚀 Run tests against built module (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
vexx32 committed Feb 29, 2020
1 parent 286c5bb commit 8e3aa52
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 110 deletions.
9 changes: 4 additions & 5 deletions Build/Build-Module.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Grab nuget bits, set build variables, start build.
Get-PackageProvider -Name NuGet -ForceBootstrap > $null

Import-Module "$env:PROJECTROOT/PSKoans"

Set-BuildEnvironment

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

$BuiltModuleFolder = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/Module/"
Write-Host "##vso[task.setvariable variable=BuiltModuleFolder]$BuiltModuleFolder"

New-Item -Path $BuiltModuleFolder -ItemType Directory
Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $BuiltModuleFolder -Recurse -PassThru
Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru |
Where-Object { -not $_.PSIsContainer }
25 changes: 25 additions & 0 deletions Build/Register-FileSystemRepository.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]
$Path,

[Parameter(Mandatory)]
[string]
$Name
)

$RepositoryFolder = if (-not (Test-Path $Path)) {
New-Item -ItemType Directory -Path $Path -Force
}
else {
Get-Item -Path $Path
}

$Params = @{
Name = $Name
SourceLocation = $RepositoryFolder.FullName
ScriptSourceLocation = $RepositoryFolder.FullName
InstallationPolicy = 'Trusted'
}
Register-PSRepository @Params
8 changes: 0 additions & 8 deletions Deploy/Publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ param(
$env:NugetApiKey = $Key

if ($OutputDirectory) {
$Params = @{
Name = 'FileSystem'
SourceLocation = "$PSScriptRoot/FileSystem"
ScriptSourceLocation = "$PSScriptRoot/FileSystem"
InstallationPolicy = 'Trusted'
}
Register-PSRepository @Params

Import-Module "$PSScriptRoot/PSKoans"
$Module = Get-Module -Name PSKoans
$Dependencies = @(
Expand Down
229 changes: 132 additions & 97 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,50 @@ trigger:
pr:
- master

variables:
NupkgArtifactName: 'PSKoans.nupkg'

stages:
- stage: LinuxTests
displayName: 'Linux'
- stage: UploadChangelog
displayName: 'Upload Changelog'
dependsOn: []
condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/master')

jobs:
- job: Linux
displayName: 'Pester Tests'
- job: GenerateChangelog
displayName: "Generate Changelog"

pool:
vmImage: ubuntu-latest

steps:
- template: templates/environment-setup.yml
- template: templates/test-steps.yml

- stage: WindowsTests
displayName: 'Windows'
dependsOn: []

jobs:
- job: Windows
displayName: 'Pester Tests'

pool:
vmImage: windows-latest
variables:
FilePath: '$(System.DefaultWorkingDirectory)/Changelog.md'

steps:
- template: templates/environment-setup.yml
- template: templates/test-steps.yml

- stage: MacOSTests
displayName: 'MacOS'
dependsOn: []

jobs:
- job: MacOS
displayName: 'Pester Tests'
- task: PowerShell@2
displayName: 'Create Changelog'
inputs:
targetType: 'filepath'
filePath: ./Build/New-Changelog.ps1
arguments: -Path '$(FilePath)' -ApiKey $(GithubApiKey) -Verbose

pool:
vmImage: macOS-latest
- task: PublishPipelineArtifact@1
displayName: 'Publish Changelog'
inputs:
path: '$(FilePath)'
artifact: Changelog

steps:
- template: templates/environment-setup.yml
- template: templates/test-steps.yml
- stage: Build
displayName: 'Build PSKoans'
dependsOn: []

- stage: PublishModule
displayName: 'Create Module'
dependsOn:
- LinuxTests
- WindowsTests
- MacOSTests
variables:
FileSystemDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/FileSystem'
BuiltModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'

jobs:
- job: BuildModule
displayName: "Build PSKoans"
- job: BuildNupkg
displayName: 'Module Nupkg'

pool:
vmImage: ubuntu-latest
Expand All @@ -78,7 +66,7 @@ stages:
- template: templates/environment-setup.yml

- task: PowerShell@2
displayName: 'Initialize Environment'
displayName: 'Stage PSKoans Module'

inputs:
targetType: 'filePath'
Expand All @@ -91,34 +79,19 @@ stages:
- task: PublishPipelineArtifact@1
displayName: 'Publish Built Module Artifact'
inputs:
path: '$(BuiltModuleFolder)/PSKoans'
path: '$(BuiltModulePath)'
artifact: PSKoans

- job: PublishFiles
dependsOn: BuildModule
displayName: "Publish Artifacts"

pool:
vmImage: ubuntu-latest
variables:
builtModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'
fileSystemDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/FileSystem'

steps:
- template: templates/environment-setup.yml

- task: DownloadPipelineArtifact@2
displayName: 'Download Built Module Artifact'
inputs:
artifact: PSKoans
path: $(builtModulePath)
- template: ./templates/register-local-repo.yml
parameters:
repositoryPath: '$(FileSystemDeploymentPath)'

- task: PowerShell@2
displayName: 'Create Module Nupkg'
inputs:
targetType: 'filePath'
filePath: ./Deploy/Publish.ps1
arguments: -Key 'filesystem' -Path '$(fileSystemDeploymentPath)' -OutputDirectory '$(fileSystemDeploymentPath)'
arguments: -Key 'filesystem' -Path '$(FileSystemDeploymentPath)' -OutputDirectory '$(FileSystemDeploymentPath)'

errorActionPreference: 'stop'
failOnStderr: true
Expand All @@ -128,18 +101,107 @@ stages:
displayName: 'Publish Nupkg Artifact'
inputs:
path: '$(NupkgPath)'
artifact: PSKoans.nupkg
artifact: '$(NupkgArtifactName)'

- stage: LinuxTests
displayName: 'Linux'
dependsOn:
- Build

variables:
PackageDownloadPath: '$(System.DefaultWorkingDirectory)/Module'
PSRepositoryName: 'FileSystem'

jobs:
- job: Linux
displayName: 'Pester Tests'

pool:
vmImage: ubuntu-latest

steps:
- template: templates/environment-setup.yml

- template: ./templates/install-built-module.yml
parameters:
repositoryPath: '$(PackageDownloadPath)'
repositoryName: '$(PSRepositoryName)'
artifactName: '$(NupkgArtifactName)'

- template: templates/test-steps.yml

- stage: WindowsTests
displayName: 'Windows'
dependsOn:
- Build

variables:
PackageDownloadPath: '$(System.DefaultWorkingDirectory)/Module'
PSRepositoryName: 'FileSystem'

jobs:
- job: Windows
displayName: 'Pester Tests'

pool:
vmImage: windows-latest

steps:
- template: templates/environment-setup.yml

- template: ./templates/install-built-module.yml
parameters:
repositoryPath: '$(PackageDownloadPath)'
repositoryName: '$(PSRepositoryName)'
artifactName: '$(NupkgArtifactName)'

- template: templates/test-steps.yml

- stage: MacOSTests
displayName: 'MacOS'
dependsOn:
- Build

variables:
PackageDownloadPath: '$(System.DefaultWorkingDirectory)/Module'
PSRepositoryName: 'FileSystem'

jobs:
- job: MacOS
displayName: 'Pester Tests'

pool:
vmImage: macOS-latest

steps:
- template: templates/environment-setup.yml

- template: ./templates/install-built-module.yml
parameters:
repositoryPath: '$(PackageDownloadPath)'
repositoryName: '$(PSRepositoryName)'
artifactName: '$(NupkgArtifactName)'

- template: templates/test-steps.yml

- stage: PublishModule
displayName: 'Publish Module'
dependsOn:
- LinuxTests
- WindowsTests
- MacOSTests
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))

jobs:
- job: PublishToGallery
displayName: 'Publish PSKoans to PSGallery'
dependsOn: PublishFiles
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/'))
displayName: 'PowerShell Gallery'

pool:
vmImage: ubuntu-latest

variables:
builtModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'
galleryDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/PSGallery'
BuiltModulePath: '$(System.DefaultWorkingDirectory)/Deploy/PSKoans'
GalleryDeploymentPath: '$(System.DefaultWorkingDirectory)/Deploy/PSGallery'

steps:
- template: templates/environment-setup.yml
Expand All @@ -148,43 +210,16 @@ stages:
displayName: 'Download Built Module Artifact'
inputs:
artifact: PSKoans
path: $(builtModulePath)
path: $(BuiltModulePath)

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

inputs:
targetType: 'filePath'
arguments: -Key $(PSApiKey) -Path '$(galleryDeploymentPath)'
arguments: -Key $(PSApiKey) -Path '$(GalleryDeploymentPath)'
filePath: ./Deploy/Publish.ps1

errorActionPreference: 'stop'
failOnStderr: true
pwsh: true

- stage: CreateChangelog
displayName: 'Upload Changelog'
dependsOn: []
condition: startsWith(variables['Build.SourceBranch'], 'refs/heads/master')

jobs:
- job: GenerateChangelog
displayName: "Generate Changelog"
pool:
vmImage: ubuntu-latest
variables:
filePath: '$(System.DefaultWorkingDirectory)/Changelog.md'

steps:
- task: PowerShell@2
displayName: 'Create Changelog'
inputs:
targetType: 'filepath'
filePath: ./Build/New-Changelog.ps1
arguments: -Path '$(filePath)' -ApiKey $(GithubApiKey) -Verbose

- task: PublishPipelineArtifact@1
displayName: 'Publish Changelog'
inputs:
path: '$(filePath)'
artifact: Changelog
36 changes: 36 additions & 0 deletions templates/install-built-module.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
parameters:
- name: repositoryPath
type: string
default: '$(System.DefaultWorkingDirectory)'
- name: repositoryName
type: string
default: 'FileSystem'
- name: artifactName
type: string
default: 'PSKoans.nupkg'

steps:
- template: ./register-local-repo.yml
parameters:
repositoryPath: ${{ parameters.repositoryPath }}
repositoryName: ${{ parameters.repositoryName }}

- task: DownloadPipelineArtifact@2
displayName: 'Download Built Module Artifact'
inputs:
artifact: ${{ parameters.artifactName }}
path: ${{ parameters.repositoryPath }}

- task: PowerShell@2
displayName: 'Install PSKoans from Nupkg'
inputs:
targetType: 'inline'
script: |
Register-PackageSource -Name PSGallery -ProviderName NuGet -Location https://www.powershellgallery.com/api/v2 -Force
Save-Package -Name Pester -ProviderName NuGet -Path ${{ parameters.repositoryPath }} -Force -Source PSGallery |
Select-Object -Property Name, Version, Status, Source
Install-Module PSKoans -Repository ${{ parameters.repositoryName }} -Force -Scope CurrentUser
errorActionPreference: 'stop'
failOnStderr: true
pwsh: true

0 comments on commit 8e3aa52

Please sign in to comment.