-
Notifications
You must be signed in to change notification settings - Fork 254
/
Get-ChocoUpdatedDebugVersion.ps1
149 lines (120 loc) · 5.38 KB
/
Get-ChocoUpdatedDebugVersion.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
[CmdletBinding(DefaultParameterSetName = "tag")]
param(
# The location where Chocolatey CLI sources are located,
# or will be located if the directory does not already exist.
# If not specified and the environment variable `CHOCO_SOURCE_LOCATION`
# is not definied, the location will default to `$env:TEMP\
[Alias("ChocoLocation")]
[string] $ChocoSourceLocation = $env:CHOCO_SOURCE_LOCATION,
# Checkout a specific tag of your own choosing.
# This value can also be a specific commit or a branch, but
# will be notified as being a tag.
# NOTE: Only tags already pulled down will be considered.
[Parameter(ParameterSetName = "tag")]
[string] $CheckoutTag = $null,
# Checkout the latest tag available in the Chocolatey Source Location.
# NOTE: Only tags already pulled down will be considered.
[Parameter(ParameterSetName = "latest")]
[switch] $CheckoutLatestTag,
# Try check out a tage with the same name as what is used as a reference
# in the packages.config file. If the reference specified is not a stable
# version, the latest tag will be checked out instead.
# NOTE: Only tags already pulled down will be considered.
[Parameter(ParameterSetName = 'ref-tag')]
[switch] $CheckoutRefTag,
# Remove and clone the specified Chocolatey Source Location again.
# This is a very destructive operation, and should only be used if
# you are not interested in any local information.
[switch] $ForceChocoClone
)
function CheckoutTag {
param(
[Parameter(Mandatory)]
[string] $SourceLocation,
[string] $TagName
)
Push-Location "$SourceLocation"
if (!$TagName) {
$TagName = . git tag --sort v:refname | Where-Object { $_ -match "^[\d\.]+$" } | Select-Object -last 1
}
if ($TagName) {
git checkout $TagName -q 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Checked out Chocolatey CLI tag '$TagName'"
}
else {
$currentBranch = . git branch --show-current
if ($currentBranch) {
Write-Warning "Unable to check out tag $TagName. Leaving source in branch $currentBranch"
}
else {
Write-Warning "Unable to check out tag $TagName. Leaving source in commit $(git rev-parse HEAD)"
}
}
}
Pop-Location
}
Write-Host "We are at $PSScriptRoot"
[xml]$packagesConfigFile = Get-Content -Path "$PSScriptRoot/Source/ChocolateyGui/packages.config"
$chocolateyLibPackageVersion = $($packagesConfigFile.packages.package | Where-Object { $_.id -eq "chocolatey.lib" }).version
if ($CheckoutRefTag) {
if ($chocolateyLibPackageVersion -match '^[\d\.]+$') {
$CheckoutTag = $chocolateyLibPackageVersion
}
else {
$CheckoutLatestTag = $true
}
}
if (!$ChocoSourceLocation) {
# To allow a default path being used for cloning the repository
$ChocoSourceLocation = "$env:TEMP\chocoSource"
}
Write-Host "Looking for choco in '$ChocoSourceLocation'"
if ($ForceChocoClone -and (Test-Path $ChocoSourceLocation)) {
Write-Host "Removing existing Chocolatey CLI Source in '$ChocoSourceLocation'"
# We use error action stop here, as there may be times the `.git` directory is locked.
# Having information about this is helpful to rectify the issue.
Remove-Item $ChocoSourceLocation -Recurse -Force -EA Stop
}
if (!(Test-Path $ChocoSourceLocation)) {
Write-Host "Cloning Chocolatey CLI Repository to '$ChocoSourceLocation'"
git clone "https://github.com/chocolatey/choco.git" "$ChocoSourceLocation"
if ($CheckoutLatestTag) {
CheckoutTag $ChocoSourceLocation
}
elseif ($CheckoutTag) {
CheckoutTag $ChocoSourceLocation -TagName $CheckoutTag
}
}
elseif ($CheckoutLatestTag) {
CheckoutTag $ChocoSourceLocation
}
elseif ($CheckoutTag) {
CheckoutTag $ChocoSourceLocation -TagName $CheckoutTag
}
if (-not (Test-Path -Path $ChocoSourceLocation)) {
# We leave this here on purpose in case the cloning of the repository has failed.
throw "Location '$ChocoSourceLocation' not found; please rerun with the -ChocoSourceLocation parameter or set the CHOCO_SOURCE_LOCATION environment variable."
}
Write-Host "Restore packages on project first..."
& ./build.debug.bat --target='Restore'
Write-Host "Building choco at $ChocoSourceLocation with Debug..."
Push-Location $ChocoSourceLocation
if (Test-Path "recipe.cake") {
& ./build.debug.bat --target='Run-ILMerge' --shouldRunTests=false --shouldRunAnalyze=false
}
else {
& ./build.debug.bat
}
Pop-Location
Write-Host "Copying chocolatey artifacts to current Chocolatey Package Version folder..."
$chocolateyLibPackageFolder = "$PSScriptRoot/Source/packages/chocolatey.lib.$chocolateyLibPackageVersion/lib/net48"
if (-not (Test-Path -Path $chocolateyLibPackageFolder)) {
New-Item -ItemType Directory -Path $chocolateyLibPackageFolder > $null
}
$codeDropLibs = "$ChocoSourceLocation/code_drop/temp/_PublishedLibs/chocolatey_merged"
if (!(Test-Path $codeDropLibs)) {
$codeDropLibs = "$ChocoSourceLocation/code_drop/chocolatey/lib"
}
Write-Host "Copying chocolatey lib items from '$codeDropLibs/*' to '$chocolateyLibPackageFolder'."
Copy-Item -Path "$codeDropLibs/*" -Destination "$chocolateyLibPackageFolder/" -Force