Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit 7a41860

Browse files
authored
Merge pull request #674 from anamnavi/refactor-pipeline
Refactor pipeline
2 parents 5aba753 + 847f571 commit 7a41860

File tree

3 files changed

+166
-73
lines changed

3 files changed

+166
-73
lines changed

.ci/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
parameters:
2+
jobName: release
3+
displayName: 'Release PowerShellGet to PSGallery'
4+
5+
jobs:
6+
- job: ${{ parameters.jobName }}
7+
pool:
8+
name: 1ES
9+
demands:
10+
- ImageOverride -equals PSMMS2019-Secure
11+
displayName: ${{ parameters.displayName }}
12+
13+
steps:
14+
- task: DownloadPipelineArtifact@2
15+
displayName: 'Download PowerShellGet module artifacts'
16+
inputs:
17+
artifact: nupkg
18+
patterns: '**/PowerShellGet*.nupkg'
19+
downloadPath: '$(Pipeline.Workspace)/nuget'
20+
21+
- powershell: |
22+
$package = (Get-ChildItem '$(Pipeline.Workspace)/nuget/PowerShellGet.*.nupkg').FullName
23+
$package
24+
$vstsCommandString = "vso[task.setvariable variable=NugetPkgPath]${package}"
25+
Write-Host "sending " + $vstsCommandString
26+
Write-Host "##$vstsCommandString"
27+
displayName: 'Capture PowerShellGet module NuGet package path and set environment variable'
28+
29+
- task: NuGetCommand@2
30+
displayName: 'Push PowerShellGet module artifacts to PSGallery feed'
31+
inputs:
32+
command: push
33+
packagesToPush: '$(NugetPkgPath)'
34+
nuGetFeedType: external
35+
publishFeedCredentials: PSGalleryPush

.ci/releaseBuild.yml

Lines changed: 130 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,190 @@
1-
# The name of the build that will be seen in mscodehub
2-
name: PowerShellGetv2-Release-$(Build.BuildId)
3-
# how is the build triggered
4-
# since this is a release build, no trigger as it's a manual release
1+
name: $(BuildDefinitionName)-$(date:yyMM).$(date:dd)$(rev:rrr)
52
trigger: none
3+
pr: none
64

7-
pr:
8-
branches:
9-
include:
10-
- master
11-
12-
# variables to set in the build environment
135
variables:
14-
DOTNET_CLI_TELEMETRY_OPTOUT: 1
15-
POWERSHELL_TELEMETRY_OPTOUT: 1
6+
- group: ESRP
7+
- name: ModuleName
8+
value: 'PowerShellGet'
9+
- name: BuildOutputPath
10+
value: '$(Build.SourcesDirectory)\dist\PowerShellGet'
11+
- name: SignedOutputPath
12+
value: '$(Build.SourcesDirectory)/signed'
1613

17-
# since this build relies on templates, we need access to those
18-
# This needs a service connection in the build to work
19-
# the *name* of the service connection must be the same as the endpoint
2014
resources:
2115
repositories:
2216
- repository: ComplianceRepo
2317
type: github
2418
endpoint: ComplianceGHRepo
2519
name: PowerShell/compliance
26-
# this can be any branch of your choosing
27-
ref: master
2820

29-
# the stages in this build. There are 2
30-
# the assumption for PowerShellGetv2 is that test is done as part of
31-
# CI so we needn't do it here
3221
stages:
3322
- stage: Build
34-
displayName: Build
35-
pool:
36-
name: Package ES CodeHub Lab E
23+
displayName: Build PowerShellGetV2 Module Package
3724
jobs:
38-
- job: Build_Job
39-
displayName: Build Microsoft.PowerShell.PowerShellGetv2
40-
# note the variable reference to ESRP.
41-
# this must be created in Project -> Pipelines -> Library -> VariableGroups
42-
# where it describes the link to the SigningServer
43-
variables:
44-
- group: ESRP
25+
- job: BuildPkg
26+
displayName: Build Package
27+
pool:
28+
name: 1ES
29+
demands:
30+
- ImageOverride -equals PSMMS2019-Secure
31+
32+
4533
steps:
46-
- checkout: self
4734

