@catladder/pipeline 0.0.3 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scripts/createSamplePipeline.d.ts +2 -0
- package/dist/scripts/createSamplePipeline.js +14 -0
- package/dist/scripts/magic/build/docker.d.ts +2 -0
- package/dist/scripts/magic/build/docker.js +68 -0
- package/dist/scripts/magic/build/index.d.ts +9 -0
- package/dist/scripts/magic/build/index.js +12 -0
- package/dist/scripts/magic/build/node.d.ts +6 -0
- package/dist/scripts/magic/build/node.js +150 -0
- package/dist/scripts/magic/build/types.d.ts +18 -0
- package/dist/scripts/magic/build/types.js +7 -0
- package/dist/scripts/magic/context/index.d.ts +3 -0
- package/dist/scripts/magic/context/index.js +122 -0
- package/dist/scripts/magic/createChildPipeline/index.d.ts +3 -0
- package/dist/scripts/magic/createChildPipeline/index.js +68 -0
- package/dist/scripts/magic/createPipeline.d.ts +14 -0
- package/dist/scripts/magic/createPipeline.js +80 -0
- package/dist/scripts/magic/deploy/index.d.ts +9 -0
- package/dist/scripts/magic/deploy/index.js +12 -0
- package/dist/scripts/magic/deploy/kubernetes.d.ts +5 -0
- package/dist/scripts/magic/deploy/kubernetes.js +62 -0
- package/dist/scripts/magic/deploy/types.d.ts +41 -0
- package/dist/scripts/magic/deploy/types.js +7 -0
- package/dist/scripts/magic/index.d.ts +2 -0
- package/dist/scripts/magic/sample-config.d.ts +3 -0
- package/dist/scripts/magic/sample-config.js +77 -0
- package/dist/scripts/magic/tests/createPipeline.test.d.ts +1 -0
- package/dist/scripts/magic/tests/createPipeline.test.js +89 -0
- package/dist/scripts/magic/types/config.d.ts +49 -0
- package/dist/scripts/magic/types/config.js +17 -0
- package/dist/scripts/magic/types/context.d.ts +19 -0
- package/dist/scripts/magic/types/context.js +2 -0
- package/dist/scripts/magic/types/gitlab-types.d.ts +57 -0
- package/dist/scripts/magic/types/gitlab-types.js +2 -0
- package/dist/scripts/magic/types/index.d.ts +3 -0
- package/dist/scripts/magic/types/index.js +15 -0
- package/dist/scripts/magic.d.ts +2 -0
- package/dist/scripts/magic.js +43 -0
- package/dist/scripts/monorepoGenerate.d.ts +2 -0
- package/dist/scripts/monorepoGenerate.js +164 -0
- package/dist/scripts/printAllValues.d.ts +2 -0
- package/dist/scripts/printAllValues.js +58 -0
- package/dist/scripts/printBuildEnv.d.ts +2 -0
- package/dist/scripts/printBuildEnv.js +77 -0
- package/dist/scripts/utils/extractAllValues.d.ts +1 -0
- package/dist/scripts/utils/extractAllValues.js +78 -0
- package/dist/scripts/utils/extractBuildEnv.d.ts +5 -0
- package/dist/scripts/utils/extractBuildEnv.js +152 -0
- package/dist/scripts/utils/extractValuesFromEnvVars.d.ts +2 -0
- package/dist/scripts/utils/extractValuesFromEnvVars.js +63 -0
- package/dist/scripts/utils/extractValuesFromMr.d.ts +2 -0
- package/dist/scripts/utils/extractValuesFromMr.js +86 -0
- package/dist/tests/extractValuesFromMr.test.d.ts +1 -0
- package/dist/tests/extractValuesFromMr.test.js +68 -0
- package/package.json +3 -2
- package/scripts/magic/build/docker.ts +2 -2
- package/scripts/magic/build/index.ts +3 -1
- package/scripts/magic/build/node.ts +26 -13
- package/scripts/magic/build/types.ts +6 -2
- package/scripts/magic/context/index.ts +127 -0
- package/scripts/magic/createChildPipeline/index.ts +5 -121
- package/scripts/magic/tests/createPipeline.test.ts +7 -7
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
exports.__esModule = true;
|
|
14
|
+
exports.getKubernetesDefault = exports.createKubernetesDeployJobs = void 0;
|
|
15
|
+
var types_1 = require("./types");
|
|
16
|
+
var createKubernetesDeployJobs = function (context) {
|
|
17
|
+
var deployConfig = context.componentConfig.deploy;
|
|
18
|
+
if (!types_1.isOfType(deployConfig, "kubernetes")) {
|
|
19
|
+
// should not happen
|
|
20
|
+
throw new Error("deploy config is not kubernetes");
|
|
21
|
+
}
|
|
22
|
+
var defaltKubeValues = {
|
|
23
|
+
application: {
|
|
24
|
+
hostname: context.environment.hostname,
|
|
25
|
+
command: context.componentConfig.build.startCommand
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var kubeValues = __assign(__assign({}, defaltKubeValues), deployConfig.values); // TODO: merge with some defaults
|
|
29
|
+
return [
|
|
30
|
+
{
|
|
31
|
+
name: "deploy-to-kubernetes",
|
|
32
|
+
job: {
|
|
33
|
+
variables: __assign(__assign({}, context.environment.variables), {
|
|
34
|
+
// TODO: refactor and unify with other stages
|
|
35
|
+
HELM_EXPERIMENTAL_OCI: "1", IMAGE_PULL_SECRET: "gitlab-registry-" + context.componentName, KUBE_VALUES: JSON.stringify(kubeValues), HELM_GITLAB_CHART_PATH: "catladder/helm-charts", HELM_GITLAB_CHART_NAME: "the-panter-chart", COMPONENT_NAME: context.componentName,
|
|
36
|
+
// TODO: unify with docker build stage
|
|
37
|
+
IMAGE_TAG: "$CI_COMMIT_SHA", HELM_GITLAB_CHART_VERSION: "3.2.0", RELEASE_NAME: context.fullConfig.customerName + "-" + context.fullConfig.appName + "-$CI_ENVIRONMENT_SLUG" }),
|
|
38
|
+
stage: "deploy",
|
|
39
|
+
dependencies: [],
|
|
40
|
+
script: [
|
|
41
|
+
"kubernetesEnsureNamespace",
|
|
42
|
+
"kubernetesCreateSecret",
|
|
43
|
+
"kubernetesDeploy",
|
|
44
|
+
],
|
|
45
|
+
environment: {
|
|
46
|
+
name: context.environment.fullName,
|
|
47
|
+
url: context.environment.url,
|
|
48
|
+
kubernetes: {
|
|
49
|
+
namespace: context.environment.variables.KUBE_NAMESPACE
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
};
|
|
56
|
+
exports.createKubernetesDeployJobs = createKubernetesDeployJobs;
|
|
57
|
+
var getKubernetesDefault = function () {
|
|
58
|
+
return {
|
|
59
|
+
values: {}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
exports.getKubernetesDefault = getKubernetesDefault;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare type DeployConfigBase = {};
|
|
2
|
+
export declare type DeployConfigKubernetes = {
|
|
3
|
+
type: "kubernetes";
|
|
4
|
+
additionalHelmArgs?: string[];
|
|
5
|
+
values?: {
|
|
6
|
+
application?: {
|
|
7
|
+
resources?: {
|
|
8
|
+
limits?: {
|
|
9
|
+
cpu?: any;
|
|
10
|
+
};
|
|
11
|
+
requests?: {
|
|
12
|
+
cpu?: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
} & Record<string, any>;
|
|
16
|
+
} & Record<string, any>;
|
|
17
|
+
} & DeployConfigBase;
|
|
18
|
+
export declare type DeployConfigServerless = {
|
|
19
|
+
type: "serverless";
|
|
20
|
+
};
|
|
21
|
+
export declare type DeployConfig = DeployConfigKubernetes | DeployConfigServerless;
|
|
22
|
+
export declare const isOfType: <T extends "kubernetes" | "serverless">(t: DeployConfig, type: T) => t is Extract<{
|
|
23
|
+
type: "kubernetes";
|
|
24
|
+
additionalHelmArgs?: string[] | undefined;
|
|
25
|
+
values?: ({
|
|
26
|
+
application?: ({
|
|
27
|
+
resources?: {
|
|
28
|
+
limits?: {
|
|
29
|
+
cpu?: any;
|
|
30
|
+
} | undefined;
|
|
31
|
+
requests?: {
|
|
32
|
+
cpu?: any;
|
|
33
|
+
} | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
} & Record<string, any>) | undefined;
|
|
36
|
+
} & Record<string, any>) | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
type: T;
|
|
39
|
+
}> | Extract<DeployConfigServerless, {
|
|
40
|
+
type: T;
|
|
41
|
+
}>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
var sampleConfig = {
|
|
4
|
+
customerName: "pan",
|
|
5
|
+
appName: "fonsi",
|
|
6
|
+
components: {
|
|
7
|
+
web: {
|
|
8
|
+
dir: "web",
|
|
9
|
+
build: {
|
|
10
|
+
type: "node"
|
|
11
|
+
},
|
|
12
|
+
deploy: {
|
|
13
|
+
type: "kubernetes",
|
|
14
|
+
values: {
|
|
15
|
+
application: {
|
|
16
|
+
resources: {
|
|
17
|
+
limits: {
|
|
18
|
+
cpu: "100m"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
vars: {
|
|
25
|
+
public: {
|
|
26
|
+
GOOGLE_TAG_MANAGER_ID: "1234"
|
|
27
|
+
},
|
|
28
|
+
fromComponents: {
|
|
29
|
+
api: {
|
|
30
|
+
API_URL: "ROOT_URL"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
env: {
|
|
35
|
+
prod: {
|
|
36
|
+
hostname: "fudilo.ch",
|
|
37
|
+
vars: {},
|
|
38
|
+
deploy: {
|
|
39
|
+
type: "kubernetes",
|
|
40
|
+
values: {
|
|
41
|
+
application: {
|
|
42
|
+
resources: {
|
|
43
|
+
limits: {
|
|
44
|
+
cpu: "1000m"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
myCustomProd: {
|
|
52
|
+
type: "prod",
|
|
53
|
+
hostname: "fudilo2.ch"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
api: {
|
|
58
|
+
env: {
|
|
59
|
+
prod: {
|
|
60
|
+
hostname: "api.fudilo.ch"
|
|
61
|
+
},
|
|
62
|
+
myCustomProd: {
|
|
63
|
+
type: "prod",
|
|
64
|
+
hostname: "api.fudilo2.ch"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
build: {
|
|
68
|
+
type: "node"
|
|
69
|
+
},
|
|
70
|
+
deploy: {
|
|
71
|
+
type: "kubernetes"
|
|
72
|
+
},
|
|
73
|
+
dir: "api"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
exports["default"] = sampleConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
39
|
+
var t = {};
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
41
|
+
t[p] = s[p];
|
|
42
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
43
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
44
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
45
|
+
t[p[i]] = s[p[i]];
|
|
46
|
+
}
|
|
47
|
+
return t;
|
|
48
|
+
};
|
|
49
|
+
exports.__esModule = true;
|
|
50
|
+
var createPipeline_1 = require("../createPipeline");
|
|
51
|
+
describe("createPipeline", function () {
|
|
52
|
+
describe("node-app to kuberntes", function () {
|
|
53
|
+
var config = {
|
|
54
|
+
appName: "test",
|
|
55
|
+
customerName: "pan",
|
|
56
|
+
components: {
|
|
57
|
+
"my-app": {
|
|
58
|
+
dir: "myapp",
|
|
59
|
+
build: {
|
|
60
|
+
type: "node"
|
|
61
|
+
},
|
|
62
|
+
deploy: {
|
|
63
|
+
type: "kubernetes"
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
it("creates a pipeline for a single app on the main branch", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
+
var _a, image, stages, workflow, jobs;
|
|
70
|
+
return __generator(this, function (_b) {
|
|
71
|
+
switch (_b.label) {
|
|
72
|
+
case 0: return [4 /*yield*/, createPipeline_1.createPipeline("mainBranch", config)];
|
|
73
|
+
case 1:
|
|
74
|
+
_a = _b.sent(), image = _a.image, stages = _a.stages, workflow = _a.workflow, jobs = __rest(_a, ["image", "stages", "workflow"]);
|
|
75
|
+
expect(image).toEqual("git.panter.ch:5001/catladder/gitlab-ci/pipeline:$PIPELINE_IMAGE_TAG");
|
|
76
|
+
expect(Object.keys(jobs)).toEqual([
|
|
77
|
+
"my-app audit",
|
|
78
|
+
"my-app lint",
|
|
79
|
+
"my-app test",
|
|
80
|
+
"dev my-app app-build",
|
|
81
|
+
"dev my-app docker-build",
|
|
82
|
+
"dev my-app deploy-to-kubernetes",
|
|
83
|
+
]);
|
|
84
|
+
return [2 /*return*/];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}); });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BuildConfig } from "../build/types";
|
|
2
|
+
import { DeployConfig } from "../deploy/types";
|
|
3
|
+
export declare type PipelineTrigger = "mainBranch" | "mr" | "taggedRelease";
|
|
4
|
+
export declare const ENV_TYPES: {
|
|
5
|
+
readonly dev: {
|
|
6
|
+
readonly trigger: "mainBranch";
|
|
7
|
+
};
|
|
8
|
+
readonly review: {
|
|
9
|
+
readonly trigger: "mr";
|
|
10
|
+
};
|
|
11
|
+
readonly prod: {
|
|
12
|
+
readonly trigger: "taggedRelease";
|
|
13
|
+
};
|
|
14
|
+
readonly stage: {
|
|
15
|
+
readonly trigger: "taggedRelease";
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
declare type EnvType = keyof typeof ENV_TYPES;
|
|
19
|
+
export declare type DefaultEnvConfig = {
|
|
20
|
+
deploy: DeployConfig;
|
|
21
|
+
build: BuildConfig;
|
|
22
|
+
vars?: {
|
|
23
|
+
public?: Record<string, any>;
|
|
24
|
+
secret?: Record<string, string>;
|
|
25
|
+
fromComponents?: {
|
|
26
|
+
[otherApp: string]: Record<string, string>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
declare type EnvConfig<E extends EnvType = EnvType> = {
|
|
31
|
+
type?: E;
|
|
32
|
+
hostname?: string;
|
|
33
|
+
} & Partial<DefaultEnvConfig>;
|
|
34
|
+
export declare type Env = {
|
|
35
|
+
dev?: EnvConfig<"dev">;
|
|
36
|
+
stage?: EnvConfig<"stage">;
|
|
37
|
+
review?: EnvConfig<"review">;
|
|
38
|
+
prod?: EnvConfig<"prod">;
|
|
39
|
+
} & Record<string, EnvConfig>;
|
|
40
|
+
export declare type ComponentConfig = {
|
|
41
|
+
env?: Env;
|
|
42
|
+
dir: string;
|
|
43
|
+
} & DefaultEnvConfig;
|
|
44
|
+
export declare type Config = {
|
|
45
|
+
customerName: string;
|
|
46
|
+
appName: string;
|
|
47
|
+
components: Record<string, ComponentConfig>;
|
|
48
|
+
};
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.ENV_TYPES = void 0;
|
|
4
|
+
exports.ENV_TYPES = {
|
|
5
|
+
dev: {
|
|
6
|
+
trigger: "mainBranch"
|
|
7
|
+
},
|
|
8
|
+
review: {
|
|
9
|
+
trigger: "mr"
|
|
10
|
+
},
|
|
11
|
+
prod: {
|
|
12
|
+
trigger: "taggedRelease"
|
|
13
|
+
},
|
|
14
|
+
stage: {
|
|
15
|
+
trigger: "taggedRelease"
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComponentConfig, Config } from "./config";
|
|
2
|
+
export declare type Environment = {
|
|
3
|
+
hostname: string;
|
|
4
|
+
fullName: string;
|
|
5
|
+
shortName: string;
|
|
6
|
+
url: string;
|
|
7
|
+
variables: Record<string, string>;
|
|
8
|
+
};
|
|
9
|
+
export declare type CommitInfo = {
|
|
10
|
+
refName: string;
|
|
11
|
+
refSlug: string;
|
|
12
|
+
};
|
|
13
|
+
export declare type Context = {
|
|
14
|
+
componentConfig: ComponentConfig;
|
|
15
|
+
componentName: string;
|
|
16
|
+
fullConfig: Config;
|
|
17
|
+
environment: Environment;
|
|
18
|
+
commit: CommitInfo;
|
|
19
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare type GitlabStage = "setup" | "test" | "build" | "deploy" | "verify" | "actions";
|
|
2
|
+
export declare type Artifacts = {
|
|
3
|
+
paths: string[];
|
|
4
|
+
};
|
|
5
|
+
export declare type GitlabJobCache = {
|
|
6
|
+
key: string;
|
|
7
|
+
policy?: string;
|
|
8
|
+
paths: string[];
|
|
9
|
+
};
|
|
10
|
+
export declare type GitlabRule = {
|
|
11
|
+
if: string;
|
|
12
|
+
when?: "always" | "on_success" | "manual" | "never";
|
|
13
|
+
};
|
|
14
|
+
export declare type Retry = {
|
|
15
|
+
max: number;
|
|
16
|
+
when: string[];
|
|
17
|
+
};
|
|
18
|
+
export declare type Service = {
|
|
19
|
+
name: string;
|
|
20
|
+
command: string[];
|
|
21
|
+
};
|
|
22
|
+
export declare type GitlabEnvironment = {
|
|
23
|
+
url: string;
|
|
24
|
+
name: string;
|
|
25
|
+
kubernetes?: {
|
|
26
|
+
namespace?: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export declare type GitlabJobDef = {
|
|
30
|
+
stage: GitlabStage;
|
|
31
|
+
before_script?: string[];
|
|
32
|
+
script: string[];
|
|
33
|
+
interruptible?: boolean;
|
|
34
|
+
needs?: string[];
|
|
35
|
+
rules?: GitlabRule[];
|
|
36
|
+
cache?: GitlabJobCache | GitlabJobCache[];
|
|
37
|
+
artifacts?: Artifacts;
|
|
38
|
+
retry?: Retry;
|
|
39
|
+
services?: Service[];
|
|
40
|
+
image?: string;
|
|
41
|
+
variables?: GitlabVariables;
|
|
42
|
+
dependencies?: string[];
|
|
43
|
+
environment?: GitlabEnvironment;
|
|
44
|
+
allow_failure?: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare type GitlabVariables = Record<string, string | undefined>;
|
|
47
|
+
export declare type GitlabJob = {
|
|
48
|
+
name: string;
|
|
49
|
+
perEnv?: boolean;
|
|
50
|
+
job: GitlabJobDef;
|
|
51
|
+
};
|
|
52
|
+
export declare type GitlabJobs = GitlabJob[];
|
|
53
|
+
export declare type GitlabPipeline = {
|
|
54
|
+
variables: GitlabVariables;
|
|
55
|
+
stages: GitlabStage[];
|
|
56
|
+
jobs: GitlabJobs;
|
|
57
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
exports.__esModule = true;
|
|
13
|
+
__exportStar(require("./config"), exports);
|
|
14
|
+
__exportStar(require("./gitlab-types"), exports);
|
|
15
|
+
__exportStar(require("./context"), exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
"use strict";
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
var fs_1 = require("fs");
|
|
5
|
+
var yaml_1 = require("yaml");
|
|
6
|
+
var createPipeline_1 = require("./magic/createPipeline");
|
|
7
|
+
var _a = process.env, CI_MERGE_REQUEST_ID = _a.CI_MERGE_REQUEST_ID, CI_COMMIT_TAG = _a.CI_COMMIT_TAG, CI_COMMIT_BRANCH = _a.CI_COMMIT_BRANCH, CI_DEFAULT_BRANCH = _a.CI_DEFAULT_BRANCH;
|
|
8
|
+
var isDefaultBranch = CI_COMMIT_BRANCH == CI_DEFAULT_BRANCH;
|
|
9
|
+
var isHotfixBranch = false; // TODO: $CI_COMMIT_BRANCH =~ /^[0-9]+\.([0-9]+|x)\.x$/
|
|
10
|
+
var isMergeRequest = Boolean(CI_MERGE_REQUEST_ID);
|
|
11
|
+
var isTaggedRelease = Boolean(CI_COMMIT_TAG);
|
|
12
|
+
var fullPath = function (ext) { return process.cwd() + "/catladder." + ext; };
|
|
13
|
+
var readConfig = function () {
|
|
14
|
+
var found = ["ts", "js", "yml", "yaml"].find(function (extension) {
|
|
15
|
+
return fs_1.existsSync(fullPath(extension));
|
|
16
|
+
});
|
|
17
|
+
if (found) {
|
|
18
|
+
if (found === "ts" || found === "js") {
|
|
19
|
+
return require(fullPath(found))["default"];
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return yaml_1.parse(fullPath(found));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var trigger = isMergeRequest || isHotfixBranch
|
|
27
|
+
? "mr"
|
|
28
|
+
: isDefaultBranch
|
|
29
|
+
? "mainBranch"
|
|
30
|
+
: isTaggedRelease
|
|
31
|
+
? "taggedRelease"
|
|
32
|
+
: null;
|
|
33
|
+
if (trigger) {
|
|
34
|
+
var config = readConfig();
|
|
35
|
+
createPipeline_1.createPipeline(trigger, config).then(function (mainPipeline) {
|
|
36
|
+
fs_1.writeFileSync("__pipeline.yml", JSON.stringify(mainPipeline, null, 2), {
|
|
37
|
+
encoding: "utf-8"
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error("no matching trigger");
|
|
43
|
+
}
|