Skip to content

Commit 69825f8

Browse files
committed
Add release automation scripts and documentation
1 parent 78f0103 commit 69825f8

File tree

5 files changed

+123
-1
lines changed

5 files changed

+123
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ App_Data
1111
TestResults
1212
[Tt]humbs.db
1313
buildd.*
14-
build/cxtcache/
14+
release/
1515
*.log
1616
*.bak
1717
packages

scripts/FetchLatestBuild.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
param($buildVersion = $null)
2+
3+
$releasePath = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\release")
4+
$binariesToSignPath = [System.IO.Path]::GetFullPath("$releasePath\BinariesToSign")
5+
$unpackedPackagesPath = [System.IO.Path]::GetFullPath("$releasePath\UnpackedPackages")
6+
7+
# Ensure that the release path exists and clear out old folders
8+
mkdir $releasePath -Force | Out-Null
9+
10+
# Install prerequisite packages
11+
#Install-Package -Name "Nito.AsyncEx" -RequiredVersion "3.0.1" -Source "nuget.org" -ProviderName "NuGet" -Destination $buildPath -Force
12+
#Install-Package -Name "Newtonsoft.Json" -RequiredVersion "7.0.1" -Source "nuget.org" -ProviderName "NuGet" -Destination $buildPath -Force
13+
14+
if ($buildVersion -eq $null) {
15+
# Get the current build status
16+
$headers = @{ "Content-Type" = "application/json" }
17+
$project = Invoke-RestMethod -Method Get -Uri "https://ci.appveyor.com/api/projects/PowerShell/PowerShellEditorServices/branch/master" -Headers $headers
18+
$buildVersion = $project.build.version
19+
if ($project.build.status -eq "success") {
20+
Write-Output "Latest build version on master is $buildVersion`r`n"
21+
}
22+
else {
23+
Write-Error "PowerShellEditorServices build $buildVersion was not successful!" -ErrorAction "Stop"
24+
}
25+
}
26+
27+
function Install-BuildPackage($packageName, $extension) {
28+
$uri = "https://ci.appveyor.com/nuget/powershelleditorservices/api/v2/package/{0}/{1}" -f $packageName.ToLower(), $buildVersion
29+
Write-Verbose "Fetching from URI: $uri"
30+
31+
# Download the package and extract it
32+
$zipPath = "$releasePath\$packageName.zip"
33+
$packageContentPath = "$unpackedPackagesPath\$packageName"
34+
Invoke-WebRequest $uri -OutFile $zipPath -ErrorAction "Stop"
35+
Expand-Archive $zipPath -DestinationPath $packageContentPath -Force -ErrorAction "Stop"
36+
Remove-Item $zipPath -ErrorAction "Stop"
37+
38+
# Copy the binary to the binary signing folder
39+
mkdir $binariesToSignPath -Force | Out-Null
40+
cp "$packageContentPath\lib\net45\$packageName.$extension" -Force -Destination $binariesToSignPath
41+
42+
Write-Output "Extracted package $packageName ($buildVersion)"
43+
}
44+
45+
# Pull the build packages from AppVeyor
46+
Install-BuildPackage "Microsoft.PowerShell.EditorServices" "dll"
47+
Install-BuildPackage "Microsoft.PowerShell.EditorServices.Protocol" "dll"
48+
Install-BuildPackage "Microsoft.PowerShell.EditorServices.Host" "exe"
49+
50+
# Open the BinariesToSign folder
51+
& start $binariesToSignPath

scripts/PackageSignedBinaries.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This script assumes the FetchBuildBinaries.ps1 has been run and
2+
# the binaries in 'release\BinariesToSign' have been signed and
3+
# replaced.
4+
5+
param($FailIfNotSigned = $true)
6+
7+
$releasePath = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\release")
8+
$finalPackagePath = [System.IO.Path]::GetFullPath("$releasePath\FinalPackages")
9+
$binariesToSignPath = [System.IO.Path]::GetFullPath("$releasePath\BinariesToSign")
10+
$unpackedPackagesPath = [System.IO.Path]::GetFullPath("$releasePath\UnpackedPackages")
11+
$nugetPath = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\.nuget\NuGet.exe")
12+
13+
mkdir $finalPackagePath -Force | Out-Null
14+
15+
$binaries = Get-ChildItem $binariesToSignPath
16+
foreach ($binaryPath in $binaries) {
17+
$signature = Get-AuthenticodeSignature $binaryPath.FullName
18+
19+
# TODO: More validation here?
20+
if ($signature.Status -eq "NotSigned" -and $FailIfNotSigned) {
21+
Write-Error "Binary file is not authenticode signed: $binaryPath" -ErrorAction Stop
22+
}
23+
24+
# Copy the file back where it belongs
25+
$packageName = [System.IO.Path]::GetFileNameWithoutExtension($binaryPath)
26+
$packagePath = "$unpackedPackagesPath\$packageName"
27+
cp $binaryPath.FullName -Destination "$packagePath\lib\net45\" -Force
28+
29+
# Repackage the nupkg with NuGet
30+
Push-Location $finalPackagePath
31+
& $nugetPath pack "$packagePath\$packageName.nuspec"
32+
Pop-Location
33+
}

scripts/PublishPackages.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
$releasePath = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\release")
3+
$finalPackagePath = [System.IO.Path]::GetFullPath("$releasePath\FinalPackages")
4+
$nugetPath = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\.nuget\NuGet.exe")
5+
6+
$packages = Get-ChildItem $finalPackagePath -Filter "*.nupkg"
7+
8+
foreach ($package in $packages) {
9+
& $nugetPath push -NonInteractive $package.FullName
10+
if ($LASTEXITCODE -ne 0)
11+
{
12+
Write-Output "`r`n'nuget push' has failed. You may need to run the following command to set the NuGet account API key:`r`n"
13+
Write-Output "& $nuGetPath setApiKey"
14+
break
15+
}
16+
else
17+
{
18+
Write-Output "Pushed package $package.FullName"
19+
}
20+
}
21+
22+
# TODO: Use Find-Package to verify that the package is there?

scripts/ReleaseProcess.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## PowerShell Editor Services Release Process
2+
3+
1. Find the latest build version for the `master` branch on AppVeyor:
4+
5+
2. Run `.\scripts\FetchLatestBuild.ps1`
6+
7+
3. Once this script completes, sign the binaries in `.\release\BinariesToSign`.
8+
9+
4. Once you have the authenticode-signed binaries, copy them back into
10+
`.\release\BinariesToSign`
11+
12+
5. Run `.\scripts\PackageSignedBinaries.ps1`. If any binaries didn't get signed
13+
correctly, this script will tell you. Once this script completes, the updated
14+
.nupkg files will be in `.\release\FinalPackages`
15+
16+
6. Run `.\scripts\PublishPackages.ps1` to publish the final packages to NuGet.

0 commit comments

Comments
 (0)