azure-sdk-for-cpp/eng/scripts/Update-VcpkgPort.ps1
Daniel Jurek 5a99f38df1
Add nightly vcpkg publishing (#2025)
* Tool changes to support nightly test package release

* Initial wiring up and refactor vcpkg-publish.yml

* Use vcpkg-clone.yml

* Disable publishing for verification of nightly builds

* Complete the comment

* Dependency is enforced at the stage level, not the deployment/job level

* Remove environment, no approval needed

* Add ability to enable test release parameters

* deploy -> job

* deployment -> job

* Remove strategy

* Download pipeline artifacts

* task -> download

* Set appropriate working directory

* git status

* Set working directory

* Add pipeline for nightly vcpkg PR update

* Correct vcpkg-clone.yml path

* Add identity parameters to git merge commands

* Remove GitIdentityParameters, the merge command does not suppor tthem. Add instead in the pipeline

* Split lines

* Write-Host

* Template for nightly branch name, update comments, Check for scheduling or "PublishNightlyVcpkg"

* include archetype-cpp-release.yml changes

* Re-enable publishing stage

* Close the and

* Runtime condition for integration stage

* Move integration below package publishing stages

* try -- to disambiguate

* ^ -> ~

* Remove --

* Documentation and variable naming

* Move documentation comment

* Update eng/pipelines/templates/steps/generate-nightly-branch-name.yml

Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>

* Review feedback

* Add ability to skip all release steps

* Equal sign

* The right number of dashes

* Checkout before merge

* Checkout the default branch

* --no-ff

* git reset

* Skip publishing for artifacts which are not publishign to vcpkg

* Add git config --unset

* Apply suggestions from code review

Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>

* Review feedback

* Review feedback

* Remove extra reset

* TestRelease -> DailyRelease

Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>
2021-04-06 14:48:32 -07:00

168 lines
5.5 KiB
PowerShell

param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $ReleaseArtifactSourceDirectory,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $PortDestinationDirectory,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $VcpkgPortName,
[string] $GitCommitParameters,
[switch] $DailyRelease
)
."$PSScriptRoot/../common/scripts/common.ps1"
# Validate prerequisites
if (!(Test-Path bootstrap-vcpkg.bat)) {
LogError "Could not locate bootstrap-vcpkg.bat current directory must be a clone of the vcpkg repo (https://github.com/microsoft/vcpkg)"
exit 1
}
if ((Get-Command git | Measure-Object).Count -eq 0) {
LogError "Could not locate git. Install git https://git-scm.com/downloads"
exit 1
}
if (!(Test-Path $ReleaseArtifactSourceDirectory/package-info.json)) {
LogError "Could not locate package-info.json in -ReleaseArtifactSourceDirectory"
exit 1
}
if (!(Test-Path $ReleaseArtifactSourceDirectory/CHANGELOG.md)) {
LogError "Could not locate CHANGELOG.md in -ReleaseArtifactSourceDirectory"
}
if (!(Test-Path $ReleaseArtifactSourceDirectory/vcpkg/port)) {
LogError "Could not locate vcpkg/port directory in -ReleaseArtifactSourceDirectory"
}
# Clean out the folder so that template files removed are not inadvertently
# re-added
if (Test-Path $PortDestinationDirectory) {
Remove-Item -v -r $PortDestinationDirectory
}
New-Item -Type Directory $PortDestinationDirectory
Copy-Item `
-Verbose `
"$ReleaseArtifactSourceDirectory/vcpkg/port/*" `
$PortDestinationDirectory
# Show artifacts copied into ports folder for PR
Write-Host "Files in destination directory:"
Get-ChildItem -Recurse $PortDestinationDirectory | Out-String | Write-Host
Write-Host "git status"
git status
# Temporarily commit changes to generate git tree objects required by
# "vcpkg x-add-version <port-name>"
Write-Host "git add -A"
git add -A
Write-Host "git $GitCommitParameters commit -m 'Temporary commit to reset after x-add-version'"
"git $GitCommitParameters commit -m 'Temporary commit to reset after x-add-version'" | Invoke-Expression -Verbose | Write-Host
Write-Host "./bootstrap-vcpkg.bat"
./bootstrap-vcpkg.bat
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to run bootstrap-vcpkg.bat"
exit 1
}
$addVersionAdditionalParameters = ''
if ($DailyRelease) {
$addVersionAdditionalParameters = '--overwrite-version'
}
Write-Host "./vcpkg.exe x-add-version $VcpkgPortName $addVersionAdditionalParameters"
./vcpkg.exe x-add-version $VcpkgPortName $addVersionAdditionalParameters
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to run vcpkg x-add-version $VcpkgPortName"
exit 1
}
# Reset to undo previous commit and put changes in the working directory.
Write-Host "git reset HEAD^"
git reset HEAD^
# Only perform the final commit if this is not a test release
if (!$DailyRelease) {
# Grab content needed for commit message and place in a temporary file
$packageVersion = (Get-Content $ReleaseArtifactSourceDirectory/package-info.json -Raw | ConvertFrom-Json).version
$commitMessageFile = New-TemporaryFile
$chagelogEntry = Get-ChangeLogEntryAsString `
-ChangeLogLocation $ReleaseArtifactSourceDirectory/CHANGELOG.md `
-VersionString $PackageVersion
"[$VcpkgPortName] Update to $PackageVersion`n$chagelogEntry" `
| Set-Content $commitMessageFile
Write-Host "Commit Message:"
Write-host (Get-Content $commitMessageFile -Raw)
Write-Host "git add -A"
git add -A
# Final commit using commit message from the temporary file. Using the file
# enables the commit message to be formatted properly without having to write
# code to escape certain characters that might appear in the changelog file.
Write-Host "git $GitCommitParameters commit --file $commitMessageFile"
"git $GitCommitParameters commit --file $commitMessageFile" `
| Invoke-Expression -Verbose `
| Write-Host
# Set $(HasChanges) to $true so that create-pull-request.yml completes the
# push and PR submission steps
Write-Host "##vso[task.setvariable variable=HasChanges]$true"
}
<#
.SYNOPSIS
Uses release artifacts to update a vcpkg port
.DESCRIPTION
This script updates a given vcpkg port using C++ release artifacts. It requires
that the GitHub repo is tagged and a release is available at that tag for
generating the SHA of the vcpkg artifact.
This script also uses the contents of the changelog at the release version in
the commit message.
Vcpkg requires the use of `vcpkg.exe x-add-version` to prepare ports going
forward. This script handles adding this and making a single commit so that
subsequent functions in the Azure DevOps pipeline can push the commit or rebase
as needed to get the commit into the PR branch.
.PARAMETER ReleaseArtifactSourceDirectory
Location of the release artifact. Must have package-info.json, CHANGELOG.md, and
vcpkg/port/
.PARAMETER PortDestinationDirectory
Location of the vcpkg port folder where the port release artifacts are copied.
Generally "<vcpkg-repo>/ports/<port-name>"
.PARAMETER VcpkgPortName
Name of the vcpkg port (e.g. azure-template-cpp)
.PARAMETER GitCommitParameters
Additional parameters to supply to the `git commit` command. These are useful
in the context of Azure DevOps where the git client does not have a configured
user.name and user.email.
.PARAMETER DailyRelease
In the case of a test release set this to ensure that the x-add-version step
includes `--overwrite-version` to ensure daily packages are properly updated
in the vcpkg repo.
#>