Skip to content

Commit f1ddcb3

Browse files
authored
Refactor build to use PSPackageProject (#273)
1 parent 8ee78d7 commit f1ddcb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+11987
-8414
lines changed

.ci/ci.yml

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
name: $(BuildDefinitionName)-$(date:yyMM).$(date:dd)$(rev:rrr)
2+
trigger:
3+
# Batch merge builds together while a merge build is running
4+
batch: true
5+
branches:
6+
include:
7+
- master
8+
pr:
9+
branches:
10+
include:
11+
- master
12+
13+
stages:
14+
- stage: Build
15+
displayName: Build PowerShellGet Module Package
16+
jobs:
17+
- job: BuildPkg
18+
displayName: Build Package
19+
pool:
20+
name: Package ES CodeHub Lab E
21+
22+
steps:
23+
- powershell: |
24+
$powerShellPath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'powershell'
25+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.ps1 -outfile ./install-powershell.ps1
26+
./install-powershell.ps1 -Destination $powerShellPath
27+
$vstsCommandString = "vso[task.setvariable variable=PATH]$powerShellPath;$env:PATH"
28+
Write-Host "sending " + $vstsCommandString
29+
Write-Host "##$vstsCommandString"
30+
displayName: Install PowerShell Core
31+
32+
- task: UseDotNet@2
33+
displayName: 'Install .NET Core 3.1.401 sdk'
34+
inputs:
35+
packageType: sdk
36+
version: 3.1.401
37+
38+
- task: NuGetToolInstaller@1
39+
displayName: 'Install NuGet 5.6.0'
40+
inputs:
41+
checkLatest: false
42+
version: 5.6.0
43+
44+
- task: PkgESSetupBuild@10
45+
displayName: 'Package ES - Setup Build'
46+
inputs:
47+
productName: PowerShellGet
48+
useDfs: false
49+
branchVersion: true
50+
disableMsbuildVersion: true
51+
52+
- pwsh: |
53+
Get-ChildItem -Path env:
54+
displayName: Capture environment for build
55+
condition: succeededOrFailed()
56+
57+
- pwsh: |
58+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
59+
if (Test-Path -Path $modulePath) {
60+
Write-Verbose -Verbose "Deleting existing temp module path: $modulePath"
61+
Remove-Item -Path $modulePath -Recurse -Force -ErrorAction Ignore
62+
}
63+
if (! (Test-Path -Path $modulePath)) {
64+
Write-Verbose -Verbose "Creating new temp module path: $modulePath"
65+
$null = New-Item -Path $modulePath -ItemType Directory
66+
}
67+
displayName: Create temporary module path for PSPackageProject
68+
69+
- pwsh: |
70+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
71+
Save-Module -Name PowerShellGet -Path $modulePath -MinimumVersion 3.0.0-beta10 -AllowPrerelease -Force
72+
displayName: Install PowerShellGet Module
73+
74+
- pwsh: |
75+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
76+
Save-Module -Name "platyPS" -Path $modulePath -Force
77+
displayName: Install platyPS dependency
78+
79+
- pwsh: |
80+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
81+
Save-Module -Name "PSScriptAnalyzer" -Path $modulePath -RequiredVersion 1.18.0 -Force
82+
displayName: Install PSScriptAnalyzer dependency
83+
84+
- pwsh: |
85+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
86+
Save-Module -Name "Pester" -MaximumVersion 4.99 -Path $modulePath -Force
87+
displayName: Install Pester version 4
88+
89+
- pwsh: |
90+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
91+
Save-Module -Name PSPackageProject -Path $modulePath -Force
92+
displayName: Install PSPackageProject module
93+
94+
- pwsh: |
95+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
96+
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
97+
$modPath = Join-Path -Path $modulePath -ChildPath PSPackageProject
98+
Write-Verbose -Verbose "Importing PSPackageProject from: $modPath"
99+
Import-Module -Name $modPath -Force
100+
#
101+
# First build for netstandard2.0 framework
102+
$(Build.SourcesDirectory)/build.ps1 -Build -Clean -BuildConfiguration Release -BuildFramework 'netstandard2.0'
103+
# Next build for net472 framework
104+
$(Build.SourcesDirectory)/build.ps1 -Build -BuildConfiguration Release -BuildFramework 'net472'
105+
displayName: Build and publish artifact
106+
107+
- pwsh: |
108+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
109+
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
110+
$modPath = Join-Path -Path $modulePath -ChildPath PSPackageProject
111+
Write-Verbose -Verbose "Importing PSPackageProject from: $modPath"
112+
Import-Module -Name $modPath -Force
113+
#
114+
$config = Get-PSPackageProjectConfiguration
115+
$signSrcPath = "$($config.BuildOutputPath)\$($config.ModuleName)"
116+
$signOutPath = "$($config.SignedOutputPath)\$($config.ModuleName)"
117+
if (! (Test-Path -Path $signOutPath)) {
118+
$null = New-Item -Path $signOutPath -ItemType Directory
119+
}
120+
Write-Host "Signed output path is: $signOutPath"
121+
$signXmlPath = "$($config.SourcePath)\..\sign-module-files.xml"
122+
# Set signing src path variable
123+
$vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}"
124+
Write-Host "sending " + $vstsCommandString
125+
Write-Host "##$vstsCommandString"
126+
# Set signing out path variable
127+
$vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}"
128+
Write-Host "sending " + $vstsCommandString
129+
Write-Host "##$vstsCommandString"
130+
# Set signing xml path
131+
$vstsCommandString = "vso[task.setvariable variable=signXmlPath]${signXmlPath}"
132+
Write-Host "sending " + $vstsCommandString
133+
Write-Host "##$vstsCommandString"
134+
displayName: Set up for code signing
135+
136+
- pwsh: |
137+
Get-ChildItem -Path env:
138+
displayName: Capture environment for module code signing
139+
condition: succeededOrFailed()
140+
141+
- task: PkgESCodeSign@10
142+
displayName: Sign build files
143+
env:
144+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
145+
inputs:
146+
signConfigXml: '$(signXmlPath)'
147+
inPathRoot: '$(signSrcPath)'
148+
outPathRoot: '$(signOutPath)'
149+
binVersion: Production
150+
binVersionOverride: ''
151+
condition: and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), ne(variables['SkipSigning'], 'True'))
152+
153+
- pwsh: |
154+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
155+
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
156+
$modPath = Join-Path -Path $modulePath -ChildPath PSPackageProject
157+
Write-Verbose -Verbose "Importing PSPackageProject from: $modPath"
158+
Import-Module -Name $modPath -Force
159+
#
160+
if ($env:SkipSigning -eq 'True')
161+
{
162+
$(Build.SourcesDirectory)/build.ps1 -Publish
163+
}
164+
else
165+
{
166+
$(Build.SourcesDirectory)/build.ps1 -Publish -Signed
167+
}
168+
displayName: Create module artifact
169+
170+
- stage: Compliance
171+
displayName: Compliance
172+
dependsOn: Build
173+
jobs:
174+
- job: ComplianceJob
175+
pool:
176+
name: Package ES CodeHub Lab E
177+
steps:
178+
- template: compliance.yml
179+
180+
- stage: Test
181+
displayName: Test Package
182+
dependsOn: Build
183+
jobs:
184+
- template: test.yml
185+
parameters:
186+
jobName: TestPkgWin
187+
displayName: PowerShell Core on Windows
188+
imageName: windows-2019
189+
190+
- template: test.yml
191+
parameters:
192+
jobName: TestPkgUbuntu16
193+
displayName: PowerShell Core on Ubuntu 16.04
194+
imageName: ubuntu-16.04
195+
196+
- template: test.yml
197+
parameters:
198+
jobName: TestPkgWinMacOS
199+
displayName: PowerShell Core on macOS
200+
imageName: macOS-10.14
201+
202+
- stage: Release
203+
displayName: Release Package
204+
condition: and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), eq(variables['Publish'], 'True'))
205+
jobs:
206+
- template: release.yml

