Skip to content

Commit b0eeacd

Browse files
Razishtaysta
andauthored
[Shared] Add git tag to version string (#1176)
* add short git hashes to engine and modules replace ~160 lines of cmake with a single call to git 🤷 * git error handling * add git hash to console * use consistent cvar name between SP and MP * normalise references to versions everywhere. use git tag instead of just the hash * redefine stringizing macros for win32 resource scripts * update actions to supported versions, use correct SHA for PRs Co-authored-by: tayst <taylor.brough13@gmail.com> * fix win32 resource file version for JK2 --------- Co-authored-by: tayst <taylor.brough13@gmail.com>
1 parent b6094d6 commit b0eeacd

36 files changed

+169
-446
lines changed

.github/workflows/build.yml

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,21 @@ jobs:
3636
platform: x64
3737

3838
steps:
39-
- uses: actions/checkout@v3
39+
- uses: actions/checkout@v4
40+
if: github.event_name == 'pull_request'
41+
with:
42+
fetch-depth: 0
43+
fetch-tags: true
44+
ref: ${{ github.event.pull_request.head.sha }}
45+
46+
- uses: actions/checkout@v4
47+
if: github.event_name != 'pull_request'
48+
with:
49+
fetch-depth: 0
50+
fetch-tags: true
4051

4152
- name: Add msbuild to PATH
42-
uses: microsoft/setup-msbuild@v1.1
53+
uses: microsoft/setup-msbuild@v1.3.2
4354

4455
- name: Create Build Environment
4556
run: cmake -E make_directory ${{ github.workspace }}/build
@@ -93,7 +104,18 @@ jobs:
93104
portable: [Non-Portable]
94105

95106
steps:
96-
- uses: actions/checkout@v3
107+
- uses: actions/checkout@v4
108+
if: github.event_name == 'pull_request'
109+
with:
110+
fetch-depth: 0
111+
fetch-tags: true
112+
ref: ${{ github.event.pull_request.head.sha }}
113+
114+
- uses: actions/checkout@v4
115+
if: github.event_name != 'pull_request'
116+
with:
117+
fetch-depth: 0
118+
fetch-tags: true
97119

98120
- name: Create Build Environment
99121
run: |
@@ -179,7 +201,18 @@ jobs:
179201
arch: arm64
180202

181203
steps:
182-
- uses: actions/checkout@v3
204+
- uses: actions/checkout@v4
205+
if: github.event_name == 'pull_request'
206+
with:
207+
fetch-depth: 0
208+
fetch-tags: true
209+
ref: ${{ github.event.pull_request.head.sha }}
210+
211+
- uses: actions/checkout@v4
212+
if: github.event_name != 'pull_request'
213+
with:
214+
fetch-depth: 0
215+
fetch-tags: true
183216

184217
- name: Create Build Environment
185218
run: |
@@ -214,17 +247,13 @@ jobs:
214247
if: ${{ matrix.build_type == 'Release' }}
215248
working-directory: ${{ github.workspace }}/install/JediAcademy
216249
shell: bash
217-
run: |
218-
chmod +x openjk.${{ matrix.arch }}.app/Contents/MacOS/openjk.${{ matrix.arch }}
219-
tar -czvf openjk-macos-${{ matrix.arch }}-${{ matrix.build_type }}-${{ matrix.portable }}.tar.gz *
250+
run: tar -czvf openjk-macos-${{ matrix.arch }}-${{ matrix.build_type }}-${{ matrix.portable }}.tar.gz *
220251

221252
- name: Create OpenJO binary archive
222253
if: ${{ matrix.build_type == 'Release' }}
223254
working-directory: ${{ github.workspace }}/install/JediOutcast
224255
shell: bash
225-
run: |
226-
chmod +x openjo_sp.${{ matrix.arch }}.app/Contents/MacOS/openjo_sp.${{ matrix.arch }}
227-
tar -czvf openjo_sp-macos-${{ matrix.arch }}-${{ matrix.build_type }}-${{ matrix.portable }}.tar.gz *
256+
run: tar -czvf openjo_sp-macos-${{ matrix.arch }}-${{ matrix.build_type }}-${{ matrix.portable }}.tar.gz *
228257

229258
- uses: actions/upload-artifact@v4
230259
if: ${{ matrix.build_type == 'Release' }}
@@ -245,7 +274,7 @@ jobs:
245274
needs: [msvc, ubuntu, macos]
246275
runs-on: ubuntu-22.04
247276
steps:
248-
- uses: actions/checkout@v3
277+
- uses: actions/checkout@v4
249278
with:
250279
submodules: recursive
251280

@@ -269,10 +298,11 @@ jobs:
269298
mv ./OpenJO-macos-arm64-Release-Non-Portable/* OpenJO-macos-arm64.tar.gz
270299
271300
- name: Create latest build
272-
uses: marvinpinto/action-automatic-releases@latest
301+
uses: softprops/action-gh-release@v1
273302
with:
274303
repo_token: ${{ secrets.GITHUB_TOKEN }}
275-
automatic_release_tag: "latest"
304+
generate_release_notes: true
305+
tag_name: "latest"
276306
prerelease: false
277307
title: Latest Build
278308
files: |
@@ -336,7 +366,7 @@ jobs:
336366
zip: false
337367

338368
steps:
339-
- uses: actions/checkout@v3
369+
- uses: actions/checkout@v4
340370
with:
341371
submodules: recursive
342372

CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,19 @@ else()
332332
message(STATUS "SOURCE_DATE_EPOCH is set ($ENV{SOURCE_DATE_EPOCH}): SOURCE_DATE set to \"${SOURCE_DATE}\"")
333333
endif()
334334

335-
# Current Git SHA1 hash
336-
include(GetGitRevisionDescription)
337-
get_git_head_revision(GIT_REFSPEC GIT_HASH)
338-
message(STATUS "Git revision is ${GIT_HASH}")
335+
# Current Git tag/version
336+
# ideally we would separate the hash suffix into its own variable, but sed is not available everywhere
337+
execute_process(
338+
COMMAND "git" "describe" "--tag"
339+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
340+
OUTPUT_VARIABLE GIT_TAG
341+
RESULT_VARIABLE GIT_TAG_ERROR
342+
OUTPUT_STRIP_TRAILING_WHITESPACE)
343+
if(GIT_TAG_ERROR AND NOT GIT_TAG_ERROR EQUAL 0)
344+
message(WARNING "Unable to determine Git tag")
345+
set(GIT_TAG vUNKNOWN)
346+
endif()
347+
message(STATUS "Git tag is ${GIT_TAG}")
339348

340349
configure_file(shared/qcommon/q_version.h.in shared/qcommon/q_version.h @ONLY)
341350

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ If you have the Mac App Store Version of Jedi Academy, follow these steps to get
7676
### Using OpenJK as a base for a new mod
7777

7878
- [Fork](https://github.com/JACoders/OpenJK/fork) the project on GitHub
79-
- Change the `GAMEVERSION` define in [codemp/game/g_local.h](https://github.com/JACoders/OpenJK/blob/master/codemp/game/g_local.h) from "OpenJK" to your project name
79+
- Change the JK_VERSION define in codemp/qcommon/game_version.h from "OpenJK" to your project name
8080
- If you make a nice change, please consider back-porting to upstream via pull request as described above. This is so everyone benefits without having to reinvent the wheel for every project.
8181

8282
## Maintainers (full list: [@JACoders](https://github.com/orgs/JACoders/people))

cmake/Modules/GetGitRevisionDescription.cmake

Lines changed: 0 additions & 123 deletions
This file was deleted.

cmake/Modules/GetGitRevisionDescription.cmake.in

Lines changed: 0 additions & 38 deletions
This file was deleted.

code/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ if(BuildSPEngine OR BuildJK2SPEngine)
183183
"${SPDir}/qcommon/z_memman_pc.cpp"
184184
"${SPDir}/qcommon/qfiles.h"
185185
"${SPDir}/qcommon/qcommon.h"
186-
"${SPDir}/qcommon/stv_version.h"
186+
"${SPDir}/qcommon/game_version.h"
187187
"${SPDir}/qcommon/timing.h"
188188
"${SPDir}/qcommon/MiniHeap.h"
189189

code/client/cl_console.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
2828

2929
#include "client.h"
3030
#include "qcommon/stringed_ingame.h"
31-
#include "qcommon/stv_version.h"
31+
#include "qcommon/game_version.h"
3232

3333
int g_console_field_width = 78;
3434

@@ -733,11 +733,11 @@ void Con_DrawSolidConsole( float frac )
733733
re.SetColor( console_color );
734734
re.DrawStretchPic( 0, y, SCREEN_WIDTH, 2, 0, 0, 0, 0, cls.whiteShader );
735735

736-
i = strlen( Q3_VERSION );
736+
i = strlen( JK_VERSION );
737737

738738
for (x=0 ; x<i ; x++) {
739739
SCR_DrawSmallChar( cls.glconfig.vidWidth - ( i - x + 1 ) * con.charWidth,
740-
(lines-(con.charHeight+con.charHeight/2)), Q3_VERSION[x] );
740+
(lines-(con.charHeight+con.charHeight/2)), JK_VERSION[x] );
741741
}
742742

743743
// draw the input prompt, user text, and cursor if desired

code/game/g_local.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
3636

3737
//==================================================================
3838

39-
// the "gameversion" client command will print this plus compile date
40-
#define GAMEVERSION "OpenJK"
41-
4239
#define BODY_QUEUE_SIZE 8
4340

4441
#define Q3_INFINITE 16777216

code/game/g_main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
3737
//rww - RAGDOLL_END
3838

3939
#include "qcommon/ojk_saved_game_helper.h"
40-
#include "qcommon/q_version.h"
40+
#include "qcommon/game_version.h"
4141

4242
extern void WP_SaberLoadParms( void );
4343
extern qboolean G_PlayerSpawned( void );
@@ -617,7 +617,7 @@ void G_InitCvars( void ) {
617617
g_developer = gi.cvar ("developer", "", 0);
618618

619619
// noset vars
620-
gi.cvar( "gamename", GAMEVERSION , CVAR_SERVERINFO | CVAR_ROM );
620+
gi.cvar( "gamename", JK_VERSION , CVAR_SERVERINFO | CVAR_ROM );
621621
gi.cvar( "gamedate", SOURCE_DATE , CVAR_ROM );
622622
g_skippingcin = gi.cvar ("skippingCinematic", "0", CVAR_ROM);
623623

@@ -734,7 +734,7 @@ void InitGame( const char *mapname, const char *spawntarget, int checkSum, cons
734734
g_qbLoadTransition = qbLoadTransition;
735735

736736
gi.Printf ("------- Game Initialization -------\n");
737-
gi.Printf ("gamename: %s\n", GAMEVERSION);
737+
gi.Printf ("gamename: %s\n", JK_VERSION);
738738
gi.Printf ("gamedate: %s\n", SOURCE_DATE);
739739

740740
srand( randomSeed );

0 commit comments

Comments
 (0)