Skip to content

Commit 9bf7364

Browse files
committed
Add artifact versioning, packaging, and publishing to .build.ps1
1 parent 41ac945 commit 9bf7364

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

.build.ps1

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
param(
22
[ValidateSet("Debug", "Release")]
3-
$Configuration = "Debug"
3+
[string]$Configuration = "Debug"
44
)
55

66
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}
77

8-
if ($env:APPVEYOR -ne $null) {
9-
dotnet --info
10-
}
8+
$script:IsCIBuild = $env:APPVEYOR -ne $null
119

1210
task SetupDotNet -Before Restore, Clean, Build, BuildHost, Test, TestPowerShellApi {
1311

@@ -67,6 +65,25 @@ task Restore {
6765

6866
task Clean {
6967
exec { & dotnet clean }
68+
Get-ChildItem -Recurse src\*.nupkg | Remove-Item -Force -ErrorAction Ignore
69+
Get-ChildItem module\*.zip | Remove-Item -Force -ErrorAction Ignore
70+
}
71+
72+
task GetProductVersion -Before PackageNuGet, PackageModule, UploadArtifacts {
73+
if ($script:BaseVersion) { return }
74+
[xml]$props = Get-Content .\PowerShellEditorServices.Common.props
75+
76+
$script:VersionSuffix = $props.Project.PropertyGroup.VersionSuffix
77+
$script:BaseVersion = "$($props.Project.PropertyGroup.VersionPrefix)-$($props.Project.PropertyGroup.VersionSuffix)"
78+
$script:FullVersion = "$($props.Project.PropertyGroup.VersionPrefix)-$($props.Project.PropertyGroup.VersionSuffix)"
79+
80+
if ($env:APPVEYOR) {
81+
$script:BuildNumber = $env:APPVEYOR_BUILD_NUMBER
82+
$script:FullVersion = "$script:FullVersion-$script:BuildNumber"
83+
$script:VersionSuffix = "$script:VersionSuffix-$script:BuildNumber"
84+
}
85+
86+
Write-Host "`n### Product Version: $script:FullVersion`n" -ForegroundColor Green
7087
}
7188

7289
function BuildForPowerShellVersion($version) {
@@ -87,7 +104,6 @@ task TestPowerShellApi {
87104
}
88105

89106
task BuildHost {
90-
# This task is meant to be used in a quick dev cycle so no 'restore' is done first
91107
exec { & dotnet build -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
92108
}
93109

@@ -116,5 +132,29 @@ task LayoutModule -After Build, BuildHost {
116132
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
117133
}
118134

135+
task PackageNuGet {
136+
exec { & dotnet pack -c $Configuration --no-build --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
137+
exec { & dotnet pack -c $Configuration --no-build --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices.Protocol\PowerShellEditorServices.Protocol.csproj }
138+
exec { & dotnet pack -c $Configuration --no-build --version-suffix $script:VersionSuffix .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj }
139+
}
140+
141+
task PackageModule {
142+
Add-Type -Assembly System.IO.Compression.FileSystem
143+
[System.IO.Compression.ZipFile]::CreateFromDirectory(
144+
"$PSScriptRoot/module/PowerShellEditorServices",
145+
"$PSScriptRoot/module/PowerShellEditorServices-$($script:FullVersion).zip",
146+
[System.IO.Compression.CompressionLevel]::Optimal,
147+
$true)
148+
}
149+
150+
task UploadArtifacts -If ($script:IsCIBuild) {
151+
if ($env:APPVEYOR) {
152+
Push-AppveyorArtifact .\src\PowerShellEditorServices\bin\$Configuration\Microsoft.PowerShell.EditorServices.$($script:FullVersion).nupkg
153+
Push-AppveyorArtifact .\src\PowerShellEditorServices.Protocol\bin\$Configuration\Microsoft.PowerShell.EditorServices.Protocol.$($script:FullVersion).nupkg
154+
Push-AppveyorArtifact .\src\PowerShellEditorServices.Host\bin\$Configuration\Microsoft.PowerShell.EditorServices.Host.$($script:FullVersion).nupkg
155+
Push-AppveyorArtifact .\module\PowerShellEditorServices-$($script:FullVersion).zip
156+
}
157+
}
158+
119159
# The default task is to run the entire CI build
120-
task . Restore, Clean, Build, TestPowerShellApi, Test
160+
task . GetProductVersion, Restore, Clean, Build, TestPowerShellApi, Test, PackageNuGet, PackageModule, UploadArtifacts

appveyor.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
version: '$(core_version).{build}'
1+
version: '0.9.0.{build}'
22
os: WMF 5
33
clone_depth: 10
44
skip_tags: true
55

6-
environment:
7-
core_version: '0.9.0'
8-
prerelease_name: '-beta'
9-
106
branches:
117
only:
128
- master
139
- develop
1410

15-
# NOTE: If you need to debug a problem with the AppVeyor build, uncomment the
16-
# following two lines and push them to your PR branch. Once the next
17-
# build starts you will see RDP connection details written out to the
18-
# build console. **DON'T FORGET TO REMOVE THIS COMMIT BEFORE MERGING!**
19-
20-
#init:
21-
#- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
22-
23-
# TODO: Work build number into build!
24-
2511
install:
2612
- ps: |
2713
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null

0 commit comments

Comments
 (0)