Skip to content

Commit ee3e549

Browse files
authored
Merge pull request #11 from maraf/ToolsPackage
NuGet package for downloading portable GitExtensions and integrating it with plugin development
2 parents 13c1987 + a6aee3d commit ee3e549

File tree

8 files changed

+306
-4
lines changed

8 files changed

+306
-4
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 4

appveyor.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ skip_tags: true
1212
max_jobs: 1
1313

1414
#---------------------------------#
15-
# environment configuration #
15+
# environment configuration #
1616
#---------------------------------#
1717

1818
# Build worker image (VM template)
@@ -21,8 +21,13 @@ image:
2121
- Visual Studio 2019
2222

2323
#---------------------------------#
24-
# build configuration #
24+
# build configuration #
2525
#---------------------------------#
26+
build_script:
27+
- ps: .\tools\Build-Nuget.ps1
2628

27-
# There is nothing to be build yet
28-
build: off
29+
#---------------------------------#
30+
# artifacts #
31+
#---------------------------------#
32+
artifacts:
33+
- path: .\*.nupkg
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
2+
<metadata>
3+
<id>GitExtensions.Extensibility</id>
4+
<version>$version$</version>
5+
<authors>Git Extensions</authors>
6+
<description>Git Extensions Extensibility package.</description>
7+
</metadata>
8+
<files>
9+
<file src="lib/net461/_._" target="lib/net461/_._" />
10+
<file src="build/net461/GitExtensions.Extensibility.props" target="build/net461/GitExtensions.Extensibility.props" />
11+
<file src="build/net461/GitExtensions.Extensibility.targets" target="build/net461/GitExtensions.Extensibility.targets" />
12+
13+
<file src="tools/Download-GitExtensions.ps1" target="tools/Download-GitExtensions.ps1" />
14+
</files>
15+
</package>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<PropertyGroup>
4+
<GitExtensionsDownloadPath Condition="$(GitExtensionsDownloadPath) == ''">..\..\references</GitExtensionsDownloadPath>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<!-- It's required to pass absolute paths to the PS1 script, otherwise it's based wrong. -->
4+
<_GitExtensionsDownloadPath>$([System.IO.Path]::Combine('$(ProjectDir)', '$(GitExtensionsDownloadPath)'))</_GitExtensionsDownloadPath>
5+
<_GitExtensionsDownloadScriptPath>$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', '..\..\tools\Download-GitExtensions.ps1'))</_GitExtensionsDownloadScriptPath>
6+
<!-- It's required to pass absolute paths as launch profile don't like relative ones. -->
7+
<GitExtensionsPath Condition="$(GitExtensionsPath) == ''">$([System.IO.Path]::Combine('$(ProjectDir)', '$(GitExtensionsDownloadPath)\GitExtensions'))</GitExtensionsPath>
8+
<GitExtensionsPluginsPath>$(GitExtensionsPath)\Plugins</GitExtensionsPluginsPath>
9+
<GitExtensionsExecutablePath>$([System.IO.Path]::Combine('$(GitExtensionsPath)', 'GitExtensions.exe'))</GitExtensionsExecutablePath>
10+
<GitExtensionsReferenceSource Condition="$(GitExtensionsReferenceSource) == ''">GitHub</GitExtensionsReferenceSource>
11+
<GitExtensionsReferenceVersion Condition="$(GitExtensionsReferenceVersion) == ''">latest</GitExtensionsReferenceVersion>
12+
</PropertyGroup>
13+
14+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
15+
<MakeDir Directories="$(GitExtensionsPluginsPath)" />
16+
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(GitExtensionsPluginsPath)" />
17+
</Target>
18+
19+
<Target Name="PreBuild" BeforeTargets="$(BuildDependsOn)">
20+
<MakeDir Directories="$(_GitExtensionsDownloadPath)" />
21+
<Error Condition="!Exists($(GitExtensionsExecutablePath)) and !Exists($(_GitExtensionsDownloadScriptPath))" Text="Path to Git Extensions portable download script is wrong. Current value '$(_GitExtensionsDownloadScriptPath)'." />
22+
<Exec Condition="!Exists($(GitExtensionsExecutablePath))" Command="powershell.exe -ExecutionPolicy Unrestricted $(_GitExtensionsDownloadScriptPath) -ExtractRootPath $(_GitExtensionsDownloadPath) -Version $(GitExtensionsReferenceVersion) -Source $(GitExtensionsReferenceSource)" />
23+
</Target>
24+
</Project>

