Skip to content

Commit e829053

Browse files
TravisEz13daxian-dbw
authored andcommitted
Add ability to package all of powershell core as a NuGet Package (PowerShell#4363)
So that PowerShell can be installed using PackageManagement cmdlets find-package and install-package.
1 parent 10a27b8 commit e829053

9 files changed

Lines changed: 445 additions & 70 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dotnet-uninstall-debian-packages.sh
3838
*.zip
3939
*.rpm
4040
*.pkg
41+
*.nupkg
4142

4243
# ignore the version file as it is generated at build time
4344
powershell.version

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 6.0.0-beta.4-{build}
1+
# version is set in tools\appveyor.psm1 - Invoke-AppVeyorInstall
22

33
image: Visual Studio 2017
44

build.psm1

Lines changed: 93 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,90 @@ $script:TestModulePathSeparator = [System.IO.Path]::PathSeparator
55
$dotnetCLIChannel = "preview"
66
$dotnetCLIRequiredVersion = "2.0.0-preview2-006502"
77

8+
# Track if tags have been sync'ed
9+
$tagsUpToDate = $false
10+
11+
# Sync Tags
12+
# When not using a branch in PowerShell/PowerShell, tags will not be fetched automatically
13+
# Since code that uses Get-PSCommitID and Get-PSLatestTag assume that tags are fetched,
14+
# This function can ensure that tags have been fetched.
15+
# This function is used during the setup phase in tools/appveyor.psm1 and tools/travis.ps1
16+
function Sync-PSTags
17+
{
18+
param(
19+
[Switch]
20+
$AddRemoteIfMissing
21+
)
22+
23+
$PowerShellRemoteUrl = "https://github.com/powershell/powershell.git"
24+
$upstreamRemoteDefaultName = 'upstream'
25+
$remotes = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" remote}
26+
$upstreamRemote = $null
27+
foreach($remote in $remotes)
28+
{
29+
$url = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" remote get-url $remote}
30+
if($url -eq $PowerShellRemoteUrl)
31+
{
32+
$upstreamRemote = $remote
33+
break
34+
}
35+
}
36+
37+
if(!$upstreamRemote -and $AddRemoteIfMissing.IsPresent -and $remotes -notcontains $upstreamRemoteDefaultName)
38+
{
39+
$null = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" remote add $upstreamRemoteDefaultName $PowerShellRemoteUrl}
40+
$upstreamRemote = $upstreamRemoteDefaultName
41+
}
42+
elseif(!$upstreamRemote)
43+
{
44+
Write-Error "Please add a remote to PowerShell\PowerShell. Example: git remote add $upstreamRemoteDefaultName $PowerShellRemoteUrl" -ErrorAction Stop
45+
}
46+
47+
$null = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" fetch --tags --quiet $upstreamRemote}
48+
$script:tagsUpToDate=$true
49+
}
50+
51+
# Gets the latest tag for the current branch
52+
function Get-PSLatestTag
53+
{
54+
# This function won't always return the correct value unless tags have been sync'ed
55+
# So, Write a warning to run Sync-PSTags
56+
if(!$tagsUpToDate)
57+
{
58+
Write-Warning "Run Sync-PSTags to update tags"
59+
}
60+
61+
return (Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" describe --abbrev=0})
62+
}
63+
64+
function Get-PSVersion
65+
{
66+
param(
67+
[switch]
68+
$OmitCommitId
69+
)
70+
if($OmitCommitId.IsPresent)
71+
{
72+
return (Get-PSLatestTag) -replace '^v'
73+
}
74+
else
75+
{
76+
return (Get-PSCommitId) -replace '^v'
77+
}
78+
}
79+
80+
function Get-PSCommitId
81+
{
82+
# This function won't always return the correct value unless tags have been sync'ed
83+
# So, Write a warning to run Sync-PSTags
84+
if(!$tagsUpToDate)
85+
{
86+
Write-Warning "Run Sync-PSTags to update tags"
87+
}
88+
89+
return (Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60})
90+
}
91+
892
function Get-EnvironmentInformation
993
{
1094
$environment = @{}
@@ -268,7 +352,7 @@ function Start-PSBuild {
268352
$gitCommitId = $ReleaseTag
269353
if (-not $gitCommitId) {
270354
# if ReleaseTag is not specified, use 'git describe' to get the commit id
271-
$gitCommitId = git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60
355+
$gitCommitId = Get-PSCommitId
272356
}
273357
$gitCommitId > "$psscriptroot/powershell.version"
274358

@@ -1934,35 +2018,6 @@ function script:Start-NativeExecution([scriptblock]$sb, [switch]$IgnoreExitcode)
19342018
}
19352019
}
19362020

1937-
# Builds coming out of this project can have version number as 'a.b.c-stringf.d-e-f' OR 'a.b.c.d-e-f'
1938-
# This function converts the above version into semantic version major.minor[.build-quality[.revision]] format
1939-
function Get-PackageSemanticVersion
1940-
{
1941-
[CmdletBinding()]
1942-
param (
1943-
# Version of the Package
1944-
[Parameter(Mandatory = $true)]
1945-
[ValidateNotNullOrEmpty()]
1946-
[string] $Version
1947-
)
1948-
1949-
Write-Verbose "Extract the semantic version in the form of major.minor[.build-quality[.revision]] for $Version"
1950-
$packageVersionTokens = $Version.Split('.')
1951-
1952-
if (3 -eq $packageVersionTokens.Count) {
1953-
# In case the input is of the form a.b.c, add a '0' at the end for revision field
1954-
$packageSemanticVersion = $Version,'0' -join '.'
1955-
} elseif (3 -lt $packageVersionTokens.Count) {
1956-
# We have all the four fields
1957-
$packageRevisionTokens = ($packageVersionTokens[3].Split('-'))[0]
1958-
$packageSemanticVersion = $packageVersionTokens[0],$packageVersionTokens[1],$packageVersionTokens[2],$packageRevisionTokens -join '.'
1959-
} else {
1960-
throw "Cannot create Semantic Version from the string $Version containing 4 or more tokens"
1961-
}
1962-
1963-
$packageSemanticVersion
1964-
}
1965-
19662021
# Builds coming out of this project can have version number as 'a.b.c' OR 'a.b.c-d-f'
19672022
# This function converts the above version into major.minor[.build[.revision]] format
19682023
function Get-PackageVersionAsMajorMinorBuildRevision
@@ -2035,8 +2090,10 @@ function New-MSIPackage
20352090
[Parameter(Mandatory = $true)]
20362091
[ValidateSet("x86", "x64")]
20372092
[ValidateNotNullOrEmpty()]
2038-
[string] $ProductTargetArchitecture
2093+
[string] $ProductTargetArchitecture,
20392094

2095+
# Force overwrite of package
2096+
[Switch] $Force
20402097
)
20412098

