Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI build for v2 branch #522

Merged
merged 27 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9ccd962
CI pipeline for platyPS v2
adityapatwardhan May 6, 2021
52f4e14
Comment out release stage
adityapatwardhan May 6, 2021
32903d0
Add verbose
adityapatwardhan May 6, 2021
8bd8fef
Fix script invocation
adityapatwardhan May 6, 2021
925fbd9
Add nuget config for tests
adityapatwardhan May 6, 2021
bc92121
Add protocol version to nuget.config
adityapatwardhan May 6, 2021
bd9e65e
Add dotnet restore
adityapatwardhan May 10, 2021
58b9b3e
Test fixes
adityapatwardhan May 11, 2021
df94cad
Add test run names
adityapatwardhan May 12, 2021
87c09f0
Fix yaml
adityapatwardhan May 12, 2021
c07715f
Add EA silentlycontinue
adityapatwardhan May 12, 2021
68b6992
Fix tests
adityapatwardhan May 12, 2021
880f858
Add logging to remove platyPS v5
adityapatwardhan May 12, 2021
6d2303f
Fix test
adityapatwardhan May 12, 2021
e1a380d
Use file path instead of file info
adityapatwardhan May 12, 2021
17928c7
Add logging to test
adityapatwardhan May 12, 2021
9b4c759
Fix test
adityapatwardhan May 12, 2021
f0e0943
Mark test as pending on macOS
adityapatwardhan May 12, 2021
6941b86
Fix tests
adityapatwardhan May 13, 2021
e2c0326
Make xunit test windows only
adityapatwardhan May 13, 2021
85f1fa8
Remove unused variable
adityapatwardhan May 13, 2021
7a273cb
Add xunit condition in yml
adityapatwardhan May 13, 2021
1d91a03
Test fixes and module page fix
adityapatwardhan May 13, 2021
850c093
Remove net5.0 target framework
adityapatwardhan May 13, 2021
5190501
Fix error condition
adityapatwardhan May 13, 2021
de3d22c
Remove extra logging and add back uninstall pester
adityapatwardhan May 13, 2021
2ec8c0f
Add compliance
adityapatwardhan May 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .ci/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Build-$(System.PullRequest.PullRequestNumber)-$(Date:yyyyMMdd)$(Rev:.rr)
trigger:
# Batch merge builds together while a merge build is running
batch: true
branches:
include:
- master
- release/*
pr:
branches:
include:
- master
- release/*

resources:
repositories:
- repository: ComplianceRepo
type: github
endpoint: ComplianceGHRepo
name: PowerShell/Compliance

stages:
- stage: Build
displayName: Build PowerShell Package
jobs:
- job: BuildPkg
displayName: Build Package
pool:
vmImage: windows-latest
steps:
- pwsh: |
$(Build.SourcesDirectory)/build.ps1 -Clean
displayName: Build

- pwsh: |
$files = (Get-ChildItem -Recurse '$(Build.SourcesDirectory)/out/platyPS' -File).FullName

$files | ForEach-Object {
Write-Host "##vso[artifact.upload containerfolder=platyPS;artifactname=platyPS]$_"
}
displayName: Publish build artifact
timeoutInMinutes: 10

- pwsh: |
Register-PSRepository -Name local -SourceLocation '$(System.ArtifactsDirectory)' -Verbose -ErrorAction Ignore
Publish-Module -Repository local -Path '$(Build.SourcesDirectory)/out/platyPS' -Verbose
$nupkgFile = Get-ChildItem -Path '$(System.ArtifactsDirectory)/platyPS*.nupkg'

Write-Verbose -Verbose "Uploading: $nupkgFile"
Write-Host "##vso[artifact.upload containerfolder=nupkg;artifactname=nupkg]$nupkgFile"

displayName: Create module .nupkg and upload

- stage: Test
displayName: Test Package
jobs:
- template: test.yml
parameters:
jobName: TestPkgWin
displayName: PowerShell Core on Windows
imageName: windows-2019

- template: test.yml
parameters:
jobName: TestPkgWinPS
displayName: Windows PowerShell on Windows
imageName: windows-2019
powershellExecutable: powershell

- template: test.yml
parameters:
jobName: TestPkgUbuntu16
displayName: PowerShell Core on Ubuntu 16.04
imageName: ubuntu-16.04

- template: test.yml
parameters:
jobName: TestPkgWinMacOS
displayName: PowerShell Core on macOS
imageName: macOS-10.14

- stage: compliance
displayName: Compliance
dependsOn: Build
jobs:
- job: Compliance_Job
pool:
name: windows-latest
steps:
- checkout: self
- checkout: ComplianceRepo
- template: ci-compliance.yml@ComplianceRepo
87 changes: 87 additions & 0 deletions .ci/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
parameters:
jobName: TestPkgWin
imageName: windows-latest
displayName: PowerShell Core on Windows
powershellExecutable: pwsh

jobs:
- job: ${{ parameters.jobName }}
pool:
vmImage: ${{ parameters.imageName }}
displayName: ${{ parameters.displayName }}
steps:
- ${{ parameters.powershellExecutable }}: |
Get-InstalledModule -Name pester -AllowPrerelease -MinimumVersion 5.0.0 -ErrorAction SilentlyContinue | Uninstall-Module -Force -Verbose -ErrorAction SilentlyContinue
displayName: Remove >= 5.0.0 Pester
timeoutInMinutes: 10

- ${{ parameters.powershellExecutable }}: |
Install-module Pester -Force -MaximumVersion 4.99
displayName: Install dependencies - Pester
timeoutInMinutes: 10

- task: DownloadBuildArtifacts@0
displayName: 'Download artifacts'
inputs:
buildType: current
downloadType: specific
itemPattern: '**/*.nupkg'
downloadPath: '$(System.ArtifactsDirectory)'
artifactName: 'nupkg'

