Skip to content

Commit

Permalink
ci: build Windows installer
Browse files Browse the repository at this point in the history
  • Loading branch information
john-u committed Jul 11, 2022
1 parent 2ada1f4 commit 76ba4c5
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/selfish-pears-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smartthings/cli": patch
---

Add Windows installer build
61 changes: 61 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:

runs-on: ubuntu-latest

outputs:
cli-released: ${{ steps.cli-release.outputs.published }}
cli-version: ${{ steps.cli-metadata.outputs.version }}
cli-tag: ${{ steps.cli-metadata.outputs.tag }}

steps:
- name: Checkout Repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -89,3 +94,59 @@ jobs:
Created by https://github.com/mislav/bump-homebrew-formula-action
env:
COMMITTER_TOKEN: ${{ secrets.HOMEBREW_COMMITTER_TOKEN }}

- name: Upload .exe Artifact
if: steps.cli-package.outcome == 'success'
uses: actions/upload-artifact@v3
with:
name: windows-exe
path: packages/cli/dist_bin/win/smartthings.exe

windows-installer:
needs: release

if: needs.release.outputs.cli-released == 'true'

name: Release Windows Installer

# ensure WiX Toolset is installed on image before updating runner
# ex: https://github.com/actions/virtual-environments/blob/b87bdfb146bdd41a98f33fc9572a961e9a60e9dd/images/win/Windows2022-Readme.md
runs-on: windows-2022

steps:
# remove any pre-release labels since WiX doesn't support them
- name: Sanitize CLI Version String
id: safe-semver
run: echo "::set-output name=version::$('${{ needs.release.outputs.cli-version }}'.Split('-') | Select-Object -Index 0)"

- name: Checkout Repo
uses: actions/checkout@v3

- name: Download .exe Artifact
uses: actions/download-artifact@v3
with:
name: windows-exe
path: packages\cli\wix

# https://github.community/t/set-path-for-wix-toolset-in-windows-runner/154708/2
# https://stackoverflow.com/a/71579543
- name: Add WiX Toolset to Path
run: Add-Content $env:GITHUB_PATH "C:\Program Files (x86)\WiX Toolset v3.11\bin"

- name: Compile WiX file
run: candle.exe smartthings.wxs -ext WixUIExtension
working-directory: packages\cli\wix
env:
SMARTTHINGS_SEMVER: ${{ steps.safe-semver.outputs.version }}
# must be absolute path or relative to .wxs file
SMARTTHINGS_BINARY_PATH: .\smartthings.exe

- name: Build .msi
run: light.exe -out smartthings.msi smartthings.wixobj -ext WixUIExtension
working-directory: packages\cli\wix

- name: Add .msi Artifact to Github Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.release.outputs.cli-tag }}
files: packages\cli\wix\smartthings.msi
Binary file added packages/cli/wix/License.rtf
Binary file not shown.
39 changes: 39 additions & 0 deletions packages/cli/wix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## SmartThings CLI Windows Installer

### WiX Toolset

We use a "simple" [WiX Toolset](https://wixtoolset.org/) v3 configuration. The majority of the .wxs file was written with these examples as reference <https://github.com/kurtanr/WiXInstallerExamples>. Comments try to point to references for info that is not immediately intuitive.

### smartthings.wxs

This is the WiX source file that needs to be "compiled" to a `.wixobj` and then finally linked into an `.msi`. The steps and expectations for this process are below.

#### Environment Variables

The WiX file includes some build variables that can be passed by setting specific env vars in the shell that runs the tasks.

1. `SMARTTHINGS_SEMVER`: Sets the version that shows in Windows Programs and Features. This should not include the fourth section of the Windows format, as we ignore this and leave 0. Pre-release labels are not supported.

1. `SMARTTHINGS_BINARY_PATH`: Specifies the location of the executable that we want to install. This will need to be accessible during the linking step below, so needs to be relative path to the `.wxs` file or an absolute system path.

#### License

The End User License Agreement step of the installer requires an `.rtf` file specified in the WiX markup. The current setup assumes this is in the same directory as the `.wxs` file.

#### Usage

The following assumes running under Windows OS with the WiX Toolset installed and on the system Path. GitHub hosted runners have the v3 tools installed by default as of writing. These tasks are ran in the same directory as required files.

> :warning: Ensure the required Environment Variables are set.
Compile WiX Source

```console
candle.exe smartthings.wxs -ext WixUIExtension
```

Build .msi Installer

```console
light.exe -out smartthings.msi smartthings.wixobj -ext WixUIExtension
```
64 changes: 64 additions & 0 deletions packages/cli/wix/smartthings.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!-- Version cannot include pre-release label extensions -->
<!-- https://github.com/kurtanr/WiXInstallerExamples/tree/main/00_HelloWorldInstaller#product -->
<Product
Id="*"
Language="1033"
Manufacturer="SmartThings"
Name="SmartThings CLI"
UpgradeCode="{AA0B7D9A-214A-4F22-9E4A-773E9FE7AE94}"
Version="$(env.SMARTTHINGS_SEMVER).0">

<Package
InstallScope="perMachine"
InstallerVersion="200"
Compressed="yes" />

<MajorUpgrade DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />

<!-- https://github.com/kurtanr/WiXInstallerExamples/tree/main/00_HelloWorldInstaller#mediatemplate -->
<MediaTemplate EmbedCab="yes" />

<!-- https://github.com/kurtanr/WiXInstallerExamples/tree/main/00_HelloWorldInstaller#directory -->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="SmartThings" />
</Directory>
</Directory>

<ComponentGroup Directory="INSTALLDIR" Id="ProductComponentGroup">
<!-- https://github.com/kurtanr/WiXInstallerExamples/tree/main/00_HelloWorldInstaller#component -->
<Component Id="ProductComponent">
<File KeyPath="yes" Source="$(env.SMARTTHINGS_BINARY_PATH)"></File>
</Component>
</ComponentGroup>

<!-- https://stackoverflow.com/a/46366291 -->
<DirectoryRef Id="TARGETDIR">
<Component Id="PathComponent" Guid="{B01A7C23-58B3-43C8-A61C-AF8D1649CC6F}">
<Environment
Id="PATH"
Name="PATH"
Value="[INSTALLDIR]"
Permanent="no"
Part="last"
Action="set"
System="no" />
</Component>
</DirectoryRef>

<!-- https://wixtoolset.org//documentation/manual/v3/wixui/dialog_reference/wixui_installdir.html -->
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
<UIRef Id="WixUI_InstallDir" />

<Feature Id="SmartThingsFeature">
<ComponentRef Id="ProductComponent" />
<ComponentRef Id="PathComponent" />
</Feature>

<!-- https://stackoverflow.com/a/1116236 -->
<WixVariable Id="WixUILicenseRtf" Value="License.rtf" />

</Product>
</Wix>
3 changes: 2 additions & 1 deletion packages/cli/zip-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ function zip_binary() {
tar -czf assets/smartthings-$os.tar.gz "smartthings$ext"
fi
zip assets/smartthings-$os.zip "smartthings$ext"
mv "smartthings$ext" "smartthings-$os$ext"
mkdir -p $os
mv "smartthings$ext" "$os"
)
}

Expand Down

0 comments on commit 76ba4c5

Please sign in to comment.