aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/get_version.php
blob: 8d48b4a5ff9fc244b503293069819e505d0fe41a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php
// because of the values in .gitattributes, these should get modified according
// to the current commit (on any checkout) and/or ref (in archive exports)
// don't touch these yourself even if they look wrong!
const __GIT_ID_INFO__ = '$Id$';
const __GIT_REF_INFO__ = '$Format:%D$';

/**
 * Gets a version identifier for the currently checked out version of the software
 * @return string
 */
function get_version(): string {
    if (str_contains(__GIT_REF_INFO__, 'tag: ')) {
        return explode(',', explode('tag: ', __GIT_REF_INFO__, 2)[1], 2)[0];
    }
    // have to do this janky string thing to stop git replacing this one as well :3
    if (__GIT_ID_INFO__ != '$' . 'Id$') {
        return 'git ' . substr(__GIT_ID_INFO__, 5, 10);
    }
    return 'unknown';
}