@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
112 lines (111 loc) โข 4.98 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.createRailsTestJobs = void 0;
var __1 = require("../..");
var utils_1 = require("../../utils");
var createRailsTestJobs = function (context) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
// 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 (!(0, __1.componentContextIsStandaloneBuild)(context)) {
return [];
}
var buildConfig = context.build.config;
var base = {
variables: __assign({}, context.environment.jobOnlyVars.build.envVars),
stage: "test",
needs: []
};
var defaultImage = "docker.io/ruby";
var bundlerCacheDir = "tmp/cache";
var bundlerInstall = ["bundle config set path '".concat(bundlerCacheDir, "'"), "bundle install -j $(nproc)"];
var bundlerCache = {
key: {
files: ["Gemfile.lock"],
prefix: "$CI_JOB_IMAGE" // a changed image might have different OS libraries which no longer work with the cached gems
},
paths: [bundlerCacheDir]
};
var auditJob = buildConfig.audit !== false ? __assign(__assign({
name: "๐ก audit"
}, base), {
cache: undefined,
image: (_c = (_b = (_a = buildConfig.audit) === null || _a === void 0 ? void 0 : _a.jobImage) !== null && _b !== void 0 ? _b : buildConfig.jobImage) !== null && _c !== void 0 ? _c : defaultImage,
script: __spreadArray(["cd ".concat(context.build.dir)], __read((_e = (0, utils_1.ensureArrayOrNull)((_d = buildConfig.audit) === null || _d === void 0 ? void 0 : _d.command)) !== null && _e !== void 0 ? _e : ["gem install bundler-audit", "bundle audit check"]), false),
allow_failure: true
}) : null;
var lintJob = buildConfig.lint !== false ? __assign(__assign({
name: "๐ฎ lint"
}, base), {
cache: bundlerCache,
image: (_h = (_g = (_f = buildConfig.lint) === null || _f === void 0 ? void 0 : _f.jobImage) !== null && _g !== void 0 ? _g : buildConfig.jobImage) !== null && _h !== void 0 ? _h : defaultImage,
script: __spreadArray(__spreadArray(["cd ".concat(context.build.dir)], __read(bundlerInstall), false), __read((_k = (0, utils_1.ensureArrayOrNull)((_j = buildConfig.lint) === null || _j === void 0 ? void 0 : _j.command)) !== null && _k !== void 0 ? _k : ["bundle exec rubocop"]), false)
}) : null;
var testJob = buildConfig.test !== false ? __assign(__assign({
name: "๐งช test"
}, base), {
cache: bundlerCache,
image: (_o = (_m = (_l = buildConfig.test) === null || _l === void 0 ? void 0 : _l.jobImage) !== null && _m !== void 0 ? _m : buildConfig.jobImage) !== null && _o !== void 0 ? _o : defaultImage,
script: __spreadArray(__spreadArray(["cd ".concat(context.build.dir)], __read(bundlerInstall), false), __read((_q = (0, utils_1.ensureArrayOrNull)((_p = buildConfig.test) === null || _p === void 0 ? void 0 : _p.command)) !== null && _q !== void 0 ? _q : ["bundle exec rake db:test:prepare", "bundle exec rake assets:precompile assets:clean", "bundle exec rspec"]), false),
runnerVariables: {
RAILS_ENV: "test",
DATABASE_URL: "postgresql://postgres@database"
},
services: [{
name: buildConfig.test && "databaseImage" in buildConfig.test ? (_s = (_r = buildConfig === null || buildConfig === void 0 ? void 0 : buildConfig.test) === null || _r === void 0 ? void 0 : _r.databaseImage) !== null && _s !== void 0 ? _s : "docker.io/postgres:latest" : "docker.io/postgres:latest",
alias: "database",
variables: {
POSTGRES_HOST_AUTH_METHOD: "trust"
}
}]
}) : null;
return [auditJob, lintJob, testJob].filter(utils_1.notNil);
};
exports.createRailsTestJobs = createRailsTestJobs;