@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
104 lines โข 4.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRailsTestJobs = void 0;
const __1 = require("../..");
const utils_1 = require("../../utils");
const createRailsTestJobs = (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 [];
}
const buildConfig = context.build.config;
const base = {
variables: {
...context.environment.jobOnlyVars.build.envVars,
},
stage: "test",
needs: [],
};
const defaultImage = "docker.io/ruby";
const bundlerCacheDir = "tmp/cache";
const bundlerInstall = [
`bundle config set path '${bundlerCacheDir}'`,
"bundle install -j $(nproc)",
];
const 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],
};
const auditJob = buildConfig.audit !== false
? {
name: "๐ก audit",
...base,
cache: undefined, // audit does not need bundle install and no cache
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: [
`cd ${context.build.dir}`,
...((_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",
]),
],
allow_failure: true,
}
: null;
const lintJob = buildConfig.lint !== false
? {
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: [
`cd ${context.build.dir}`,
...bundlerInstall,
...((_k = (0, utils_1.ensureArrayOrNull)((_j = buildConfig.lint) === null || _j === void 0 ? void 0 : _j.command)) !== null && _k !== void 0 ? _k : [
"bundle exec rubocop",
]),
],
}
: null;
const testJob = buildConfig.test !== false
? {
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: [
`cd ${context.build.dir}`,
...bundlerInstall,
...((_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",
]),
],
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;
//# sourceMappingURL=testJob.js.map