20422099
## AppVeyor base image might update the version for Wix. Hence, we should
@@ -2095,7 +2152,11 @@ function New-MSIPackage
20952152
$packageName += "-$ProductNameSuffix"
20962153
}
20972154
$msiLocationPath = Join-Path $pwd "$packageName.msi"
2098-
Remove-Item -ErrorAction SilentlyContinue $msiLocationPath -Force
2155+
2156+
if(!$Force.IsPresent -and (Test-Path -Path $msiLocationPath))
2157+
{
2158+
Write-Error -Message "Package already exists, use -Force to overwrite, path: $msiLocationPath" -ErrorAction Stop
2159+
}
20992160

21002161
& $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v | Write-Verbose
21012162
& $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -ext WixUIExtension -ext WixUtilExtension -arch x64 -v | Write-Verbose

tools/appveyor.psm1

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ function Invoke-AppVeyorBuild
189189
# Implements the AppVeyor 'install' step
190190
function Invoke-AppVeyorInstall
191191
{
192+
# Make sure we have all the tags
193+
Sync-PSTags -AddRemoteIfMissing
194+
if($env:APPVEYOR_BUILD_NUMBER)
195+
{
196+
Update-AppveyorBuild -Version "$(Get-PSVersion -OmitCommitId)-$env:APPVEYOR_BUILD_NUMBER"
197+
}
198+
192199
if(Test-DailyBuild){
193200
$buildName = "[Daily]"
194201

@@ -434,8 +441,14 @@ function Get-PackageName
434441
function Invoke-AppveyorFinish
435442
{
436443
try {
444+
$packageParams = @{}
445+
if($env:APPVEYOR_BUILD_VERSION)
446+
{
447+
$packageParams += @{Version=$env:APPVEYOR_BUILD_VERSION}
448+
}
449+
437450
# Build packages
438-
$packages = Start-PSPackage
451+
$packages = Start-PSPackage @packageParams
439452

440453
$name = Get-PackageName
441454

@@ -503,6 +516,12 @@ function Invoke-AppveyorFinish
503516
$pushedAllArtifacts = $false
504517
Write-Warning "Artifact $_ does not exist."
505518
}
519+
520+
if($env:NUGET_KEY -and $env:NUGET_URL -and [system.io.path]::GetExtension($_) -ieq '.nupkg')
521+
{
522+
log "pushing $_ to $env:NUGET_URL"
523+
Start-NativeExecution -sb {dotnet nuget push $_ --api-key $env:NUGET_KEY --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode
524+
}
506525
}
507526
if(!$pushedAllArtifacts)
508527
{

tools/packaging/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
staging/
2+
nugetStaging/

0 commit comments

Comments
 (0)