@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
103 lines (102 loc) โข 5.53 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);
};
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createNodeTestJobs = void 0;
var runner_1 = require("../../runner");
var context_1 = require("../../types/context");
var utils_1 = require("../../utils");
var createArtifactsConfig_1 = require("../base/createArtifactsConfig");
var cache_1 = require("./cache");
var constants_1 = require("./constants");
var yarn_1 = require("./yarn");
var createJobCache_1 = require("../cache/createJobCache");
var createNodeTestJobs = function (context) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
// don't run tests after release
// TODO: this will be replaced by using rules
if (context.trigger === "taggedRelease") {
return [];
}
// if its not a standalone build, we don't need to run tests
if (context.type === "component" && !(0, context_1.componentContextIsStandaloneBuild)(context)) {
return [];
}
var defaultImage = (0, runner_1.getRunnerImage)("jobs-default");
var base = {
variables: __assign({
APP_PATH: context.build.dir
}, context.type === "component" ? __assign({}, context.environment.jobOnlyVars.build.envVars) : {}),
runnerVariables: constants_1.NODE_RUNNER_BUILD_VARIABLES,
stage: "test",
needs: []
};
var buildConfig = context.build.config;
var yarnInstall = (0, yarn_1.getYarnInstall)(context);
var auditJob = buildConfig.audit !== false ? __assign(__assign(__assign({
name: "๐ก audit"
}, base), {
image: (_b = (_a = buildConfig.audit) === null || _a === void 0 ? void 0 : _a.jobImage) !== null && _b !== void 0 ? _b : defaultImage,
cache: undefined,
script: __spreadArray(["cd ".concat(context.build.dir)], __read((_d = (0, utils_1.ensureArrayOrNull)((_c = buildConfig.audit) === null || _c === void 0 ? void 0 : _c.command)) !== null && _d !== void 0 ? _d : [context.packageManagerInfo.isClassic ? "yarn audit" : "yarn npm audit --environment production" // yarn 2
]), false),
allow_failure: true
}), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_e = buildConfig.audit) === null || _e === void 0 ? void 0 : _e.artifactsReports, (_f = buildConfig.audit) === null || _f === void 0 ? void 0 : _f.artifacts)) : null;
var lintJob = buildConfig.lint !== false ? __assign(__assign(__assign({
name: "๐ฎ lint"
}, base), {
image: (_h = (_g = buildConfig.lint) === null || _g === void 0 ? void 0 : _g.jobImage) !== null && _h !== void 0 ? _h : defaultImage,
cache: (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, (0, cache_1.getNodeCache)(context)),
script: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((0, yarn_1.ensureNodeVersion)(context)), false), ["cd ".concat(context.build.dir)], false), __read(yarnInstall), false), __read((_k = (0, utils_1.ensureArrayOrNull)((_j = buildConfig.lint) === null || _j === void 0 ? void 0 : _j.command)) !== null && _k !== void 0 ? _k : ["yarn lint"]), false)
}), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_l = buildConfig.lint) === null || _l === void 0 ? void 0 : _l.artifactsReports, (_m = buildConfig.lint) === null || _m === void 0 ? void 0 : _m.artifacts)) : null;
var testJob = buildConfig.test !== false ? __assign(__assign(__assign({
name: "๐งช test"
}, base), {
image: (_p = (_o = buildConfig.test) === null || _o === void 0 ? void 0 : _o.jobImage) !== null && _p !== void 0 ? _p : (0, runner_1.getRunnerImage)("jobs-testing-chrome"),
cache: (0, createJobCache_1.createJobCacheFromCacheConfigs)(context, (0, cache_1.getNodeCache)(context)),
script: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read((0, yarn_1.ensureNodeVersion)(context)), false), ["cd ".concat(context.build.dir)], false), __read(yarnInstall), false), __read((_r = (0, utils_1.ensureArrayOrNull)((_q = buildConfig.test) === null || _q === void 0 ? void 0 : _q.command)) !== null && _r !== void 0 ? _r : ["yarn test"]), false)
}), (0, createArtifactsConfig_1.createArtifactsConfig)(context.build.dir, (_s = buildConfig.test) === null || _s === void 0 ? void 0 : _s.artifactsReports, (_t = buildConfig.test) === null || _t === void 0 ? void 0 : _t.artifacts)) : null;
return [auditJob, lintJob, testJob].filter(utils_1.notNil);
};
exports.createNodeTestJobs = createNodeTestJobs;