
const getVersion = require ('./services/version')
const shell = require('shelljs')
const {
  requireValue,
  execShell
  } = require('./services/utils')

module.exports = async (options, logger) => {

  if (!shell.which('git')) {
    logger('This script requires git'.red);
    return 1
  }

  const versionInfo = getVersion(options, logger)

  let {
    version = process.env.VERSION || versionInfo.version || requireValue('version'),
    build_id = process.env.BUILD_ID || versionInfo.build_id || requireValue('build'),
    debug = false
  } = options

  logger(`Tagging git with ${version} version and ${build_id} build-id`.gray)

  execShell(`git tag  -f -a "${version}" -m "Version:${version} Build:${build_id} [skip ci]"`)

  if(!debug)
    execShell(`git push origin -f --tags --no-verify`)

  return 0
}