48-
# the steps for building the module go here
4935
- pwsh: |
50-
Set-Location "$(Build.SourcesDirectory)/PowerShellGetv2"
36+
Get-ChildItem -Path env:
37+
Get-ChildItem -Path env:
38+
displayName: Capture environment for build
39+
condition: succeededOrFailed()
40+
41+
- pwsh: |
42+
Set-Location "$(Build.SourcesDirectory)"
5143
Import-Module ./tools/build.psm1 -Force
5244
Install-Dependencies
5345
Update-ModuleManifestFunctions
5446
Publish-ModuleArtifacts
55-
displayName: Execute build
47+
displayName: Build and publish artifact
5648
57-
# these are setting vso variables which will be persisted between stages
5849
- pwsh: |
59-
$signSrcPath = "$(Build.SourcesDirectory)/PowerShellGetv2/dist/PowerShellGet"
60-
dir
61-
# Set signing src path variable
50+
$signSrcPath = "$(BuildOutputPath)"
6251
$vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}"
6352
Write-Host "sending " + $vstsCommandString
6453
Write-Host "##$vstsCommandString"
6554
66-
$signOutPath = "$(Build.SourcesDirectory)/OSS_Microsoft_PowerShellGetv2/signed/PowerShellGet"
67-
$null = New-Item -ItemType Directory -Path $signOutPath -force
68-
# Set signing out path variable
69-
$vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}"
55+
$outSignPath = "$(BuildOutputPath)"
56+
$vstsCommandString = "vso[task.setvariable variable=signOutPath]${outSignPath}"
7057
Write-Host "sending " + $vstsCommandString
7158
Write-Host "##$vstsCommandString"
59+
displayName: Create fake source and output variables for signing template and no signing
60+
condition: and(succeeded(), eq(variables['SkipSigning'], 'True'))
61+
62+
- pwsh: |
63+
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
64+
65+
# Created files signing directory
66+
$srcPath = "$(BuildOutputPath)"
67+
$createdSignSrcPath = "$(SignedOutputPath)\CreatedFiles"
68+
if (! (Test-Path -Path $createdSignSrcPath)) {
69+
$null = New-Item -Path $createdSignSrcPath -ItemType Directory -Verbose
70+
}
71+
Copy-Item -Path $srcPath -Dest $createdSignSrcPath -Recurse -Force -Verbose
7272
73-
# Set path variable for guardian codesign validation
74-
$vstsCommandString = "vso[task.setvariable variable=GDN_CODESIGN_TARGETDIRECTORY]${signOutPath}"
73+
$signOutPath = "$(SignedOutputPath)\$(ModuleName)"
74+
if (! (Test-Path -Path $signOutPath)) {
75+
$null = New-Item -Path $signOutPath -ItemType Directory
76+
}
77+
78+
# Set signing src path variable
79+
$vstsCommandString = "vso[task.setvariable variable=signSrcPath]${createdSignSrcPath}"
7580
Write-Host "sending " + $vstsCommandString
7681
Write-Host "##$vstsCommandString"
7782
78-
# Get version and create a variable
79-
$moduleData = Import-PowerShellDataFile "$(Build.SourcesDirectory)/PowerShellGetv2/dist/PowerShellGet/PowerShellGet.psd1"
80-
$moduleVersion = $moduleData.ModuleVersion
81-
$vstsCommandString = "vso[task.setvariable variable=moduleVersion]${moduleVersion}"
83+
$outSignPath = "$(SignedOutputPath)\$(ModuleName)"
84+
if (! (Test-Path -Path $outSignPath)) {
85+
$null = New-Item -Path $outSignPath -ItemType Directory -Verbose
86+
}
87+
88+
# Set signing out path variable
89+
$vstsCommandString = "vso[task.setvariable variable=signOutPath]${outSignPath}"
8290
Write-Host "sending " + $vstsCommandString
8391
Write-Host "##$vstsCommandString"
84-
displayName: Setup variables for signing
92+
displayName: Set up for module created files code signing
93+
condition: and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), ne(variables['SkipSigning'], 'True'))
8594
86-
# checkout the Compliance repository so it can be used to do the actual signing
87-
- checkout: ComplianceRepo
95+
- pwsh: |
96+
Get-ChildItem -Path env:
97+
Get-ChildItem -Path . -Recurse -Directory
98+
displayName: Capture environment for code signing
99+
condition: succeededOrFailed()
88100
89-
# this the MS authored step This cert covers MS autored items
90-
# note that the buildOutputPath (where we get the files to sign)
91-
# is the same as the signOutputPath in the previous step
92-
# at the end of this step we will have all the files signed that should be
93-
# signOutPath is the location which contains the files we will use to make the module
94101
- template: EsrpSign.yml@ComplianceRepo
95102
parameters:
96-
# the folder which contains the binaries to sign
97103
buildOutputPath: $(signSrcPath)
98-
# the location to put the signed output
99104
signOutputPath: $(signOutPath)
100-
# the certificate ID to use (Authenticode)
101105
certificateId: "CP-230012"
102106
pattern: |
103107
**\*.psd1
104108
**\*.psm1
105109
**\*.ps1xml
106110
**\*.mof
111+
useMinimatch: true
112+
113+
- pwsh: |
114+
$srcPath = "$(BuildOutputPath)"
115+
$signOutPath = "$(SignedOutputPath)\$(ModuleName)"
116+
if (! (Test-Path -Path $signOutPath)) {
117+
$null = New-Item -Path $signOutPath -ItemType Directory
118+
}
119+
120+
Get-ChildItem -Path $srcPath | Foreach-Object {
121+
if ($_.Attributes -ne "Directory")
122+
{
123+
$sig = Get-AuthenticodeSignature -FilePath $_.FullName
124+
if ($sig.Status -eq 'Valid' -and ($sig.SignerCertificate.Subject -like '*Microsoft*' -and $sig.SignerCertificate.Issuer -like '*Microsoft Code Signing PCA*')) {
125+
# Copy already signed files directly to output
126+
Copy-Item -Path $_.FullName -Dest $signOutPath -Force -Verbose
127+
}
128+
}
129+
}
130+
displayName: Copy already properly signed files (.psd1, .psm1, .ps1xml, .mof)
131+
condition: and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), ne(variables['SkipSigning'], 'True'))
132+
133+
- ${{ if ne(variables.SkipSigning, 'True') }}:
134+
- template: Sbom.yml@ComplianceRepo
135+
parameters:
136+
BuildDropPath: $(signOutPath)
137+
Build_Repository_Uri: 'https://github.com/powershell/powershellgetv2'
138+
PackageName: 'PowerShellGet'
139+
PackageVersion: '2.2.5.1'
140+
141+
- pwsh: |
142+
$srcModulePath = Resolve-Path -Path "$(signOutPath)" # build drop path -- '$(Build.SourcesDirectory)/signed/PowerShellGet'
143+
$nupkgPath = "$(SignedOutputPath)/nupkg" # '$(Build.SourcesDirectory)/signed/nupkg'
144+
$tmpPkgMgmtDir = "$(SignedOutputPath)/tmpDir" # '$(Build.SourcesDirectory)/signed/tmpDir'
145+
mkdir $nupkgPath
146+
mkdir $tmpPkgMgmtDir
107147
108-
# finally publish the parts of the build which will be used in the next stages
109-
# if it's not published, the subsequent stages will not be able to access it.
110-
# This is the build directory (it contains all of the dll/pdb files)
111-
- publish: "$(Build.SourcesDirectory)/OSS_Microsoft_PowerShellGetv2"
112-
artifact: build
113-
displayName: publish build directory
148+
$srcLocation = [System.Uri] $nupkgPath.ToString()
149+
Register-PSRepository -Name "LocalNupkgRepo" -SourceLocation $srcLocation # '$(Build.SourcesDirectory)/signed/nupkg'
150+
$moduleToPublish = Join-Path -Path $srcModulePath -ChildPath "PowerShellGet" # '$(Build.SourcesDirectory)/signed/PowerShellGet/PowerShellGet'
151+
152+
Save-Module -Name PackageManagement -Repository PSGallery -Path $tmpPkgMgmtDir ## '$(Build.SourcesDirectory)/signed/tmpDir'
153+
Publish-Module -Path (Join-Path -Path $tmpPkgMgmtDir -ChildPath "PackageManagement") -Repository "LocalNupkgRepo" # '$(Build.SourcesDirectory)/signed/nupkg'
154+
155+
Publish-Module -Path $moduleToPublish -Repository "LocalNupkgRepo" # '$(Build.SourcesDirectory)/signed/nupkg'
156+
157+
Remove-Item $nupkgPath/PackageManagement*.nupkg
158+
$artifactName = "$(ModuleName)"
159+
$nupkgName = "nupkg"
160+
Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$nupkgName;]$nupkgPath"
161+
Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$srcModulePath"
162+
displayName: Create module artifacts (including .nupkg)
114163
115164
# Now on to the compliance stage
116165
- stage: compliance
117166
displayName: Compliance
118167
dependsOn: Build
119168
jobs:
120-
- job: Compliance_Job
169+
- job: ComplianceJob
121170
pool:
122-
name: Package ES CodeHub Lab E
171+
name: 1ES
172+
demands:
173+
- ImageOverride -equals PSMMS2019-Secure
174+
123175
steps:
124176
- checkout: self
177+
clean: true
125178
- checkout: ComplianceRepo
179+
clean: true
126180
- download: current
127-
artifact: build
128-
129-
# use the templates in the compliance repo
130-
# since script analyzer has modules, we're using the assembly-module-compliance template
131-
# if you don't have assemblies, you should use script-module-compliance template
181+
artifact: 'PowerShellGet'
132182
- template: script-module-compliance.yml@ComplianceRepo
133183
parameters:
134184
# component-governance - the path to sources
135185
sourceScanPath: '$(Build.SourcesDirectory)'
186+
# credscan
187+
suppressionsFile: ''
136188
# TermCheck
137189
optionsRulesDBPath: ''
138190
optionsFTPath: ''
@@ -141,3 +193,9 @@ stages:
141193
codeBaseName: 'PowerShellGetv2_20200129'
142194
# selections
143195
APIScan: false # set to false when not using Windows APIs.
196+
197+
- stage: Release
198+
displayName: Publish Package to PSGallery
199+
condition: and(and(succeeded(), eq(variables['Build.Reason'], 'Manual')), eq(variables['Publish'], 'True'))
200+
jobs:
201+
- template: release.yml

src/PowerShellGet/PowerShellGet.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'PSModule.psm1'
3-
ModuleVersion = '2.2.5'
3+
ModuleVersion = '2.2.5.1'
44
GUID = '1d73a601-4a6c-43c5-ba3f-619b18bbb404'
55
Author = 'Microsoft Corporation'
66
CompanyName = 'Microsoft Corporation'

0 commit comments

Comments
 (0)