-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAndroidSetVersion.ps1
72 lines (58 loc) · 2.21 KB
/
AndroidSetVersion.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# adapted from https://github.com/jamesmontemagno/vsts-mobile-tasks/blob/18c29f6a58bb4194ecddc9bc68e743b041127dd0/tasks/AndroidBumpVersion/task.ps1
# following PoshCode style guide: https://github.com/PoshCode/PowerShellPracticeAndStyle
param (
[Parameter(Mandatory)]
[string]
$ManifestPath,
# manual, long-term adjustment to build id or whatever
[Parameter(Mandatory)]
[int]
$VersionCodeBase,
# the value that increases each time
[Parameter(Mandatory)]
[int]
$VersionCodeOffset,
[Parameter(Mandatory)]
[string]
$VersionName,
[bool]
$PrintFile = $false
)
[int] $versionCode = $VersionCodeBase + $VersionCodeOffset
Write-Output "ENVIRONMENT VARIABLES ----------"
Write-Output "Build_BuildId: $env:Build_BuildId"
Write-Output "Build_BuildNumber: $env:Build_BuildNumber"
Write-Output "SCRIPT VARIABLES ---------------"
Write-Output "ManifestPath: $ManifestPath"
Write-Output "VersionCodeBase: $VersionCodeBase"
Write-Output "VersionCodeOffset: $VersionCodeOffset"
Write-Output "calced versionCode: $versionCode"
Write-Output "VersionName: $VersionName"
[xml] $manifest = Get-Content -Path $ManifestPath
function Select-ManifestAttribute {
param
( [Parameter(Mandatory)] [xml] $manifestDoc
, [Parameter(Mandatory)] [string] $attributeName
)
$namespaces = @{android="http://schemas.android.com/apk/res/android"}
$commonXpath = "/manifest/@android:"
return Select-Xml -xml $manifestDoc -Xpath "$commonXpath$attributeName" -namespace $namespaces
}
$manifestVersionCode = Select-ManifestAttribute $manifest "versionCode"
$manifestVersionName = Select-ManifestAttribute $manifest "versionName"
Write-Output "OLD MANIFEST VALUES ------------"
Write-Output "Old version code: $($manifestVersionCode.Node.Value)"
Write-Output "Old version name: $($manifestVersionName.Node.Value)"
if($PrintFile)
{
Write-Output "ORIGINAL MANIFEST --------------"
Get-Content $ManifestPath | Write-Output
}
$manifestVersionCode.Node.Value = $versionCode
$manifestVersionName.Node.Value = $VersionName
$manifest.Save($ManifestPath)
if($PrintFile)
{
Write-Output "FINAL MANIFEST -----------------"
Get-Content $ManifestPath | Write-Output
}