Skip to content

Commit 5fad092

Browse files
committed
Refactor Windows Installer setup
Resolves cli#703 along with several other issues: * Build an x64 MSI for an x64 executable. This means the binary is installed to C:\Program Files, by default, rather than C:\Program Files (x86) without the ability to redirect it to 64-bit locations. * Environment change to PATH is not system-wide, which for a per-machine install it should be so all users who can access the executable have it in their PATH. * Environment change to PATH is not cleaned up when uninstalled. * RTF conversion of LICENSE was difficult to read. A simple conversion script is checked in to facilitate regenerating RTF from root LICENSE.
1 parent 8f3b674 commit 5fad092

File tree

6 files changed

+144
-42
lines changed

6 files changed

+144
-42
lines changed

.github/workflows/releases.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,17 @@ jobs:
123123
unzip -o *.zip && rm -v *.zip
124124
env:
125125
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
126-
- name: Install go-msi
127-
run: choco install -y "go-msi"
128126
- name: Prepare PATH
129-
shell: bash
130-
run: |
131-
echo "$WIX\\bin" >> $GITHUB_PATH
132-
echo "C:\\Program Files\\go-msi" >> $GITHUB_PATH
127+
uses: microsoft/setup-msbuild@v1.0.3
133128
- name: Build MSI
134129
id: buildmsi
135130
shell: bash
136131
env:
137132
ZIP_FILE: ${{ steps.download_exe.outputs.zip }}
138133
run: |
139-
mkdir -p build
140-
msi="$(basename "$ZIP_FILE" ".zip").msi"
141-
printf "::set-output name=msi::%s\n" "$msi"
142-
go-msi make --msi "$PWD/$msi" --out "$PWD/build" --version "${GITHUB_REF#refs/tags/}"
134+
name="$(basename "$ZIP_FILE" ".zip")"
135+
printf "::set-output name=msi::%s\n" "$name.msi"
136+
msbuild .\build\windows\gh.wixproj /p:SourceDir="$PWD" /p:OutputName="$name" /p:ProductVersion="${GITHUB_REF#refs/tags/}"
143137
- name: Obtain signing cert
144138
id: obtain_cert
145139
env:

build/windows/ConvertTo-Rtf.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[CmdletBinding()]
2+
param (
3+
[Parameter(Mandatory=$true, Position=0)]
4+
[string] $Path,
5+
6+
[Parameter(Mandatory=$true, Position=1)]
7+
[string] $OutFile,
8+
9+
[Parameter()]
10+
[ValidateNotNullOrEmpty()]
11+
[string] $FontFamily = 'Arial'
12+
)
13+
14+
$rtf = "{\rtf1\ansi\deff0{\fonttbl{\f0\fcharset0 $FontFamily;}}\pard\sa200\sl200\slmult1\fs20`n"
15+
foreach ($line in (Get-Content $Path)) {
16+
if (!$line) {
17+
$rtf += "\par`n"
18+
} else {
19+
$rtf += "$line`n"
20+
}
21+
}
22+
$rtf += '}'
23+
24+
$rtf | Set-Content $OutFile

build/windows/LICENSE.rtf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{\rtf1\ansi\deff0{\fonttbl{\f0\fcharset0 Arial;}}\pard\sa200\sl200\slmult1\fs20
2+
MIT License
3+
\par
4+
Copyright (c) 2019 GitHub Inc.
5+
\par
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
\par
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
\par
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
}

