Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dotnet-uninstall-debian-packages.sh
*.zip
*.rpm
*.pkg
*.nupkg

# ignore the version file as it is generated at build time
powershell.version
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 6.0.0-beta.4-{build}
# version is set in tools\appveyor.psm1 - Invoke-AppVeyorInstall

image: Visual Studio 2017

Expand Down
125 changes: 93 additions & 32 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,90 @@ $script:TestModulePathSeparator = [System.IO.Path]::PathSeparator
$dotnetCLIChannel = "preview"
$dotnetCLIRequiredVersion = "2.0.0-preview2-006502"

# Track if tags have been sync'ed
$tagsUpToDate = $false

# Sync Tags
# When not using a branch in PowerShell/PowerShell, tags will not be fetched automatically
# Since code that uses Get-PSCommitID and Get-PSLatestTag assume that tags are fetched,
# This function can ensure that tags have been fetched.
# This function is used during the setup phase in tools/appveyor.psm1 and tools/travis.ps1
function Sync-PSTags
{
param(
[Switch]
$AddRemoteIfMissing
)

$PowerShellRemoteUrl = "https://github.com/powershell/powershell.git"
$upstreamRemoteDefaultName = 'upstream'
$remotes = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" remote}
$upstreamRemote = $null
foreach($remote in $remotes)
{
$url = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" remote get-url $remote}
if($url -eq $PowerShellRemoteUrl)
{
$upstreamRemote = $remote
break
}
}

if(!$upstreamRemote -and $AddRemoteIfMissing.IsPresent -and $remotes -notcontains $upstreamRemoteDefaultName)
{
$null = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" remote add $upstreamRemoteDefaultName $PowerShellRemoteUrl}
$upstreamRemote = $upstreamRemoteDefaultName
}
elseif(!$upstreamRemote)
{
Write-Error "Please add a remote to PowerShell\PowerShell. Example: git remote add $upstreamRemoteDefaultName $PowerShellRemoteUrl" -ErrorAction Stop

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we continue to execute the script after the error?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not continue executing the script unless you have a remote to PowerShell as the error indicates. The script has always assumed you can fetch the tags. This is just adding a verification.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only occur when someone manually runs the function and it cannot complete the action. So, returning an error and stopping is the correct thing to do.

}

$null = Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" fetch --tags --quiet $upstreamRemote}
$script:tagsUpToDate=$true
}

# Gets the latest tag for the current branch
function Get-PSLatestTag
{
# This function won't always return the correct value unless tags have been sync'ed
# So, Write a warning to run Sync-PSTags
if(!$tagsUpToDate)
{
Write-Warning "Run Sync-PSTags to update tags"
}

return (Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" describe --abbrev=0})
}

function Get-PSVersion
{
param(
[switch]
$OmitCommitId
)
if($OmitCommitId.IsPresent)
{
return (Get-PSLatestTag) -replace '^v'
}
else
{
return (Get-PSCommitId) -replace '^v'
}
}

function Get-PSCommitId
{
# This function won't always return the correct value unless tags have been sync'ed
# So, Write a warning to run Sync-PSTags
if(!$tagsUpToDate)
{
Write-Warning "Run Sync-PSTags to update tags"
}

return (Start-NativeExecution {git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60})
}

function Get-EnvironmentInformation
{
$environment = @{}
Expand Down Expand Up @@ -268,7 +352,7 @@ function Start-PSBuild {
$gitCommitId = $ReleaseTag
if (-not $gitCommitId) {
# if ReleaseTag is not specified, use 'git describe' to get the commit id
$gitCommitId = git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60
$gitCommitId = Get-PSCommitId
}
$gitCommitId > "$psscriptroot/powershell.version"

Expand Down Expand Up @@ -1934,35 +2018,6 @@ function script:Start-NativeExecution([scriptblock]$sb, [switch]$IgnoreExitcode)
}
}

# 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'
# This function converts the above version into semantic version major.minor[.build-quality[.revision]] format
function Get-PackageSemanticVersion
{
[CmdletBinding()]
param (
# Version of the Package
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $Version
)

Write-Verbose "Extract the semantic version in the form of major.minor[.build-quality[.revision]] for $Version"
$packageVersionTokens = $Version.Split('.')

if (3 -eq $packageVersionTokens.Count) {
# In case the input is of the form a.b.c, add a '0' at the end for revision field
$packageSemanticVersion = $Version,'0' -join '.'
} elseif (3 -lt $packageVersionTokens.Count) {
# We have all the four fields
$packageRevisionTokens = ($packageVersionTokens[3].Split('-'))[0]
$packageSemanticVersion = $packageVersionTokens[0],$packageVersionTokens[1],$packageVersionTokens[2],$packageRevisionTokens -join '.'
} else {
throw "Cannot create Semantic Version from the string $Version containing 4 or more tokens"
}

$packageSemanticVersion
}

# Builds coming out of this project can have version number as 'a.b.c' OR 'a.b.c-d-f'
# This function converts the above version into major.minor[.build[.revision]] format
function Get-PackageVersionAsMajorMinorBuildRevision
Expand Down Expand Up @@ -2035,8 +2090,10 @@ function New-MSIPackage
[Parameter(Mandatory = $true)]
[ValidateSet("x86", "x64")]
[ValidateNotNullOrEmpty()]
[string] $ProductTargetArchitecture
[string] $ProductTargetArchitecture,

# Force overwrite of package
[Switch] $Force
)