src/GitExtensions.Extensibility/lib/net461/_._

Whitespace-only changes.
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
param(
2+
[Parameter(Mandatory=$true)]
3+
[string] $ExtractRootPath,
4+
[Parameter(Mandatory=$true)]
5+
[string] $Version,
6+
[ValidateSet('GitHub','AppVeyor', ignorecase=$False)]
7+
[string] $Source = "GitHub"
8+
)
9+
10+
$LatestVersionName = "latest";
11+
12+
function Test-LocalCopy
13+
{
14+
Param(
15+
[Parameter(Mandatory=$true, Position=0)]
16+
[string] $ExtractPath,
17+
[Parameter(Mandatory=$true, Position=1)]
18+
[string] $FileName
19+
)
20+
21+
$FilePath = [System.IO.Path]::Combine($ExtractPath, $FileName);
22+
if (Test-Path $FilePath)
23+
{
24+
Write-Host "Download '$FileName' already exists.";
25+
return $true;
26+
}
27+
28+
return $false;
29+
}
30+
31+
function Find-ArchiveUrl
32+
{
33+
param (
34+
[Parameter(Mandatory=$true, Position=0)]
35+
[string] $Version,
36+
[Parameter(Mandatory=$true, Position=1)]
37+
[ValidateSet('GitHub','AppVeyor', ignorecase=$False)]
38+
[string] $Source
39+
)
40+
41+
Write-Host "Searching for Git Extensions release '$Version' on '$Source'.";
42+
if ($Source -eq "GitHub")
43+
{
44+
return Find-ArchiveUrlFromGitHub -Version $Version;
45+
}
46+
47+
if ($Source -eq "AppVeyor")
48+
{
49+
return Find-ArchiveUrlFromAppVeyor -Version $Version;
50+
}
51+
52+
throw "Unable to find download URL for 'Git Extensions $Version'";
53+
}
54+
55+
function Find-ArchiveUrlFromGitHub
56+
{
57+
param (
58+
[Parameter(Mandatory=$true, Position=0)]
59+
[string] $Version
60+
)
61+
62+
$BaseUrl = 'https://api.github.com/repos/gitextensions/gitextensions/releases';
63+
$SelectedRelease = $null;
64+
if ($Version -eq $LatestVersionName)
65+
{
66+
$SelectedRelease = Invoke-RestMethod -Uri "$BaseUrl/latest";
67+
$Version = $SelectedRelease.tag_name;
68+
Write-Host "Selected release '$($SelectedRelease.name)'.";
69+
}
70+
else
71+
{
72+
$Releases = Invoke-RestMethod -Uri $BaseUrl;
73+
foreach ($Release in $Releases)
74+
{
75+
if ($Release.tag_name -eq $Version)
76+
{
77+
Write-Host "Selected release '$($Release.name)'.";
78+
$SelectedRelease = $Release;
79+
break;
80+
}
81+
}
82+
}
83+
84+
if (!($null -eq $SelectedRelease))
85+
{
86+
foreach ($Asset in $SelectedRelease.assets)
87+
{
88+
if ($Asset.content_type -eq "application/zip" -and $Asset.name.Contains('Portable'))
89+
{
90+
Write-Host "Selected asset '$($Asset.name)'.";
91+
return $Version,$Asset.browser_download_url;
92+
}
93+
}
94+
}
95+
96+
throw "Unable to find download URL for 'Git Extensions $Version' on GitHub";
97+
}
98+
99+
function Find-ArchiveUrlFromAppVeyor
100+
{
101+
param (
102+
[Parameter(Mandatory=$true, Position=0)]
103+
[string] $Version
104+
)
105+
106+
$UrlVersion = $Version;
107+
if ($UrlVersion.StartsWith("v"))
108+
{
109+
$UrlVersion = $UrlVersion.Substring(1);
110+
}
111+
112+
$UrlBase = "https://ci.appveyor.com/api";
113+
114+
try
115+
{
116+
if ($Version -eq $LatestVersionName)
117+
{
118+
$Url = "$UrlBase/projects/gitextensions/gitextensions/branch/master";
119+
}
120+
else
121+
{
122+
$Url = "$UrlBase/projects/gitextensions/gitextensions/build/$UrlVersion";
123+
}
124+
125+
$BuildInfo = Invoke-RestMethod -Uri $Url;
126+
$Version = "v$($BuildInfo.build.version)";
127+
$Job = $BuildInfo.build.jobs[0];
128+
if ($Job.Status -eq "success")
129+
{
130+
$JobId = $Job.jobId;
131+
Write-Host "Selected build job '$JobId'.";
132+
133+
$AssetsUrl = "$UrlBase/buildjobs/$JobId/artifacts";
134+
$Assets = Invoke-RestMethod -Method Get -Uri $AssetsUrl;
135+
foreach ($Asset in $Assets)
136+
{
137+
if ($Asset.type -eq "zip" -and $Asset.FileName.Contains('Portable'))
138+
{
139+
Write-Host "Selected asset '$($Asset.FileName)'.";
140+
return $Version,($AssetsUrl + "/" + $Asset.FileName);
141+
}
142+
}
143+
}
144+
}
145+
catch
146+
{
147+
if (!($_.Exception.Response.StatusCode -eq 404))
148+
{
149+
throw;
150+
}
151+
}
152+
153+
throw "Unable to find download URL for 'Git Extensions $Version' on AppVeyor";
154+
}
155+
156+
function Get-Application
157+
{
158+
param (
159+
[Parameter(Mandatory=$true, Position=0)]
160+
[string] $ArchiveUrl,
161+
[Parameter(Mandatory=$true, Position=1)]
162+
[string] $ExtractPath,
163+
[Parameter(Mandatory=$true, Position=2)]
164+
[string] $FileName
165+
)
166+
167+
if (!(Test-Path $ExtractPath))
168+
{
169+
New-Item -ItemType directory -Path $ExtractPath | Out-Null;
170+
}
171+
172+
$FilePath = [System.IO.Path]::Combine($ExtractPath, $FileName);
173+
174+
Write-Host "Downloading '$ArchiveUrl'...";
175+
176+
Invoke-WebRequest -Uri $ArchiveUrl -OutFile $FilePath;
177+
Expand-Archive $FilePath -DestinationPath $ExtractPath -Force;
178+
179+
Write-Host "Application extracted to '$ExtractPath'.";
180+
}
181+
182+
function Get-ZipFileName {
183+
param (
184+
[Parameter(Mandatory=$true, Position=0)]
185+
[string] $Version
186+
)
187+
188+
return "GitExtensions-$Version.zip";
189+
}
190+
191+
192+
Push-Location $PSScriptRoot;
193+
try
194+
{
195+
$ExtractRootPath = Resolve-Path $ExtractRootPath;
196+
Write-Host "Extraction root path is '$ExtractRootPath'.";
197+
198+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
199+
200+
if (!($Version -eq $LatestVersionName))
201+
{
202+
$FileName = Get-ZipFileName -Version $Version;
203+
if (Test-LocalCopy -ExtractPath $ExtractRootPath -FileName $FileName)
204+
{
205+
exit 0;
206+
}
207+
}
208+
209+
$SelectedVersion,$DownloadUrl = Find-ArchiveUrl -Version $Version -Source $Source;
210+
if ($Version -eq $LatestVersionName)
211+
{
212+
$FileName = Get-ZipFileName -Version $SelectedVersion;
213+
if (Test-LocalCopy -ExtractPath $ExtractRootPath -FileName $FileName)
214+
{
215+
exit 0;
216+
}
217+
}
218+
219+
Get-Application -ArchiveUrl $DownloadUrl -ExtractPath $ExtractRootPath -FileName $FileName;
220+
}
221+
catch
222+
{
223+
Write-Host $_.Exception -ForegroundColor Red;
224+
exit -1;
225+
}
226+
finally
227+
{
228+
Pop-Location;
229+
}

tools/Build-Nuget.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
param([string] $Version = $env:APPVEYOR_BUILD_VERSION)
2+
3+
Push-Location $PSScriptRoot;
4+
try
5+
{
6+
nuget pack ..\src\GitExtensions.Extensibility\GitExtensions.Extensibility.nuspec -OutputDirectory .. -Version $Version
7+
}
8+
catch
9+
{
10+
Write-Host $_.Exception -ForegroundColor Red;
11+
exit -1;
12+
}
13+
finally
14+
{
15+
Pop-Location;
16+
}

0 commit comments

Comments
 (0)