From b18fb0e5f8e8270ba5ec3b04c900f6692f6d6de7 Mon Sep 17 00:00:00 2001 From: soul-codes Date: Tue, 15 Oct 2024 18:41:05 -0400 Subject: [PATCH] =?UTF-8?q?ci:=20=F0=9F=8E=A1=20add=20version=20number=20t?= =?UTF-8?q?o=20executable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build_exe.yml | 20 ++++++++++++++++++++ .gitignore | 1 + components/splash.py | 15 +++++++++++++++ pyinstaller.spec | 6 ++++++ 4 files changed, 42 insertions(+) diff --git a/.github/workflows/build_exe.yml b/.github/workflows/build_exe.yml index 93ffa35..00c4c45 100644 --- a/.github/workflows/build_exe.yml +++ b/.github/workflows/build_exe.yml @@ -4,6 +4,9 @@ on: push: tags: - "v[0-9]+.[0-9]+.[0-9]+-?*" + pull_request: + branches: + - main workflow_dispatch: jobs: @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 32619bf..c284299 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __private__ /build /dist /analysis_outputs +VERSION diff --git a/components/splash.py b/components/splash.py index 9204a17..8e9cfe8 100644 --- a/components/splash.py +++ b/components/splash.py @@ -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 "" + + _ascii_splash: str = """ -..*+:..- -.=-+%@%##+-=.- diff --git a/pyinstaller.spec b/pyinstaller.spec index 29770fd..dcebb56 100644 --- a/pyinstaller.spec +++ b/pyinstaller.spec @@ -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'),