Skip to content

Commit e186875

Browse files
committed
#33 - Update GE download script to take GE version from csproj.
1 parent 6ca9090 commit e186875

File tree

2 files changed

+60
-21
lines changed

2 files changed

+60
-21
lines changed

src/GitExtensions.BundleBackuper/GitExtensions.BundleBackuper.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This plugin lets you create a .bundle containing all unpublished commits.</Descr
1313

1414
<PropertyGroup>
1515
<GitExtensionsDebugPluginsPath>..\..\references\GitExtensions\Plugins\</GitExtensionsDebugPluginsPath>
16+
<GitExtensionsReferenceVersion>v3.1</GitExtensionsReferenceVersion>
1617
</PropertyGroup>
1718

1819
<ItemGroup>
@@ -56,7 +57,7 @@ This plugin lets you create a .bundle containing all unpublished commits.</Descr
5657
</Target>
5758

5859
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
59-
<Exec Command="powershell.exe -ExecutionPolicy Unrestricted ..\..\tools\Download-GitExtensions.ps1" />
60+
<Exec Command="powershell.exe -ExecutionPolicy Unrestricted ..\..\tools\Download-GitExtensions.ps1 -Version $(GitExtensionsReferenceVersion)" />
6061
</Target>
6162

6263
<Target Name="SetPackageProperties" BeforeTargets="GenerateNuspec">

tools/Download-GitExtensions.ps1

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,75 @@
1+
param([string] $Version)
2+
3+
If (-not($Version))
4+
{
5+
Throw "Parameter -Version is required";
6+
}
7+
18
Set-Location $PSScriptRoot
29

310
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
411
$ExtractRootPath = '../references'
5-
$AssetToDownloadName = 'GitExtensions-Portable-3.0.2.5232.zip';
6-
$AssetToDownloadUrl = 'https://github.com/gitextensions/gitextensions/releases/download/v3.0.2/GitExtensions-Portable-3.0.2.5232.zip';
12+
$AssetToDownloadName = 'GitExtensions-' + $Version + '.zip';
13+
$AssetToDownloadUrl = $null;
714

8-
if (!($null -eq $AssetToDownloadUrl))
15+
$DownloadName = [System.IO.Path]::GetFileName($AssetToDownloadName);
16+
$DownloadFilePath = [System.IO.Path]::Combine($ExtractRootPath, $DownloadName);
17+
if (Test-Path $DownloadFilePath)
918
{
10-
$DownloadName = [System.IO.Path]::GetFileName($AssetToDownloadName);
11-
$DownloadFilePath = [System.IO.Path]::Combine($ExtractRootPath, $DownloadName);
12-
$ExtractPath = $ExtractRootPath;
19+
Write-Host ('Download "' + $DownloadName + '" already exists.');
20+
Pop-Location
21+
exit;
22+
}
1323

14-
if (!(Test-Path $DownloadFilePath))
24+
# Find release and asset.
25+
$Releases = Invoke-RestMethod -Uri 'https://api.github.com/repos/gitextensions/gitextensions/releases'
26+
foreach ($Release in $Releases)
27+
{
28+
if ($Release.tag_name -eq $Version)
1529
{
16-
if (!(Test-Path $ExtractRootPath))
17-
{
18-
New-Item -ItemType directory -Path $ExtractRootPath | Out-Null;
19-
}
30+
Write-Host ('Selected release "' + $Release.name + '".');
31+
foreach ($Asset in $Release.assets)
32+
{
33+
if ($Asset.content_type -eq "application/zip" -and $Asset.name.Contains('Portable'))
34+
{
35+
Write-Host ('Selected asset "' + $Asset.name + '".');
36+
$AssetToDownloadUrl = $Asset.browser_download_url;
37+
break;
38+
}
39+
}
2040

21-
if (!(Test-Path $ExtractPath))
22-
{
23-
New-Item -ItemType directory -Path $ExtractPath | Out-Null;
24-
}
41+
if (!($null -eq $AssetToDownloadUrl))
42+
{
43+
break;
44+
}
45+
}
46+
}
2547

26-
Write-Host ('Downloading "' + $DownloadName + '".');
48+
# Download and extract zip.
49+
if (!($null -eq $AssetToDownloadUrl))
50+
{
51+
$ExtractPath = $ExtractRootPath;
2752

28-
Invoke-WebRequest -Uri $AssetToDownloadUrl -OutFile $DownloadFilePath;
29-
Expand-Archive $DownloadFilePath -DestinationPath $ExtractPath -Force
53+
if (!(Test-Path $ExtractRootPath))
54+
{
55+
New-Item -ItemType directory -Path $ExtractRootPath | Out-Null;
3056
}
31-
else
57+
58+
if (!(Test-Path $ExtractPath))
3259
{
33-
Write-Host ('Download "' + $DownloadName + '" already exists.');
60+
New-Item -ItemType directory -Path $ExtractPath | Out-Null;
3461
}
62+
63+
Write-Host ('Downloading "' + $DownloadName + '" from URL "' + $AssetToDownloadUrl + '".');
64+
65+
Invoke-WebRequest -Uri $AssetToDownloadUrl -OutFile $DownloadFilePath;
66+
Expand-Archive $DownloadFilePath -DestinationPath $ExtractPath -Force
67+
68+
Write-Host ('Extraction at "' + $ExtractPath + '" completed.');
69+
}
70+
else
71+
{
72+
Write-Host ('Download for version "' + $Version + '" not found.');
3573
}
3674

3775
Pop-Location

0 commit comments

Comments
 (0)