@catladder/cli
Version:
Panter cli tool for cloud CI/CD and DevOps
76 lines (75 loc) โข 4 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, _t, _u, _v, _w;
// 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: (_g = (_f = buildConfig.audit) === null || _f === void 0 ? void 0 : _f.allowFailure) !== null && _g !== void 0 ? _g : true
} : null;
const lintJob = buildConfig.lint !== false ? {
name: "๐ฎ lint",
...base,
cache: bundlerCache,
image: (_k = (_j = (_h = buildConfig.lint) === null || _h === void 0 ? void 0 : _h.jobImage) !== null && _j !== void 0 ? _j : buildConfig.jobImage) !== null && _k !== void 0 ? _k : defaultImage,
script: [`cd ${context.build.dir}`, ...bundlerInstall, ...((_m = (0, utils_1.ensureArrayOrNull)((_l = buildConfig.lint) === null || _l === void 0 ? void 0 : _l.command)) !== null && _m !== void 0 ? _m : ["bundle exec rubocop"])],
allow_failure: (_o = buildConfig.lint) === null || _o === void 0 ? void 0 : _o.allowFailure
} : null;
const testJob = buildConfig.test !== false ? {
name: "๐งช test",
...base,
cache: bundlerCache,
image: (_r = (_q = (_p = buildConfig.test) === null || _p === void 0 ? void 0 : _p.jobImage) !== null && _q !== void 0 ? _q : buildConfig.jobImage) !== null && _r !== void 0 ? _r : defaultImage,
script: [`cd ${context.build.dir}`, ...bundlerInstall, ...((_t = (0, utils_1.ensureArrayOrNull)((_s = buildConfig.test) === null || _s === void 0 ? void 0 : _s.command)) !== null && _t !== void 0 ? _t : ["bundle exec rake db:test:prepare", "bundle exec rake assets:precompile assets:clean", "bundle exec rspec"])],
allow_failure: (_u = buildConfig.test) === null || _u === void 0 ? void 0 : _u.allowFailure,
runnerVariables: {
RAILS_ENV: "test",
DATABASE_URL: "postgresql://postgres@database"
},
services: [{
name: buildConfig.test && "databaseImage" in buildConfig.test ? (_w = (_v = buildConfig === null || buildConfig === void 0 ? void 0 : buildConfig.test) === null || _v === void 0 ? void 0 : _v.databaseImage) !== null && _w !== void 0 ? _w : "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;