Skip to content

Commit

Permalink
ci: 🎡 add version number to executable
Browse files Browse the repository at this point in the history
  • Loading branch information
soul-codes committed Oct 16, 2024
1 parent 33f0726 commit b18fb0e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build_exe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+-?*"
pull_request:
branches:
- main
workflow_dispatch:

jobs:
Expand All @@ -14,6 +17,7 @@ jobs:
- platform_name: Windows
artifact_name: windows
os: windows-2022
version_command: icacls "VERSION" /grant Everyone:F /T /C /Q
move_command: move dist\mangotango.exe dist\mangotango_windows.exe
sha_command: pwsh -c "Get-FileHash -Algorithm SHA1 dist\mangotango_windows.exe | Format-Table Hash -HideTableHeaders > dist\mangotango_windows.exe.sha1"
list_command: dir dist
Expand Down Expand Up @@ -70,6 +74,22 @@ jobs:
- name: Install PyInstaller
run: pip install pyinstaller

- name: Print version string (for tag)
id: get_version_tag
if: ${{ github.ref_type == 'tag' }}
run: |
python -c "with open('VERSION', 'w', encoding='utf-8') as f: f.write('${{ github.ref_name }}')"
- name: Print version string (for branch)
id: get_version_branch
if: ${{ github.ref_type != 'tag' }}
run: |
python -c "with open('VERSION', 'w', encoding='utf-8') as f: f.write('${{ github.ref_name }}-${{ github.sha }}')"
- name: Modify version string permission
if: ${{ matrix.version_command }}
run: ${{ matrix.version_command }}

- name: Build the executable
run: |
pyinstaller pyinstaller.spec
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __private__
/build
/dist
/analysis_outputs
VERSION
15 changes: 15 additions & 0 deletions components/splash.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
from terminal_tools import clear_terminal, wait_for_key
from pathlib import Path
import os


def splash():
clear_terminal()
print(_ascii_splash)
print("")
print(f"{get_version()}")
print("")
wait_for_key(True)


def get_version():
root_path = str(Path(__file__).resolve().parent.parent)
version_path = os.path.join(root_path, "VERSION")
try:
with open(version_path, "r") as version_file:
return version_file.read().strip()
except FileNotFoundError:
return "<development version>"


_ascii_splash: str = """
-..*+:..-
-.=-+%@%##+-=.-
Expand Down
6 changes: 6 additions & 0 deletions pyinstaller.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ a = Analysis(
pathex=['.'], # Ensure all paths are correctly included
binaries=[],
datas=[
# version file, if defined
*(
[('VERSION', 'VERSION')]
if os.path.exists('VERSION') else []
),

# inquirer depends on readchar as a hidden dependency that requires package metadata
*copy_metadata('readchar'),

Expand Down

0 comments on commit b18fb0e

Please sign in to comment.