From 5531d67adb59301bb79ce3f5a0bc08af06ceca73 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 17 Jun 2023 11:51:52 -0700 Subject: [PATCH] GHA: add a workflow for performing a Windows release (#1471) Add some build rules to package up a Windows installer for release builds. Perform a separate build that is a release configuration and does not include debug information to minimise size and optimize load times. Package this up into a MSI installer. Ideally, we would perform code signing for the MSI and the binary, but that can be done as a follow up as it requires a Code Signing certificate to be available. The default install location is: `%SystemDrive%\Program Files\nicklockwood\SwiftFormat` following Windows conventions of `[ProgramFiles][Manufacturer][ProductName]`. Prefer to use `swoftprops/action-gh-release` over `actions/release` as the latter is marked as deprecated. --- .github/workflows/windows_release.yml | 61 +++++++++++++++++++++ Platforms/Windows/SwiftFormat.wixproj | 47 ++++++++++++++++ Platforms/Windows/SwiftFormat.wxs | 51 ++++++++++++++++++ Platforms/Windows/WixCodeSigning.targets | 69 ++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 .github/workflows/windows_release.yml create mode 100644 Platforms/Windows/SwiftFormat.wixproj create mode 100644 Platforms/Windows/SwiftFormat.wxs create mode 100644 Platforms/Windows/WixCodeSigning.targets diff --git a/.github/workflows/windows_release.yml b/.github/workflows/windows_release.yml new file mode 100644 index 00000000..3379aff1 --- /dev/null +++ b/.github/workflows/windows_release.yml @@ -0,0 +1,61 @@ +name: Windows Release + +on: + workflow_dispatch: + inputs: + revision: + description: 'Revision to build (branch, tag, or SHA)' + required: false + default: 'master' + + version: + description: 'Version being released' + required: false + default: '0.0.0' + +jobs: + windows: + runs-on: windows-latest + + strategy: + fail-fast: false + matrix: + include: + - branch: swift-5.8.1-release + tag: 5.8.1-RELEASE + + - branch: development + tag: DEVELOPMENT-SNAPSHOT-2023-06-05-a + + name: Windows (${{ matrix.tag }}) + + steps: + - uses: compnerd/gha-setup-swift@main + with: + tag: ${{ matrix.tag }} + branch: ${{ matrix.branch }} + + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.inputs.revision }} + + - run: swift build -c release -Xswiftc -gnone + + - uses: microsoft/setup-msbuild@v1.3.1 + + - run: msbuild -nologo -restore Platforms\Windows\SwiftFormat.wixproj -p:Configuration=Release -p:ProductVersion=${{ github.event.inputs.version }} -p:SWIFTFORMAT_BUILD=${{ github.workspace }}\.build\release -p:OutputPath=${{ github.workspace }}\artifacts -p:RunWixToolsOutOfProc=true + + - run: | + $MSI_PATH = cygpath -m ${{ github.workspace }}\artifacts\SwiftFormat.msi + Echo MSI_PATH=$MSI_PATH | Out-File -FilePath ${env:GITHUB_ENV} -Encoding utf8 -Append + + - name: release + uses: softprops/action-gh-release@v1 + with: + draft: true + prerelease: true + name: SwiftFormat v${{ github.event.inputs.version }} (Swift ${{ matrix.tag }}) + tag_name: v${{ github.event.inputs.version }} + files: | + .build/x86_64-unknown-windows-msvc/release/swiftformat.exe + ${{ env.MSI_PATH }} diff --git a/Platforms/Windows/SwiftFormat.wixproj b/Platforms/Windows/SwiftFormat.wixproj new file mode 100644 index 00000000..10c05fd7 --- /dev/null +++ b/Platforms/Windows/SwiftFormat.wixproj @@ -0,0 +1,47 @@ + + + false + + + + amd64 + $(ProductArchitecture) + + 0.0.0 + $(ProductVersion) + + + + build\ + build\obj\ + + + + + + ProductArchitecture=$(ProductArchitecture);ProductVersion=$(ProductVersion);SWIFTFORMAT_BUILD=$(SWIFT_FORMAT_BUILD) + + + + x64 + + + arm64 + 500 + + + arm + 500 + + + x86 + + + + + + + + + + diff --git a/Platforms/Windows/SwiftFormat.wxs b/Platforms/Windows/SwiftFormat.wxs new file mode 100644 index 00000000..2ef366c7 --- /dev/null +++ b/Platforms/Windows/SwiftFormat.wxs @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Platforms/Windows/WixCodeSigning.targets b/Platforms/Windows/WixCodeSigning.targets new file mode 100644 index 00000000..f69b1521 --- /dev/null +++ b/Platforms/Windows/WixCodeSigning.targets @@ -0,0 +1,69 @@ + + + + false + $(SignOutput) + + + + + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot10', null, RegistryView.Registry32, RegistryView.Default)) + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot81', null, RegistryView.Registry32, RegistryView.Default)) + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot', null, RegistryView.Registry32, RegistryView.Default)) + + + $(WindowsKitsRoot)bin\10.0.22621.0\x64\ + $(WindowsKitsRoot)bin\10.0.22000.0\x64\ + + $(WindowsKitsRoot)bin\10.0.20348.0\x64\ + $(WindowsKitsRoot)bin\10.0.19041.0\x64\ + $(WindowsKitsRoot)bin\10.0.18362.0\x64\ + $(WindowsKitsRoot)bin\10.0.17763.0\x64\ + $(WindowsKitsRoot)bin\10.0.17134.0\x64\ + $(WindowsKitsRoot)bin\10.0.16299.0\x64\ + $(WindowsKitsRoot)bin\10.0.15063.0\x64\ + $(WindowsKitsRoot)bin\10.0.14393.0\x64\ + $(WindowsKitsRoot)bin\10.0.10586.0\x64\ + $(WindowsKitsRoot)bin\10.0.10240.0\x64\ + + $(WindowsKitsRoot)bin\x64\ + + + $(WindowsKitsRoot)bin\10.0.22621.0\arm64\ + $(WindowsKitsRoot)bin\10.0.22000.0\arm64\ + + $(WindowsKitsRoot)bin\10.0.20348.0\arm64\ + $(WindowsKitsRoot)bin\10.0.19041.0\arm64\ + $(WindowsKitsRoot)bin\10.0.18362.0\arm64\ + $(WindowsKitsRoot)bin\10.0.17763.0\arm64\ + $(WindowsKitsRoot)bin\10.0.17134.0\arm64\ + $(WindowsKitsRoot)bin\10.0.16299.0\arm64\ + $(WindowsKitsRoot)bin\10.0.15063.0\arm64\ + $(WindowsKitsRoot)bin\10.0.14393.0\arm64\ + $(WindowsKitsRoot)bin\10.0.10586.0\arm64\ + $(WindowsKitsRoot)bin\10.0.10240.0\arm64\ + + "$(SignToolPath)signtool.exe" sign /f "$(CERTIFICATE)" /p "$(PASSPHRASE)" /tr http://timestamp.digicert.com /fd sha256 /td sha256 + + + + + + + + + + + + + + + + + + + + + + +