.ci/compliance.yml

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
steps:
2+
3+
- powershell: |
4+
$powerShellPath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'powershell'
5+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/install-powershell.ps1 -outfile ./install-powershell.ps1
6+
./install-powershell.ps1 -Destination $powerShellPath
7+
$vstsCommandString = "vso[task.setvariable variable=PATH]$powerShellPath;$env:PATH"
8+
Write-Host "sending " + $vstsCommandString
9+
Write-Host "##$vstsCommandString"
10+
displayName: Install PowerShell Core
11+
12+
- task: DownloadBuildArtifacts@0
13+
displayName: 'Download artifacts'
14+
inputs:
15+
buildType: current
16+
downloadType: specific
17+
itemPattern: '**/*.nupkg'
18+
downloadPath: '$(System.ArtifactsDirectory)'
19+
20+
- pwsh: |
21+
Get-ChildItem -Path "$(System.ArtifactsDirectory)" -Recurse
22+
displayName: Capture artifacts directory
23+
24+
- pwsh: |
25+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
26+
if (Test-Path -Path $modulePath) {
27+
Write-Verbose -Verbose "Deleting existing temp module path: $modulePath"
28+
Remove-Item -Path $modulePath -Recurse -Force -ErrorAction Ignore
29+
}
30+
if (! (Test-Path -Path $modulePath)) {
31+
Write-Verbose -Verbose "Creating new temp module path: $modulePath"
32+
$null = New-Item -Path $modulePath -ItemType Directory
33+
}
34+
displayName: Create temporary module path for PSPackageProject
35+
36+
- pwsh: |
37+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
38+
Save-Module -Name PowerShellGet -Path $modulePath -MinimumVersion 3.0.0-beta10 -AllowPrerelease -Force
39+
displayName: Install PowerShellGet Module
40+
41+
- pwsh: |
42+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
43+
Save-Module -Name "platyPS" -Path $modulePath -Force
44+
displayName: Install platyPS dependency
45+
46+
- pwsh: |
47+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
48+
Save-Module -Name "PSScriptAnalyzer" -Path $modulePath -RequiredVersion 1.18.0 -Force
49+
displayName: Install PSScriptAnalyzer dependency
50+
51+
- pwsh: |
52+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
53+
Save-Module -Name "Pester" -MaximumVersion 4.99 -Path $modulePath -Force
54+
displayName: Install Pester version 4
55+
56+
- pwsh: |
57+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
58+
Save-Module -Name PSPackageProject -Path $modulePath -Force
59+
displayName: Install PSPackageProject module
60+
61+
- pwsh: |
62+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
63+
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
64+
$sourceName = 'pspackageproject-local-repo'
65+
Register-PackageSource -Name $sourceName -Location "$(System.ArtifactsDirectory)" -ProviderName PowerShellGet -Force -ErrorAction Ignore
66+
Get-PackageSource -Name $sourceName
67+
$config = Get-PSPackageProjectConfiguration
68+
$buildOutputPath = $config.BuildOutputPath
69+
$null = New-Item -ItemType Directory -Path $buildOutputPath -Verbose
70+
$moduleName = $config.ModuleName
71+
Write-Verbose -Verbose "Saving package $sourceName to $($config.BuildOutputPath)"
72+
Save-Package -Name $moduleName -Source $sourceName -ProviderName PowerShellGet -Path $config.BuildOutputPath -AllowPrereleaseVersions -Force
73+
Write-Verbose -Verbose "Writing BUILD_SOURCE variable"
74+
$vstsCommandString = "vso[task.setvariable variable=BUILD_SOURCE]$($config.BuildOutputPath)"
75+
Write-Host "sending " + $vstsCommandString
76+
Write-Host "##$vstsCommandString"
77+
displayName: Extract product artifact
78+
79+
- pwsh: |
80+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
81+
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
82+
$config = Get-PSPackageProjectConfiguration
83+
dir "$($config.BuildOutputPath)/*" -r 2>$null
84+
displayName: 'BuildOutputPath directory'
85+
86+
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
87+
displayName: 'Component Detection'
88+
inputs:
89+
sourceScanPath: '$(Build.SourcesDirectory)'
90+
snapshotForceEnabled: true
91+
92+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-antimalware.AntiMalware@3
93+
displayName: 'Run Defender Scan'
94+
95+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
96+
displayName: 'Run CredScan'
97+
inputs:
98+
toolMajorVersion: V2
99+
debugMode: false
100+
continueOnError: true
101+
102+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-binskim.BinSkim@3
103+
displayName: 'Run BinSkim '
104+
inputs:
105+
InputType: Basic
106+
AnalyzeTarget: '$(BUILD_SOURCE)\PowerShellGet\netstandard2.0\Microsoft.PowerShellGet.dll'
107+
AnalyzeSymPath: 'SRV*'
108+
AnalyzeVerbose: true
109+
AnalyzeHashes: true
110+
AnalyzeStatistics: true
111+
continueOnError: true
112+
113+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-policheck.PoliCheck@1
114+
displayName: 'Run PoliCheck'
115+
inputs:
116+
targetType: F
117+
optionsFC: 0
118+
optionsXS: 0
119+
optionsPE: '1|2|3|4'
120+
optionsHMENABLE: 0
121+
# optionsRulesDBPath: '$(Build.SourcesDirectory)\tools\terms\PowerShell-Terms-Rules.mdb'
122+
# optionsFTPATH: '$(Build.SourcesDirectory)\tools\terms\FileTypeSet.xml'
123+
toolVersion: 5.8.2.1
124+
continueOnError: true
125+
126+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
127+
displayName: 'Publish Security Analysis Logs to Build Artifacts'
128+
continueOnError: true
129+
130+
#- task: securedevelopmentteam.vss-secure-development-tools.build-task-uploadtotsa.TSAUpload@1
131+
# displayName: 'TSA upload to Codebase: PowerShellGet_201510 Stamp: Azure'
132+
# inputs:
133+
# codeBaseName: PowerShellGet_201510
134+
# tsaVersion: TsaV2
135+
# uploadFortifySCA: false
136+
# uploadFxCop: false
137+
# uploadModernCop: false
138+
# uploadPREfast: false
139+
# uploadRoslyn: false
140+
# uploadTSLint: false
141+
# uploadAPIScan: false
142+
143+
- task: securedevelopmentteam.vss-secure-development-tools.build-task-report.SdtReport@1
144+
displayName: 'Create Security Analysis Report'
145+
inputs:
146+
TsvFile: false
147+
APIScan: false
148+
BinSkim: false
149+
CredScan: true
150+
PoliCheck: true
151+
PoliCheckBreakOn: Severity2Above
152+
153+
- pwsh: |
154+
Unregister-PSRepository -Name 'pspackageproject-local-repo' -ErrorAction Ignore
155+
displayName: Unregister temporary PSRepository
156+
condition: always()

0 commit comments

Comments
 (0)