- task: DotNetCoreCLI@2
displayName: dotnet restore
inputs:
command: restore
projects: '$(Build.SourcesDirectory)/**/*.csproj'
includeNuGetOrg: true

- ${{ parameters.powershellExecutable }}: |
$sourceName = 'pspackageproject-local-repo'
Register-PSRepository -Name $sourceName -SourceLocation '$(System.ArtifactsDirectory)/nupkg' -ErrorAction Ignore -Verbose
$null = New-Item -Path '$(System.ArtifactsDirectory)/saved' -ItemType Directory
Save-Module -Repository $sourceName -Name platyPS -Path '$(System.ArtifactsDirectory)/saved' -Verbose
displayName: Extract product artifact
timeoutInMinutes: 10

- ${{ parameters.powershellExecutable }}: |
$(Build.SourcesDirectory)/build.ps1 -OutputDir '$(System.ArtifactsDirectory)/saved' -Test

$pesterResult = '$(Build.SourcesDirectory)/pester.tests.xml'

if (-not (Test-Path $pesterResult))
{
throw 'Pester test results not found'
}

Write-Host "##vso[results.publish type=NUnit;mergeResults=true;runTitle=Pester;publishRunAttachments=true;resultFiles=$pesterResult;]"

if ($IsWindows)
{
$xunitResult = '$(Build.SourcesDirectory)/xunit.tests.xml'

if (-not (Test-Path $xunitResult))
{
throw 'xUnit test results not found'
}
}
displayName: Execute functional tests
errorActionPreference: continue

- task: PublishTestResults@2
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '**/pester.tests.xml'
testRunTitle: '${{ parameters.jobName }}-Pester'

- task: PublishTestResults@2
inputs:
testResultsFormat: 'xUnit'
testResultsFiles: '**/xunit.tests.xml'
testRunTitle: '${{ parameters.jobName }}-xUnit'

- ${{ parameters.powershellExecutable }}: |
Unregister-PSRepository -Name 'pspackageproject-local-repo' -ErrorAction Ignore
displayName: Unregister temporary PSRepository
condition: always()
timeoutInMinutes: 10
37 changes: 16 additions & 21 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ param(
[ValidateSet("Debug", "Release")]
[string] $Configuration = "Debug",

[Parameter(ParameterSetName = "Build")]
[string] $OutputDir = "$PSScriptRoot/out",

[Parameter(ParameterSetName = "Test", Mandatory)]
Expand Down Expand Up @@ -48,8 +47,7 @@ if ($PSCmdlet.ParameterSetName -eq 'Build') {
$expectedBuildPath = "./bin/$Configuration/net461/"
$expectedDllPath = "$expectedBuildPath/Microsoft.PowerShell.PlatyPS.dll"

if (-not (Test-Path $expectedDllPath))
{
if (-not (Test-Path $expectedDllPath)) {
throw "Build did not succeed."
}

Expand All @@ -73,30 +71,27 @@ if ($PSCmdlet.ParameterSetName -eq 'Build') {
elseif ($PSCmdlet.ParameterSetName -eq 'Test') {
Import-Module -Name "$OutputDir/platyPS" -Force

$xunitTestRoot = "$PSScriptRoot/test/Microsoft.PowerShell.PlatyPS.Tests"
Write-Verbose "Executing XUnit tests under $xunitTestRoot" -Verbose

$xunitTestFailed = $true

try {
Push-Location $xunitTestRoot
dotnet test --test-adapter-path:. "--logger:xunit;LogFilePath=$XUnitLogPath"

if ($LASTEXITCODE -eq 0) {
$xunitTestFailed = $false
if ($IsWindows) {
try {
$xunitTestRoot = "$PSScriptRoot/test/Microsoft.PowerShell.PlatyPS.Tests"
Write-Verbose "Executing XUnit tests under $xunitTestRoot" -Verbose
Push-Location $xunitTestRoot
dotnet test --test-adapter-path:. "--logger:xunit;LogFilePath=$XUnitLogPath"
if ($LASTEXITCODE -ne 0) {
throw "XUnit test failed"
}
}
finally {
Pop-Location
}
}
finally {
Pop-Location
}

$pesterTestRoot = "$PSScriptRoot/test/Pester"
Write-Verbose "Executing Pester tests under $pesterTestRoot"
Write-Verbose "Executing Pester tests under $pesterTestRoot" -Verbose

$results = Invoke-Pester -Script $pesterTestRoot -PassThru -Outputformat nunitxml -outputfile $PesterLogPath

if ($results.FailedCount -ne 0 -or $xunitTestFailed)
{
throw "Tests failed."
if ($results.FailedCount -ne 0) {
throw "Pester Tests failed."
}
}
2 changes: 1 addition & 1 deletion src/MarkdownWriter/ModulePageWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal FileInfo Write(Collection<CommandHelp> helpItems)

if (!string.Equals(modulePage.Extension, ".md", StringComparison.OrdinalIgnoreCase))
{
_modulePagePath = $"{_modulePagePath}\\{moduleName}.md";
_modulePagePath = $"{_modulePagePath}{Constants.DirectorySeparator}{moduleName}.md";
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions test/Microsoft.PowerShell.PlatyPS.Tests/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/>
</packageSources>
<disabledPackageSources>
<clear />
</disabledPackageSources>
</configuration>
Loading