@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
30 lines (29 loc) • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBuildInfoVariables = exports.ALL_BUILD_VARIABLES = void 0;
const BashExpression_1 = require("../bash/BashExpression");
const bashExpressionPerPipelineType_1 = require("../bash/bashExpressionPerPipelineType");
const BUILD_VARIABLES = {
BUILD_INFO_BUILD_ID: {
default: new BashExpression_1.BashExpression(`$(git describe --tags 2>/dev/null || git rev-parse HEAD)`)
},
BUILD_INFO_BUILD_TIME: {
default: "unknown-build-time",
gitlab: new BashExpression_1.BashExpression(`$CI_JOB_STARTED_AT`)
},
BUILD_INFO_CURRENT_VERSION: {
default: new BashExpression_1.BashExpression(
// because we do shallow fetch, we need to ask the origin
`$(tag=$(git ls-remote origin "refs/tags/v*[0-9]" 2>/dev/null | cut -f 2- | sort -V | tail -1 | sed 's/refs\\/tags\\/v//'); [ -z "$tag" ] && echo "0.0.0" || echo "$tag")`)
}
};
exports.ALL_BUILD_VARIABLES = Object.keys(BUILD_VARIABLES);
const getBuildInfoVariables = ctx => {
const {
pipelineType
} = ctx;
return Object.fromEntries(Object.entries(BUILD_VARIABLES).map(([key, value]) => [key, (0, bashExpressionPerPipelineType_1.getBashExpressionPerPipelineType)(value, pipelineType)]));
};
exports.getBuildInfoVariables = getBuildInfoVariables;