Skip to content

Commit 03a33ab

Browse files
committed
Use appveyor build number for publishable builds, otherwise use a timestamp
1 parent 456d8cb commit 03a33ab

9 files changed

Lines changed: 44 additions & 30 deletions

File tree

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '{build}'
21
install:
32
- ps: >-
43
$full_build = Test-Path env:GHFVS_KEY
@@ -20,7 +19,7 @@ install:
2019
2120
nuget restore GitHubVS.sln
2221
build_script:
23-
- ps: scripts\build.ps1 -AppVeyor
22+
- ps: scripts\build.ps1 -AppVeyor -Version -BuildNumber:{build}
2423
test_script:
2524
- ps: scripts\test.ps1 -AppVeyor
2625
on_success:

scripts/Bump-Version.ps1

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Param(
2929
[switch]
3030
$BumpBuild = $false
3131
,
32+
[int]
33+
$BuildNumber = -1
34+
,
3235
[switch]
3336
$Commit = $false
3437
,
@@ -51,6 +54,12 @@ if ($Trace) { Set-PSDebug -Trace 1 }
5154
. $scriptsDirectory\Modules\SolutionInfo.ps1 | out-null
5255
. $scriptsDirectory\Modules\Versioning.ps1 | out-null
5356

57+
if ($NewVersion -eq $null) {
58+
if (!$BumpMajor -and !$BumpMinor -and !$BumpPatch -and !$BumpBuild){
59+
Die -1 "You need to indicate which part of the version to update via -BumpMajor/-BumpMinor/-BumpPatch/-BumpBuild flags or a custom version via -NewVersion"
60+
}
61+
}
62+
5463
if ($Push -and !$Commit) {
5564
Die 1 "Cannot push a version bump without -Commit"
5665
}
@@ -64,23 +73,19 @@ if (!$?) {
6473
}
6574

6675
if ($NewVersion -eq $null) {
67-
if (!$BumpMajor -and !$BumpMinor -and !$BumpPatch -and !$BumpBuild){
68-
Die -1 "You need to indicate which part of the version to update via -BumpMajor/-BumpMinor/-BumpPatch flags or a custom version via -NewVersion"
69-
}
70-
71-
$currentVersion = Read-CurrentVersion
72-
$NewVersion = Generate-Version $currentVersion $BumpMajor $BumpMinor $BumpPatch $BumpBuild
73-
74-
} elseif (!(Validate-Version($NewVersion))) {
75-
Die -1 "Invalid version specific - $NewVersion"
76+
$currentVersion = Read-CurrentVersionVsix
77+
$NewVersion = Generate-Version $currentVersion $BumpMajor $BumpMinor $BumpPatch $BumpBuild $BuildNumber
7678
}
7779

80+
Write-Output "Setting version to $NewVersion"
7881
Write-Version $NewVersion
7982

8083
if ($Commit) {
84+
Write-Output "Committing version change"
8185
Commit-Version $NewVersion
8286

8387
if ($Push) {
88+
Write-Output "Pushing version change"
8489
$branch = & $git rev-parse --abbrev-ref HEAD
8590
Push-Changes $branch
8691
}

scripts/build.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Param(
3333
[switch]
3434
$BumpVersion = $false
3535
,
36+
[int]
37+
$BuildNumber = -1
38+
,
3639
[switch]
3740
$Trace = $false
3841
)
@@ -68,7 +71,7 @@ if ($publishable) { #forcing a deploy flag for CI
6871

6972
if ($BumpVersion) {
7073
Write-Output "Bumping the version"
71-
Bump-Version -BumpBuild
74+
Bump-Version -BumpBuild -BuildNumber:$BuildNumber
7275
}
7376

7477
if ($Package) {

scripts/modules/SolutionInfo.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ New-Module -ScriptBlock {
3737
$regex = "(string ShortVersion = )`"\d+\.\d+\.\d+\.\d+`";"
3838
if ($newString -match $regex) {
3939
$numberOfReplacements++
40-
$newString = $newString -replace $regex, "`$1`"$($version.Major).$($version.Minor).$($version.Build).0`";"
40+
$newString = $newString -replace $regex, "`$1`"$version`";"
4141
}
4242
$newString
4343
}

scripts/modules/Versioning.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ New-Module -ScriptBlock {
88

99
function Generate-Version([System.Version]$currentVersion,
1010
[bool]$BumpMajor, [bool] $BumpMinor,
11-
[bool]$BumpPatch, [bool] $BumpBuild) {
11+
[bool]$BumpPatch, [bool] $BumpBuild,
12+
[int]$BuildNumber = -1) {
1213

1314
if (!(Validate-Version $currentVersion)) {
1415
Die 1 "Invalid current version $currentVersion"
@@ -21,8 +22,12 @@ New-Module -ScriptBlock {
2122
} elseif ($BumpPatch) {
2223
New-Object -TypeName System.Version -ArgumentList $currentVersion.Major, $currentVersion.Minor, ($currentVersion.Build + 1), 0
2324
} elseif ($BumpBuild) {
24-
$timestamp = [System.DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
25-
[System.Version] "$($currentVersion.Major).$($currentVersion.Minor).$($currentVersion.Build).$timestamp"
25+
if ($BuildNumber -ge 0) {
26+
[System.Version] "$($currentVersion.Major).$($currentVersion.Minor).$($currentVersion.Build).$BuildNumber"
27+
} else {
28+
$timestamp = [System.DateTimeOffset]::UtcNow.ToUnixTimeSeconds()
29+
[System.Version] "$($currentVersion.Major).$($currentVersion.Minor).$($currentVersion.Build).$timestamp"
30+
}
2631
}
2732
else {
2833
$currentVersion
@@ -34,7 +39,7 @@ New-Module -ScriptBlock {
3439
Write-VersionInstaller $version
3540
Write-VersionSolutionInfo $version
3641
Push-Location $rootDirectory
37-
New-Item -Type Directory build | out-null
42+
New-Item -Type Directory -ErrorAction SilentlyContinue build | out-null
3843
Set-Content build\version $version
3944
Pop-Location
4045
}

scripts/modules/Vsix.ps1

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ New-Module -ScriptBlock {
1717
[xml] $xmlText
1818
}
1919

20-
function Read-CurrentVersion {
21-
[System.Version] (Get-VsixManifestXml).PackageManifest.Metadata.Identity.Version
22-
}
23-
2420
function Read-CurrentVersionVsix {
2521
[System.Version] (Get-VsixManifestXml).PackageManifest.Metadata.Identity.Version
2622
}
@@ -35,5 +31,5 @@ New-Module -ScriptBlock {
3531
$document.Save((Get-VsixManifestPath))
3632
}
3733

38-
Export-ModuleMember -Function Read-CurrentVersion,Read-CurrentVersionVsix,Write-VersionVsixManifest
34+
Export-ModuleMember -Function Read-CurrentVersionVsix,Write-VersionVsixManifest
3935
}

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<DeployExtension>False</DeployExtension>
125125
<OutputPath>..\..\build\Release\</OutputPath>
126126
</PropertyGroup>
127-
<Import Project="$(SolutionDir)\src\common\signing.props" />
127+
<Import Project="..\common\signing.props" />
128128
<PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
129129
<!-- Only deploy extension when building inside Visual Studio -->
130130
<DeployExtension>false</DeployExtension>
@@ -748,7 +748,7 @@
748748
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != '' And '$(NCrunch)' != '1'" />
749749
<Import Project="packaging.targets" />
750750
<!-- For regenerating templates on build -->
751-
<Import Project="$(SolutionDir)\src\common\t4.targets" />
751+
<Import Project="..\common\t4.targets" />
752752
<Import Project="versioning.targets" />
753753
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
754754
<PropertyGroup>

src/GitHub.VisualStudio/packaging.targets

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
<Message Importance="High" Text='Suppressed "@(SuppressPackaging)" from being included in VSIX.' />
1616
</Target>
1717

18-
<Target Name="UpdateManifestVersion" AfterTargets="DetokenizeVsixManifestFile" Outputs="$(IntermediateVsixManifest)">
19-
<ReadLinesFromFile File="$(SolutionDir)\build\version">
20-
<Output TaskParameter="Lines" PropertyName="Version" />
21-
</ReadLinesFromFile>
22-
<Message Text="Stamping package with version '$(Version)'" />
23-
<XmlPoke XmlInputPath="$(IntermediateVsixManifest)" Query="/x:PackageManifest/x:Metadata/x:Identity/@Version" Value="$(Version)" Namespaces="&lt;Namespace Prefix='x' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011' /&gt;" />
18+
<Target Name="UpdateManifestVersion"
19+
AfterTargets="DetokenizeVsixManifestFile"
20+
DependsOnTargets="GetBuildVersion"
21+
Outputs="$(IntermediateVsixManifest)">
22+
<Message Text="Stamping package with version '$(BuildVersion)'" />
23+
<XmlPoke XmlInputPath="$(IntermediateVsixManifest)" Query="/x:PackageManifest/x:Metadata/x:Identity/@Version" Value="$(BuildVersion)" Namespaces="&lt;Namespace Prefix='x' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011' /&gt;" />
2424
</Target>
2525

2626
<!-- set AllUsers="false" and Experimental="true" when $(IsExperimental)' == 'true' -->

src/GitHub.VisualStudio/versioning.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@
3838

3939
<WriteLinesToFile File="$(SolutionDir)\build\version" Lines="$(GeneratedVersion)" Overwrite="True" />
4040
</Target>
41+
42+
<Target Name="GetBuildVersion" Returns="$(BuildVersion)" DependsOnTargets="GenerateVersionFile">
43+
<ReadLinesFromFile File="$(SolutionDir)\build\version">
44+
<Output TaskParameter="Lines" PropertyName="BuildVersion" />
45+
</ReadLinesFromFile>
46+
</Target>
4147
</Project>

0 commit comments

Comments
 (0)