build/windows/gh.wixproj

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
5+
<Platform Condition="'$(Platform)' == ''">x64</Platform>
6+
<ProductVersion Condition="'$(ProductVersion)' == ''">0.1.0</ProductVersion>
7+
<OutputName Condition="'$(OutputName)' == ''">$(MSBuildProjectName)</OutputName>
8+
<OutputType>package</OutputType>
9+
<RepoPath>$(MSBuildProjectDirectory)\..\..</RepoPath>
10+
<OutputPath>$(RepoPath)\bin\$(Platform)\$(Configuration)\</OutputPath>
11+
<IntermediateOutputPath>$(RepoPath)\bin\obj\$(Platform)\$(Configuration)\</IntermediateOutputPath>
12+
<DefineConstants>
13+
$(DefineConstants);
14+
ProductVersion=$(ProductVersion);
15+
</DefineConstants>
16+
<DefineSolutionProperties>false</DefineSolutionProperties>
17+
<WixTargetsPath Condition="'$(WixTargetsPath)' == ''">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
18+
</PropertyGroup>
19+
<ItemGroup>
20+
<Compile Include="gh.wxs"/>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<!-- Include directory containing LICENSE.rtf (run ConvertTo-Rtf to regenerate from root LICENSE) -->
24+
<BindInputPaths Include="$(MSBuildProjectDirectory)"/>
25+
26+
<!-- Include directories containing both user-specified output and unzipped release for ease -->
27+
<BindInputPaths Include="$(SourceDir)"/>
28+
<BindInputPaths Include="$(SourceDir)\bin"/>
29+
</ItemGroup>
30+
<ItemGroup>
31+
<WixExtension Include="WixUIExtension"/>
32+
<WixExtension Include="WixUtilExtension"/>
33+
</ItemGroup>
34+
<Import Project="$(WixTargetsPath)"/>
35+
</Project>

build/windows/gh.wxs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<?ifndef ProductVersion?>
4+
<?error ProductVersion property not defined?>
5+
<?endif?>
6+
7+
<!-- Define a unique UpgradeCode per platform -->
8+
<?define UpgradeCode=8CFB9531-B959-4E1B-AA2E-4AF0FFCC4AF4?>
9+
10+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
11+
<Product Id="*" Name="GitHub CLI" Version="$(var.ProductVersion)" Language="1033" Manufacturer="GitHub, Inc." UpgradeCode="$(var.UpgradeCode)">
12+
<Package Compressed="yes" InstallerVersion="200" InstallScope="perMachine"/>
13+
<MediaTemplate EmbedCab="yes"/>
14+
15+
<!-- Remove older product(s) early but within the transaction -->
16+
<MajorUpgrade Schedule="afterInstallInitialize" DowngradeErrorMessage="A newer version of !(bind.property.ProductName) is already installed."/>
17+
18+
<!-- Upgrade older x86 products -->
19+
<Upgrade Id="7C0A5736-5B8E-4176-B350-613FA2D8A1B3">
20+
<UpgradeVersion Maximum="$(var.ProductVersion)" Property="OLDERX86VERSIONDETECTED"/>
21+
</Upgrade>
22+
23+
<Directory Id="TARGETDIR" Name="SourceDir">
24+
<Directory Id="ProgramFiles64Folder" Name="Program Files">
25+
<Directory Id="INSTALLDIR" Name="GitHub CLI"/>
26+
</Directory>
27+
</Directory>
28+
29+
<!-- Restore the INSTALLDIR if previously persisted to the registry -->
30+
<Property Id="INSTALLDIR">
31+
<RegistrySearch Id="InstallDir" Root="HKLM" Key="SOFTWARE\GitHub\CLI" Name="InstallDir" Type="directory"/>
32+
</Property>
33+
34+
<Feature Id="DefaultFeature" ConfigurableDirectory="INSTALLDIR">
35+
<!-- @Guid will be automatically and durably assigned based on key path -->
36+
<Component Directory="INSTALLDIR">
37+
<File Name="gh.exe"/>
38+
</Component>
39+
40+
<!-- Persist the INSTALLDIR and restore it in subsequent installs -->
41+
<Component Directory="INSTALLDIR">
42+
<RegistryValue Root="HKLM" Key="SOFTWARE\GitHub\CLI" Name="InstallDir" Type="string" Value="[INSTALLDIR]"/>
43+
</Component>
44+
45+
<Component Id="Env" Guid="94FAAC3D-4478-431C-8497-FBA55DCFB249" Directory="TARGETDIR">
46+
<Environment Id="Path" Action="set" Name="PATH" Part="last" System="yes" Value="[INSTALLDIR]"/>
47+
</Component>
48+
</Feature>
49+
50+
<!-- Broadcast environment variable changes -->
51+
<CustomActionRef Id="WixBroadcastEnvironmentChange" />
52+
53+
<!-- Use WixUI showing license and allowing user-specified INSTALLDIR -->
54+
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR"/>
55+
<UIRef Id="WixUI_InstallDir"/>
56+
<WixVariable Id="WixUILicenseRtf" Value="LICENSE.rtf"/>
57+
</Product>
58+
</Wix>

wix.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)