Merge pull request #11048 from cli/babakks/embed-winres-at-release
Embed Windows resources (VERSIONINFO) during build
This commit is contained in:
commit
2fc1e548cc
4 changed files with 118 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -15,6 +15,9 @@
|
|||
/pkg_payload
|
||||
/build/macOS/resources
|
||||
|
||||
# Windows resource files
|
||||
/cmd/gh/*.syso
|
||||
|
||||
# VS Code
|
||||
.vscode
|
||||
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
70
script/gen-winres.ps1
Executable file
70
script/gen-winres.ps1
Executable file
|
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/env pwsh
|
||||
|
||||
$_usage = @"
|
||||
Generate Windows resource files as ``.syso``
|
||||
|
||||
Usage:
|
||||
gen-winres.ps1 <file-version> <product-version> <path-to-versioninfo.json> <output-path>
|
||||
|
||||
Arguments:
|
||||
<file-version> string to set as file version (e.g. "1.0.0")
|
||||
<product-version> string to set as product version (e.g. "1.0.0")
|
||||
<path-to-versioninfo.json> path to the ``versioninfo.json`` file containing static metadata
|
||||
<output-path> directory where the generated ``.syso`` files should be placed
|
||||
|
||||
The created ``.syso`` files are named as ``resource_windows_<arch>.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
|
||||
43
script/versioninfo.template.json
Normal file
43
script/versioninfo.template.json
Normal file
|
|
@ -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": ""
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue