From e6e49d4601afb4047043cf4400504c51ac656896 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sat, 23 Dec 2023 20:20:00 -0500 Subject: [PATCH 1/9] 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 a3de381be..3839a734e 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 77b6a0f74..73262ac95 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 From c522250a400bb94126f3a084e3fadf2802e4ed56 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sat, 23 Dec 2023 22:03:46 -0500 Subject: [PATCH 2/9] More indentation to satisfy linter --- config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/__init__.py b/config/__init__.py index 73262ac95..5ce889f43 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -141,7 +141,7 @@ def appversion() -> semantic_version.Version: # 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() + shorthash = gitv.read() else: shorthash = git_shorthash_from_head() if shorthash is None: From b6150cab7d0a6e159f0b93fa088add4d29e7cb7b Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sun, 24 Dec 2023 10:09:49 -0500 Subject: [PATCH 3/9] Further satisfy linter --- config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/__init__.py b/config/__init__.py index 5ce889f43..25acc41ae 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -139,7 +139,7 @@ def appversion() -> semantic_version.Version: else: # 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: + if pathlib.Path("./" + GITVERSION_FILE).is_file(): with open(pathlib.Path("./" + GITVERSION_FILE)) as gitv: shorthash = gitv.read() else: From 16f584b519a4ede5b7e2a86f51bc26bc91c56b45 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sun, 24 Dec 2023 10:25:44 -0500 Subject: [PATCH 4/9] Rename for testing --- .github/workflows/{build-on-release.yml => windows-build.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{build-on-release.yml => windows-build.yml} (100%) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/windows-build.yml similarity index 100% rename from .github/workflows/build-on-release.yml rename to .github/workflows/windows-build.yml From ffecae17a713fe23d39404f22e57465b8c62cf88 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sun, 24 Dec 2023 10:28:50 -0500 Subject: [PATCH 5/9] Need 8 characters --- .github/workflows/windows-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 3839a734e..55c63d908 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -20,7 +20,7 @@ jobs: with: script: | core.setOutput('sem_ver', '${{ github.ref_name }}'.replaceAll('Release\/', '')) - core.setOutput('short_sha', '${{ github.sha }}'.substring(0, 7)) + core.setOutput('short_sha', '${{ github.sha }}'.substring(0, 8)) linux_build: needs: [variables] From 4ae516677e5299e4c7e3c9edd811578cddf715fb Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sun, 24 Dec 2023 10:34:35 -0500 Subject: [PATCH 6/9] More excludes, change path for .gitversion --- .github/workflows/windows-build.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 55c63d908..b6883d256 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -32,7 +32,7 @@ jobs: submodules: true - name: Create .gitversion run: | - echo "${{ needs.variables.outputs.short_sha }}" > ../.gitversion + echo "${{ needs.variables.outputs.short_sha }}" > .gitversion - name: Make tar archive run: | @@ -44,10 +44,11 @@ jobs: --exclude=EDMarketConnector-release-*.* \ --exclude=.editorconfig \ --exclude=.flake8 \ - --exclude=.gitattribues \ + --exclude=.gitattributes \ --exclude=.gitignore \ --exclude=.gitmodules \ --exclude=.git \ + --exclude=.github \ --exclude=.mypy.ini \ --exclude=.pre-commit-config.yaml \ --exclude=build.py \ From 6f84e39a4a675512d115aba153a70cefed231770 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sun, 24 Dec 2023 11:25:37 -0500 Subject: [PATCH 7/9] Proper check for .gitversion --- config/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 25acc41ae..860e9750c 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -139,10 +139,12 @@ def appversion() -> semantic_version.Version: else: # 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: + if pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE).exists(): + print("Found .gitversion") + with open(pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE), encoding='utf-8') as gitv: shorthash = gitv.read() else: + print("Did not find .gitversion in " + sys.path[0] + "/" + GITVERSION_FILE) shorthash = git_shorthash_from_head() if shorthash is None: shorthash = 'UNKNOWN' From 35ff88b83b20be659657a517602d4a099d10163d Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sun, 24 Dec 2023 15:58:06 -0500 Subject: [PATCH 8/9] Remove debug prints --- config/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index 860e9750c..acd6bbb6c 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -140,11 +140,9 @@ def appversion() -> semantic_version.Version: # 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(sys.path[0] + "/" + GITVERSION_FILE).exists(): - print("Found .gitversion") with open(pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE), encoding='utf-8') as gitv: shorthash = gitv.read() else: - print("Did not find .gitversion in " + sys.path[0] + "/" + GITVERSION_FILE) shorthash = git_shorthash_from_head() if shorthash is None: shorthash = 'UNKNOWN' From 3947c6af63fd90d644e90ebf0c06238f0cf89129 Mon Sep 17 00:00:00 2001 From: David Muckle Date: Sun, 24 Dec 2023 21:42:00 -0500 Subject: [PATCH 9/9] Reorder cases --- config/__init__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/config/__init__.py b/config/__init__.py index acd6bbb6c..33d531e93 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -137,14 +137,15 @@ def appversion() -> semantic_version.Version: shorthash = gitv.read() else: - # 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(sys.path[0] + "/" + GITVERSION_FILE).exists(): - with open(pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE), encoding='utf-8') as gitv: - shorthash = gitv.read() - else: - shorthash = git_shorthash_from_head() - if shorthash is None: + # Running from source. Use git rev-parse --short HEAD + # or fall back to .gitversion file if it exists. + # This is also required for the Flatpak + shorthash = git_shorthash_from_head() + if shorthash is None: + if pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE).exists(): + with open(pathlib.Path(sys.path[0] + "/" + GITVERSION_FILE), encoding='utf-8') as gitv: + shorthash = gitv.read() + else: shorthash = 'UNKNOWN' _cached_version = semantic_version.Version(f'{_static_appversion}+{shorthash}')