## AppVeyor base image might update the version for Wix. Hence, we should
Expand Down Expand Up @@ -2095,7 +2152,11 @@ function New-MSIPackage
$packageName += "-$ProductNameSuffix"
}
$msiLocationPath = Join-Path $pwd "$packageName.msi"
Remove-Item -ErrorAction SilentlyContinue $msiLocationPath -Force

if(!$Force.IsPresent -and (Test-Path -Path $msiLocationPath))
{
Write-Error -Message "Package already exists, use -Force to overwrite, path: $msiLocationPath" -ErrorAction Stop
}

& $wixHeatExePath dir $ProductSourcePath -dr $productVersionWithName -cg $productVersionWithName -gg -sfrag -srd -scom -sreg -out $wixFragmentPath -var env.ProductSourcePath -v | Write-Verbose
& $wixCandleExePath "$ProductWxsPath" "$wixFragmentPath" -out (Join-Path "$env:Temp" "\\") -ext WixUIExtension -ext WixUtilExtension -arch x64 -v | Write-Verbose
Expand Down
21 changes: 20 additions & 1 deletion tools/appveyor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ function Invoke-AppVeyorBuild
# Implements the AppVeyor 'install' step
function Invoke-AppVeyorInstall
{
# Make sure we have all the tags
Sync-PSTags -AddRemoteIfMissing
if($env:APPVEYOR_BUILD_NUMBER)
{
Update-AppveyorBuild -Version "$(Get-PSVersion -OmitCommitId)-$env:APPVEYOR_BUILD_NUMBER"
}

if(Test-DailyBuild){
$buildName = "[Daily]"

Expand Down Expand Up @@ -434,8 +441,14 @@ function Get-PackageName
function Invoke-AppveyorFinish
{
try {
$packageParams = @{}
if($env:APPVEYOR_BUILD_VERSION)
{
$packageParams += @{Version=$env:APPVEYOR_BUILD_VERSION}
}

# Build packages
$packages = Start-PSPackage
$packages = Start-PSPackage @packageParams

$name = Get-PackageName

Expand Down Expand Up @@ -503,6 +516,12 @@ function Invoke-AppveyorFinish
$pushedAllArtifacts = $false
Write-Warning "Artifact $_ does not exist."
}

if($env:NUGET_KEY -and $env:NUGET_URL -and [system.io.path]::GetExtension($_) -ieq '.nupkg')
{
log "pushing $_ to $env:NUGET_URL"
Start-NativeExecution -sb {dotnet nuget push $_ --api-key $env:NUGET_KEY --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode
}
}
if(!$pushedAllArtifacts)
{
Expand Down
2 changes: 2 additions & 0 deletions tools/packaging/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
staging/
nugetStaging/
Loading