Skip to content

Commit 1479ed6

Browse files
authored
Scripts needed to build and sign PSSA via MS VSTS so it can be published in the gallery (#983)
* First set of files for vsts build * Added scripts for VSTS build Updated docker file and releasemaker module * Change vsts build script to be able to put built module anywhere based on _DockerVolume_ Remove a comment * Revert "Change vsts build script to be able to put built module anywhere based on _DockerVolume_" This reverts commit 82ebc03.
1 parent c315bc5 commit 1479ed6

File tree

8 files changed

+313
-2
lines changed

8 files changed

+313
-2
lines changed

Utils/ReleaseMaker.psm1

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function New-ReleaseBuild
9292
Push-Location $solutionPath
9393
try
9494
{
95-
remove-item out/ -recurse -force
95+
if ( test-path out ) { remove-item out/ -recurse -force }
9696
.\buildCoreClr.ps1 -Framework net451 -Configuration Release -Build
9797
.\buildCoreClr.ps1 -Framework net451 -Configuration PSV3Release -Build
9898
.\buildCoreClr.ps1 -Framework netstandard2.0 -Configuration Release -Build
@@ -196,4 +196,4 @@ function Set-ContentUtf8NoBom {
196196
}
197197

198198
Export-ModuleMember -Function New-Release
199-
Export-ModuleMember -Function New-ReleaseBuild
199+
Export-ModuleMember -Function New-ReleaseBuild

tools/releaseBuild/Image/DockerFile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# escape=`
2+
#0.3.6 (no powershell 6)
3+
# FROM microsoft/windowsservercore
4+
FROM microsoft/dotnet-framework:4.7.1
5+
LABEL maintainer='PowerShell Team <[email protected]>'
6+
LABEL description="This Dockerfile for Windows Server Core with git installed via chocolatey."
7+
8+
SHELL ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
9+
# Install Git, and platyPS
10+
# Git installs to C:\Program Files\Git
11+
# nuget installs to C:\ProgramData\chocolatey\bin\NuGet.exe
12+
COPY dockerInstall.psm1 containerFiles/dockerInstall.psm1
13+
14+
RUN Import-Module PackageManagement; `
15+
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force; `
16+
Import-Module ./containerFiles/dockerInstall.psm1; `
17+
Install-ChocolateyPackage -PackageName git -Executable git.exe; `
18+
Install-ChocolateyPackage -PackageName nuget.commandline -Executable nuget.exe -Cleanup; `
19+
Install-Module -Force -Name platyPS; `
20+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1 -outfile C:/dotnet-install.ps1; `
21+
C:/dotnet-install.ps1 -Channel Release -Version 2.1.4; `
22+
Add-Path C:/Users/ContainerAdministrator/AppData/Local/Microsoft/dotnet;
23+
24+
RUN Import-Module ./containerFiles/dockerInstall.psm1; `
25+
# git clone https://Github.com/PowerShell/PSScriptAnalyzer; `
26+
Install-ChocolateyPackage -PackageName dotnet4.5;
27+
28+
RUN Import-Module ./containerFiles/dockerInstall.psm1; `
29+
Install-ChocolateyPackage -PackageName netfx-4.5.1-devpack;
30+
31+
COPY buildPSSA.ps1 containerFiles/buildPSSA.ps1
32+
33+
ENTRYPOINT ["C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "-command"]
34+
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
push-location C:/PSScriptAnalyzer
2+
import-module C:/PSScriptAnalyzer/Utils/ReleaseMaker.psm1
3+
New-ReleaseBuild
4+
Copy-Item -Recurse C:/PSScriptAnalyzer/out C:/
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
function Install-ChocolateyPackage
2+
{
3+
param(
4+
[Parameter(Mandatory=$true)]
5+
[string]
6+
$PackageName,
7+
8+
[Parameter(Mandatory=$false)]
9+
[string]
10+
$Executable,
11+
12+
[string[]]
13+
$ArgumentList,
14+
15+
[switch]
16+
$Cleanup,
17+
18+
[int]
19+
$ExecutionTimeout = 2700,
20+
21+
[string]
22+
$Version
23+
)
24+
25+
if(-not(Get-Command -name Choco -ErrorAction SilentlyContinue))
26+
{
27+
Write-Verbose "Installing Chocolatey provider..." -Verbose
28+
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
29+
}
30+
31+
Write-Verbose "Installing $PackageName..." -Verbose
32+
$extraCommand = @()
33+
if($Version)
34+
{
35+
$extraCommand += '--version', $version
36+
}
37+
choco install -y $PackageName --no-progress --execution-timeout=$ExecutionTimeout $ArgumentList $extraCommands
38+
39+
if($executable)
40+
{
41+
Write-Verbose "Verifing $Executable is in path..." -Verbose
42+
$exeSource = $null
43+
$exeSource = Get-ChildItem -path "$env:ProgramFiles\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
44+
if(!$exeSource)
45+
{
46+
Write-Verbose "Falling back to x86 program files..." -Verbose
47+
$exeSource = Get-ChildItem -path "${env:ProgramFiles(x86)}\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
48+
}
49+
50+
# Don't search the chocolatey program data until more official locations have been searched
51+
if(!$exeSource)
52+
{
53+
Write-Verbose "Falling back to chocolatey..." -Verbose
54+
$exeSource = Get-ChildItem -path "$env:ProgramData\chocolatey\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
55+
}
56+
57+
# all obvious locations are exhausted, use brute force and search from the root of the filesystem
58+
if(!$exeSource)
59+
{
60+
Write-Verbose "Falling back to the root of the drive..." -Verbose
61+
$exeSource = Get-ChildItem -path "/$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
62+
}
63+
64+
if(!$exeSource)
65+
{
66+
throw "$Executable not found"
67+
}
68+
69+
$exePath = Split-Path -Path $exeSource
70+
Add-Path -path $exePath
71+
}
72+
73+
if($Cleanup.IsPresent)
74+
{
75+
Remove-Folder -Folder "$env:temp\chocolatey"
76+
}
77+
}
78+
79+
function Add-Path
80+
{
81+
param
82+
(
83+
$path
84+
)
85+
$machinePathString = [System.Environment]::GetEnvironmentVariable('path',[System.EnvironmentVariableTarget]::Machine)
86+
$machinePath = $machinePathString -split ';'
87+
88+
if($machinePath -inotcontains $path)
89+
{
90+
$newPath = "$machinePathString;$path"
91+
Write-Verbose "Adding $path to path..." -Verbose
92+
[System.Environment]::SetEnvironmentVariable('path',$newPath,[System.EnvironmentVariableTarget]::Machine)
93+
Write-Verbose "Added $path to path." -Verbose
94+
$env:Path += ";$newPath"
95+
}
96+
else
97+
{
98+
Write-Verbose "$path already in path." -Verbose
99+
}
100+
}
101+
102+
function Remove-Folder
103+
{
104+
param(
105+
[string]
106+
$Folder
107+
)
108+
109+
Write-Verbose "Cleaning up $Folder..." -Verbose
110+
$filter = Join-Path -Path $Folder -ChildPath *
111+
[int]$measuredCleanupMB = (Get-ChildItem $filter -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
112+
Remove-Item -recurse -force $filter -ErrorAction SilentlyContinue
113+
Write-Verbose "Cleaned up $measuredCleanupMB MB from $Folder" -Verbose
114+
}

tools/releaseBuild/build.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Windows": {
3+
"Name": "win7-x64",
4+
"RepoDestinationPath": "C:\\PSScriptAnalyzer",
5+
"BuildCommand": "C:\\containerFiles\\buildPSSA.ps1",
6+
"DockerFile": ".\\tools\\releaseBuild\\Image\\DockerFile",
7+
"DockerImageName": "pssa",
8+
"BinaryBucket": "release",
9+
"PublishAsFolder": true,
10+
"AdditionalContextFiles" : [
11+
".\\tools\\releaseBuild\\Image\\buildPSSA.ps1",
12+
".\\tools\\releaseBuild\\Image\\dockerInstall.psm1"
13+
]
14+
}
15+
}

tools/releaseBuild/signing.xml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<SignConfigXML>
3+
<!-- ****Begin**** BothDual - Dual (Sha256 and Sha1) AuthenticodeDual) and should be StrongName, but we will add this in 6.1.0 ******** -->
4+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer" approvers="vigarg;gstolt">
5+
<file src="__INPATHROOT__\PSScriptAnalyzer\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="AuthenticodeDual" dest="__OUTPATHROOT__\PSScriptAnalyzer\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
6+
<file src="__INPATHROOT__\PSScriptAnalyzer\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="AuthenticodeDual" dest="__OUTPATHROOT__\PSScriptAnalyzer\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
7+
<file src="__INPATHROOT__\PSScriptAnalyzer\PSScriptAnalyzer.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\PSScriptAnalyzer.psd1" />
8+
<file src="__INPATHROOT__\PSScriptAnalyzer\PSScriptAnalyzer.psm1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\PSScriptAnalyzer.psm1" />
9+
<file src="__INPATHROOT__\PSScriptAnalyzer\ScriptAnalyzer.format.ps1xml" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\ScriptAnalyzer.format.ps1xml" />
10+
<file src="__INPATHROOT__\PSScriptAnalyzer\ScriptAnalyzer.types.ps1xml" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\ScriptAnalyzer.types.ps1xml" />
11+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\CmdletDesign.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\CmdletDesign.psd1" />
12+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\CodeFormatting.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\CodeFormatting.psd1" />
13+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\CodeFormattingAllman.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\CodeFormattingAllman.psd1" />
14+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\CodeFormattingOTBS.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\CodeFormattingOTBS.psd1" />
15+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\CodeFormattingStroustrup.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\CodeFormattingStroustrup.psd1" />
16+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\DSC.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\DSC.psd1" />
17+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\PSGallery.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\PSGallery.psd1" />
18+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\ScriptFunctions.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\ScriptFunctions.psd1" />
19+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\ScriptingStyle.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\ScriptingStyle.psd1" />
20+
<file src="__INPATHROOT__\PSScriptAnalyzer\Settings\ScriptSecurity.psd1" signType="Authenticode" dest="__OUTPATHROOT__\PSScriptAnalyzer\Settings\ScriptSecurity.psd1" />
21+
</job>
22+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer core" approvers="vigarg;gstolt">
23+
<file src="__INPATHROOT__\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="AuthenticodeDual" dest="__OUTPATHROOT__\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
24+
<file src="__INPATHROOT__\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="AuthenticodeDual" dest="__OUTPATHROOT__\PSScriptAnalyzer\coreclr\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
25+
</job>
26+
<job platform="" configuration="" dest="__OUTPATHROOT__\signed" jobname="PowerShell Script Analyzer PSv3" approvers="vigarg;gstolt">
27+
<file src="__INPATHROOT__\PSScriptAnalyzer\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" signType="AuthenticodeDual" dest="__OUTPATHROOT__\PSScriptAnalyzer\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll" />
28+
<file src="__INPATHROOT__\PSScriptAnalyzer\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" signType="AuthenticodeDual" dest="__OUTPATHROOT__\PSScriptAnalyzer\PSv3\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll" />
29+
</job>
30+
</SignConfigXML>

tools/releaseBuild/updateSigning.ps1

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
param(
4+
[string] $SigningXmlPath = (Join-Path -Path $PSScriptRoot -ChildPath 'signing.xml')
5+
)
6+
# Script for use in VSTS to update signing.xml
7+
8+
# Parse the signing xml
9+
$signingXml = [xml](Get-Content $signingXmlPath)
10+
11+
# Get any variables to updating 'signType' in the XML
12+
# Define a varabile named `<signTypeInXml>SignType' in VSTS to updating that signing type
13+
# Example: $env:AuthenticodeSignType='newvalue'
14+
# will cause all files with the 'Authenticode' signtype to be updated with the 'newvalue' signtype
15+
$signTypes = @{}
16+
Get-ChildItem -Path env:/*SignType | ForEach-Object -Process {
17+
$signType = $_.Name.ToUpperInvariant().Replace('SIGNTYPE','')
18+
Write-Host "Found SigningType $signType with value $($_.value)"
19+
$signTypes[$signType] = $_.Value
20+
}
21+
22+
# examine each job in the xml
23+
$signingXml.SignConfigXML.job | ForEach-Object -Process {
24+
# examine each file in the job
25+
$_.file | ForEach-Object -Process {
26+
# if the sign type is one of the variables we found, update it to the new value
27+
$signType = $_.SignType.ToUpperInvariant()
28+
if($signTypes.ContainsKey($signType))
29+
{
30+
$newSignType = $signTypes[$signType]
31+
Write-Host "Updating $($_.src) to $newSignType"
32+
$_.signType = $newSignType
33+
}
34+
}
35+
}
36+
37+
$signingXml.Save($signingXmlPath)

tools/releaseBuild/vstsbuild.ps1

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[cmdletbinding()]
2+
param(
3+
[Parameter(Mandatory=$true,Position=0)]
4+
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d+)?)?$")]
5+
[string]$ReleaseTag
6+
)
7+
8+
Begin
9+
{
10+
$ErrorActionPreference = 'Stop'
11+
12+
$gitBinFullPath = (Get-Command -Name git -CommandType Application).Path | Select-Object -First 1
13+
if ( ! $gitBinFullPath )
14+
{
15+
throw "Git is missing! Install from 'https://git-scm.com/download/win'"
16+
}
17+
18+
# clone the release tools
19+
$releaseToolsDirName = "PSRelease"
20+
$releaseToolsLocation = Join-Path -Path $PSScriptRoot -ChildPath PSRelease
21+
if ( Test-Path $releaseToolsLocation )
22+
{
23+
Remove-Item -Force -Recurse -Path $releaseToolsLocation
24+
}
25+
& $gitBinFullPath clone -b master --quiet https://github.com/PowerShell/${releaseToolsDirName}.git $releaseToolsLocation
26+
Import-Module "$releaseToolsLocation/vstsBuild" -Force
27+
Import-Module "$releaseToolsLocation/dockerBasedBuild" -Force
28+
}
29+
30+
End {
31+
32+
$AdditionalFiles = .{
33+
Join-Path $PSScriptRoot -child "Image/buildPSSA.ps1"
34+
Join-Path $PSScriptRoot -child "Image/dockerInstall.psm1"
35+
}
36+
$buildPackageName = $null
37+
38+
# defined if building in VSTS
39+
if($env:BUILD_STAGINGDIRECTORY)
40+
{
41+
# Use artifact staging if running in VSTS
42+
$destFolder = $env:BUILD_STAGINGDIRECTORY
43+
}
44+
else
45+
{
46+
# Use temp as destination if not running in VSTS
47+
$destFolder = $env:temp
48+
}
49+
50+
$resolvedRepoRoot = (Resolve-Path (Join-Path -Path $PSScriptRoot -ChildPath "../../")).Path
51+
52+
try
53+
{
54+
Write-Verbose "Starting build at $resolvedRepoRoot ..." -Verbose
55+
Clear-VstsTaskState
56+
57+
$buildParameters = @{
58+
ReleaseTag = $ReleaseTag
59+
}
60+
$buildArgs = @{
61+
RepoPath = $resolvedRepoRoot
62+
BuildJsonPath = './tools/releaseBuild/build.json'
63+
Parameters = $buildParameters
64+
AdditionalFiles = $AdditionalFiles
65+
Name = "win7-x64"
66+
}
67+
Invoke-Build @buildArgs
68+
}
69+
catch
70+
{
71+
Write-VstsError -Error $_
72+
}
73+
finally{
74+
Write-VstsTaskState
75+
exit 0
76+
}
77+
}

0 commit comments

Comments
 (0)