@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
47 lines (46 loc) • 1.52 kB
JavaScript
;
var __assign = this && this.__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.addCacheFallback = exports.getCacheKeyWithFallbackForMR = void 0;
var getCacheKeyWithFallbackForMR = function (baseKey, context) {
// if its a branch, create a key with the branch name with fallback to the base key
if (context.trigger === "mr") {
return {
key: baseKey + "-mr$CI_MERGE_REQUEST_IID",
fallback_keys: [baseKey]
};
}
return {
key: baseKey
};
};
exports.getCacheKeyWithFallbackForMR = getCacheKeyWithFallbackForMR;
var addCacheFallback = function (cache, context) {
if (context.type !== "agent" && context.trigger === "mr") {
if (Array.isArray(cache)) {
return cache.map(function (c) {
return addCacheFallbackToSingleCacheForMR(c, context);
});
}
return addCacheFallbackToSingleCacheForMR(cache, context);
}
return cache;
};
exports.addCacheFallback = addCacheFallback;
var addCacheFallbackToSingleCacheForMR = function (cache, context) {
if (typeof cache.key === "string") {
return __assign(__assign({}, cache), (0, exports.getCacheKeyWithFallbackForMR)(cache.key, context));
}
return cache; // as is
};