Skip to content

Commit 1cc46d7

Browse files
committed
Add script to generate version file dynamically
1 parent 2c1ce6d commit 1cc46d7

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

.github/workflows/generate-windows-installer.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ jobs:
2626
python -m pip install --upgrade pip
2727
python -m pip install -r requirements.txt
2828
29+
- name: Set version number for PyInstaller
30+
run: |
31+
python.exe tools\windows-installer\generate-version-info.py ${{github.event.release.tag_name}}
32+
2933
- name: Run PyInstaller to create binaries
3034
run: |
3135
pyinstaller.exe --noconfirm turing-system-monitor.spec
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
# turing-smart-screen-python - a Python system monitor and library for USB-C displays like Turing Smart Screen or XuanFang
3+
# https://github.com/mathoudebine/turing-smart-screen-python/
4+
#
5+
# Copyright (C) 2021-2023 Matthieu Houdebine (mathoudebine)
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
# generate-version-info.py: generate PyInstaller .exe version file from version number in argument
20+
# Inspired from PyInstaller/utils/cliutils/grab_version.py and PyInstaller/utils/win32/versioninfo.py
21+
22+
import codecs
23+
import sys
24+
from pathlib import Path
25+
26+
from PyInstaller.utils.win32 import versioninfo
27+
28+
# Load generic file and parse version info
29+
VERSION_INFO_FILE = str(Path(__file__).parent.resolve()) + "/pyinstaller-version-info.txt"
30+
info = versioninfo.load_version_info_from_text_file(VERSION_INFO_FILE)
31+
32+
if not info:
33+
raise SystemExit("Error: VersionInfo resource not found in exe")
34+
35+
# Get version number from argument
36+
version = sys.argv[1].split('.')
37+
major = int(version[0])
38+
minor = int(version[1])
39+
revision = int(version[2])
40+
build = 0 # For this project we only use 3-digit versions
41+
42+
# Update FixedFileInfo version
43+
info.ffi.fileVersionMS = (major << 16) + minor
44+
info.ffi.fileVersionLS = (revision << 16) + build
45+
info.ffi.productVersionMS = (major << 16) + minor
46+
info.ffi.productVersionLS = (revision << 16) + build
47+
48+
# Update StringFileInfo version
49+
for elem in info.kids[0].kids[0].kids:
50+
if elem.name == 'ProductVersion' or elem.name == 'FileVersion':
51+
elem.val = f"{major}.{minor}.{revision}"
52+
53+
# Update version file with new info, to be used by PyInstaller
54+
with codecs.open(VERSION_INFO_FILE, 'w', 'utf-8') as fp:
55+
fp.write(str(info))
56+
57+
print(f"Version info written to: {VERSION_INFO_FILE}")

tools/windows-installer/pyinstaller-version-info.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ VSVersionInfo(
66
ffi=FixedFileInfo(
77
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
88
# Set not needed items to zero 0.
9-
filevers=(3, 7, 0, 0),
10-
prodvers=(3, 7, 0, 0),
9+
filevers=(1, 2, 3, 4),
10+
prodvers=(1, 2, 3, 4),
1111
# Contains a bitmask that specifies the valid bits 'flags'r
1212
mask=0x0,
1313
# Contains a bitmask that specifies the Boolean attributes of the file.
@@ -31,8 +31,8 @@ VSVersionInfo(
3131
'040904b0',
3232
[StringStruct('FileDescription', 'System Monitor for USB smart screens like Turing'),
3333
StringStruct('ProductName', 'Turing System Monitor'),
34-
StringStruct('ProductVersion', '3.7.0'),
35-
StringStruct('FileVersion', '3.7.0')])
34+
StringStruct('ProductVersion', '1.2.3'),
35+
StringStruct('FileVersion', '1.2.3')])
3636
]),
3737
VarFileInfo([VarStruct('Translation', [1033, 1200])])
3838
]

tools/windows-installer/turing-system-monitor.iss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ AppName={#MyAppName}
1818
AppVersion={#MyAppVersion}
1919
AppPublisher={#MyAppPublisher}
2020
AppPublisherURL={#MyAppURL}
21-
AppSupportURL={#MyAppURL}
22-
AppUpdatesURL={#MyAppURL}
21+
AppSupportURL={#MyAppURL}/wiki
22+
AppUpdatesURL={#MyAppURL}/releases
2323
DefaultDirName={autopf}\{#MyAppName}
2424
DefaultGroupName={#MyAppName}
2525
OutputBaseFilename=turing-system-monitor_{#MyAppVersion}

0 commit comments

Comments
 (0)