From e6e49d4601afb4047043cf4400504c51ac656896 Mon Sep 17 00:00:00 2001
From: David Muckle <dvdmuckle@dvdmuckle.xyz>
Date: Sat, 23 Dec 2023 20:20:00 -0500
Subject: [PATCH] Include .gitversion in linux archive

---
 .../{windows-build.yml => build-on-release.yml}     | 13 ++++++++++---
 config/__init__.py                                  | 13 +++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)
 rename .github/workflows/{windows-build.yml => build-on-release.yml} (92%)

diff --git a/.github/workflows/windows-build.yml b/.github/workflows/build-on-release.yml
similarity index 92%
rename from .github/workflows/windows-build.yml
rename to .github/workflows/build-on-release.yml
index a3de381b..3839a734 100644
--- a/.github/workflows/windows-build.yml
+++ b/.github/workflows/build-on-release.yml
@@ -1,5 +1,5 @@
 # vim: tabstop=2 shiftwidth=2
-name: Build EDMC for Windows
+name: Build EDMC
 
 on:
   push:
@@ -11,7 +11,7 @@ jobs:
   variables:
     outputs:
       sem_ver: ${{ steps.var.outputs.sem_ver }}
-      archive_exclusions: ${{ steps.var.outputs.archive_exclusions }}
+      short_sha: ${{ steps.var.outputs.short_sha }}
     runs-on: "ubuntu-latest"
     steps:
       - name: Setting global variables
@@ -20,6 +20,7 @@ jobs:
         with:
           script: |
             core.setOutput('sem_ver', '${{ github.ref_name }}'.replaceAll('Release\/', ''))
+            core.setOutput('short_sha', '${{ github.sha }}'.substring(0, 7))
 
   linux_build:
     needs: [variables]
@@ -29,6 +30,9 @@ jobs:
       - uses: actions/checkout@v4
         with:
           submodules: true
+      - name: Create .gitversion
+        run: |
+          echo "${{ needs.variables.outputs.short_sha }}" > ../.gitversion
 
       - name: Make tar archive
         run: |
@@ -40,7 +44,10 @@ jobs:
               --exclude=EDMarketConnector-release-*.* \
               --exclude=.editorconfig \
               --exclude=.flake8 \
-              --exclude=.git* \
+              --exclude=.gitattribues \
+              --exclude=.gitignore \
+              --exclude=.gitmodules \
+              --exclude=.git \
               --exclude=.mypy.ini \
               --exclude=.pre-commit-config.yaml \
               --exclude=build.py \
diff --git a/config/__init__.py b/config/__init__.py
index 77b6a0f7..73262ac9 100644
--- a/config/__init__.py
+++ b/config/__init__.py
@@ -137,10 +137,15 @@ def appversion() -> semantic_version.Version:
             shorthash = gitv.read()
 
     else:
-        # Running from source
-        shorthash = git_shorthash_from_head()
-        if shorthash is None:
-            shorthash = 'UNKNOWN'
+        # Running from source. For Linux, check to see if .gitversion file exists
+        # If so, use it. This is also required for the Flatpak
+        if pathlib.Path("./" + GITVERSION_FILE).is_file:
+            with open(pathlib.Path("./" + GITVERSION_FILE)) as gitv:
+              shorthash = gitv.read()
+        else:
+            shorthash = git_shorthash_from_head()
+            if shorthash is None:
+                shorthash = 'UNKNOWN'
 
     _cached_version = semantic_version.Version(f'{_static_appversion}+{shorthash}')
     return _cached_version