diff --git a/.gitignore b/.gitignore index 272b7703d..a4b73ac7a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ /pkg_payload /build/macOS/resources +# Windows resource files +/cmd/gh/*.syso + # VS Code .vscode diff --git a/.goreleaser.yml b/.goreleaser.yml index 6ef1ecc8b..309e2ca8f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -11,6 +11,8 @@ before: {{ if eq .Runtime.Goos "windows" }}echo{{ end }} make manpages GH_VERSION={{.Version}} - >- # On linux the completions are used in nfpms below, but on macos they are used outside in the deployment build. {{ if eq .Runtime.Goos "windows" }}echo{{ end }} make completions + - >- # We need to create the `.syso` files (per architecture) to embed Windows resources (version info) + {{ if ne .Runtime.Goos "windows" }}echo{{ end }} pwsh .\script\gen-winres.ps1 '{{ .Version }} ({{time "2006-01-02"}})' '{{ .Version }}' .\script\versioninfo.template.json .\cmd\gh\ builds: - id: macos #build:macos goos: [darwin] diff --git a/script/gen-winres.ps1 b/script/gen-winres.ps1 new file mode 100755 index 000000000..e5eab1c9c --- /dev/null +++ b/script/gen-winres.ps1 @@ -0,0 +1,70 @@ +#!/usr/bin/env pwsh + +$_usage = @" +Generate Windows resource files as ``.syso`` + +Usage: + gen-winres.ps1 + +Arguments: + string to set as file version (e.g. "1.0.0") + string to set as product version (e.g. "1.0.0") + path to the ``versioninfo.json`` file containing static metadata + directory where the generated ``.syso`` files should be placed + +The created ``.syso`` files are named as ``resource_windows_.syso``. This +helps Go compiler to pick the correct file based on the target platform and +architecture. +"@ + +$ErrorActionPreference = "Stop" + +$_file_version = $args[0] +if ([string]::IsNullOrEmpty($_file_version)) { + Write-Host "error: file-version argument is missing" + Write-Host $_usage + exit 1 +} + +$_product_version = $args[1] +if ([string]::IsNullOrEmpty($_product_version)) { + Write-Host "error: product-version argument is missing" + Write-Host $_usage + exit 1 +} + +$_versioninfo_path = $args[2] +if ([string]::IsNullOrEmpty($_versioninfo_path)) { + Write-Host "error: path to versioninfo.json is missing" + Write-Host $_usage + exit 1 +} + +if (-not (Test-Path $_versioninfo_path)) { + Write-Host "error: path to versioninfo.json '$_versioninfo_path' is not a file" + Write-Host $_usage + exit 1 +} + +$_output = $args[3] +if ([string]::IsNullOrEmpty($_output)) { + Write-Host "error: output path is missing" + Write-Host $_usage + exit 1 +} + +if (-not (Test-Path $_output -PathType Container)) { + Write-Host "error: output path '$_output' is not a directory" + Write-Host $_usage + exit 1 +} + +go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@v1.5.0 + +goversioninfo ` + -64 -arm -platform-specific ` + -file-version "$_file_version" ` + -product-version "$_product_version" ` + "$_versioninfo_path" + +Move-Item -Path "resource_windows_*.syso" -Destination "$_output" -Force diff --git a/script/versioninfo.template.json b/script/versioninfo.template.json new file mode 100644 index 000000000..6096837ff --- /dev/null +++ b/script/versioninfo.template.json @@ -0,0 +1,43 @@ +{ + "FixedFileInfo": { + "FileVersion": { + "Major": 0, + "Minor": 0, + "Patch": 0, + "Build": 0 + }, + "ProductVersion": { + "Major": 0, + "Minor": 0, + "Patch": 0, + "Build": 0 + }, + "FileFlagsMask": "3f", + "FileFlags ": "00", + "FileOS": "040004", + "FileType": "01", + "FileSubType": "00" + }, + "StringFileInfo": { + "Comments": "", + "CompanyName": "GitHub", + "FileDescription": "GitHub CLI", + "FileVersion": "", + "InternalName": "gh", + "LegalCopyright": "", + "LegalTrademarks": "", + "OriginalFilename": "gh.exe", + "PrivateBuild": "", + "ProductName": "GitHub CLI", + "ProductVersion": "", + "SpecialBuild": "" + }, + "VarFileInfo": { + "Translation": { + "LangID": "0409", + "CharsetID": "04B0" + } + }, + "IconPath": "", + "ManifestPath": "" +} \ No newline at end of file