Skip to content

Commit

Permalink
Merge pull request #128 from nbelakovski/use_git_describe
Browse files Browse the repository at this point in the history
  • Loading branch information
zaikunzhang authored Jan 2, 2024
2 parents 95ae22c + 05083c1 commit c3196b7
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions .git-archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:%(describe:tags=true,match=v[0-9]*)$
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@
*.fits binary
*.npy binary
*.npz binary

# Version files for git archive
.git-archival.txt export-subst
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2138,3 +2138,4 @@ chocolatey
fcn
BINDIR
cmdfile
macports
12 changes: 8 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,21 @@ jobs:
uses: actions/checkout@v4
if: github.event.inputs.git-ref == ''
with:
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
submodules: recursive
fetch-depth: 0
fetch-tags: true
- name: Clone Repository (Custom Ref)
uses: actions/checkout@v4
if: github.event.inputs.git-ref != ''
with:
ref: ${{ github.event.inputs.git-ref }}
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
# ssh-key: ${{ secrets.SSH_PRIVATE_KEY_ACT }} # This forces checkout to use SSH, not HTTPS
# As of 231227, checkout with ssh fails frequently on Windows runners.
submodules: recursive
fetch-depth: 0
fetch-tags: true

- name: Miscellaneous setup
run: bash .github/scripts/misc_setup
Expand Down
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,29 @@ if (PRIMA_ENABLE_C)
set(primac_target "primac")
endif ()

file (STRINGS VERSION.txt PRIMA_VERSION)
# Get the version number
find_package(Git)
if(GIT_EXECUTABLE)
# --always means git describe will output the commit hash if no tags are found
# This is usually the case for forked repos since they do not clone tags by default.
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --always --dirty
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE PRIMA_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
# If git is not available, that may indicate we are building on macports which
# downloads the bundle from github (which uses git archive) and so the version
# number should be in .git-archival.txt
file(STRINGS .git-archival.txt PRIMA_VERSION)
if(PRIMA_VERSION MATCHES "describe")
message(WARNING "No git detected and .git-archival.txt does not contain a version number")
set(PRIMA_VERSION "unknown")
endif()

endif()
# Remove the leading v from PRIMA_VERSION, if it contains one.
string(REGEX REPLACE "^v" "" PRIMA_VERSION ${PRIMA_VERSION})
message(STATUS "Setting PRIMA version to ${PRIMA_VERSION}")

install(
TARGETS primaf ${primac_target}
Expand Down
1 change: 0 additions & 1 deletion VERSION.txt

This file was deleted.

0 comments on commit c3196b7

Please sign in to comment.