aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/version.ts
blob: 5b3bf59dd75d3192bcec762e013cb5b92dfd49c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { execPromise, execPromise2 } from './core-utils'
import { logger } from './logger'

async function getServerCommit () {
  try {
    const tag = await execPromise2(
      '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true',
      { stdio: [ 0, 1, 2 ] }
    )

    if (tag) return tag.replace(/^v/, '')
  } catch (err) {
    logger.debug('Cannot get version from git tags.', { err })
  }

  try {
    const version = await execPromise('[ ! -d .git ] || git rev-parse --short HEAD')

    if (version) return version.toString().trim()
  } catch (err) {
    logger.debug('Cannot get version from git HEAD.', { err })
  }

  return ''
}

function getNodeABIVersion () {
  const version = process.versions.modules

  return parseInt(version)
}

export {
  getServerCommit,
  getNodeABIVersion
}