@catladder/pipeline 1.75.4 → 1.76.0
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/build/base/createBuildJob.js +5 -27
- package/dist/build/base/writeBuildInfo.js +0 -3
- package/dist/build/custom/buildJob.js +3 -23
- package/dist/build/custom/index.js +3 -10
- package/dist/build/docker.js +5 -40
- package/dist/build/index.js +0 -8
- package/dist/build/node/buildJob.js +3 -25
- package/dist/build/node/cache.js +3 -21
- package/dist/build/node/index.js +3 -16
- package/dist/build/node/meteor.js +3 -20
- package/dist/build/node/testJob.js +5 -22
- package/dist/build/node/yarn.js +5 -18
- package/dist/build/rails/build.js +2 -8
- package/dist/build/rails/index.js +3 -11
- package/dist/build/rails/test.js +5 -18
- package/dist/build/types.d.ts +0 -9
- package/dist/build/types.js +0 -4
- package/dist/bundles/catladder-gitlab/index.js +1 -1
- package/dist/catladder-gitlab.js +6 -24
- package/dist/config/{configruedEnvs.test.d.ts → __tests__/configruedEnvs.test.d.ts} +0 -0
- package/dist/config/{configruedEnvs.test.js → __tests__/configruedEnvs.test.js} +10 -12
- package/dist/config/configruedEnvs.js +7 -22
- package/dist/config/index.js +0 -4
- package/dist/config/readConfig.js +2 -13
- package/dist/constants.js +1 -1
- package/dist/context/{resolveReferences.test.d.ts → __tests__/resolveReferences.test.d.ts} +0 -0
- package/dist/context/{resolveReferences.test.js → __tests__/resolveReferences.test.js} +52 -103
- package/dist/context/getEnvConfig.js +0 -8
- package/dist/context/getEnvType.js +0 -5
- package/dist/context/getEnvironment.js +13 -49
- package/dist/context/getEnvironmentContext.js +0 -5
- package/dist/context/getEnvironmentVariables.js +20 -83
- package/dist/context/getLabels.js +2 -13
- package/dist/context/index.js +13 -58
- package/dist/context/resolveReferences.js +36 -126
- package/dist/deploy/base.js +4 -19
- package/dist/deploy/cloudRun/deployJob.js +19 -61
- package/dist/deploy/cloudRun/index.js +17 -39
- package/dist/deploy/cloudRun/utils/database.js +11 -29
- package/dist/deploy/cloudRun/utils/gcloudServiceAccountLoginCommands.js +0 -4
- package/dist/deploy/cloudRun/utils/jobName.js +0 -2
- package/dist/deploy/custom/deployJob.js +3 -18
- package/dist/deploy/custom/index.js +0 -2
- package/dist/deploy/dockerTag/deployJob.js +0 -9
- package/dist/deploy/dockerTag/index.js +0 -2
- package/dist/deploy/index.js +0 -11
- package/dist/deploy/kubernetes/additionalSecretKeys.js +0 -9
- package/dist/deploy/kubernetes/cloudSql/index.js +0 -12
- package/dist/deploy/kubernetes/deployJob.js +3 -24
- package/dist/deploy/kubernetes/index.js +7 -17
- package/dist/deploy/kubernetes/kubeEnv.d.ts +0 -1
- package/dist/deploy/kubernetes/kubeEnv.js +5 -23
- package/dist/deploy/kubernetes/kubeValues.js +6 -24
- package/dist/deploy/kubernetes/mongodb.js +0 -24
- package/dist/deploy/kubernetes/processSecretsAsFiles.js +2 -10
- package/dist/deploy/types/base.d.ts +0 -1
- package/dist/deploy/types/custom.d.ts +0 -6
- package/dist/deploy/types/googleCloudRun.d.ts +4 -12
- package/dist/deploy/types/index.js +0 -10
- package/dist/deploy/types/kubernetes.d.ts +0 -28
- package/dist/deploy/utils.js +0 -11
- package/dist/index.js +0 -10
- package/dist/pipeline/commitInfo/getBuildId.d.ts +1 -0
- package/dist/pipeline/{createChildPipeline.test.js → commitInfo/getBuildId.js} +25 -84
- package/dist/pipeline/commitInfo/getCommitInfo.d.ts +2 -0
- package/dist/{build/tests/storybook.test.js → pipeline/commitInfo/getCommitInfo.js} +30 -104
- package/dist/pipeline/createChildPipeline.js +19 -76
- package/dist/pipeline/createJobs.js +35 -135
- package/dist/pipeline/gitlab/makeGitlabJob.d.ts +1 -0
- package/dist/pipeline/gitlab/makeGitlabJob.js +13 -15
- package/dist/pipeline/index.js +0 -4
- package/dist/pipeline/packageManager.js +20 -173
- package/dist/pipeline/yarn/yarnUtils.d.ts +4 -0
- package/dist/pipeline/yarn/yarnUtils.js +193 -0
- package/dist/runner/index.js +0 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/config.d.ts +0 -13
- package/dist/types/config.js +5 -15
- package/dist/types/context.d.ts +0 -2
- package/dist/types/environmentContext.d.ts +0 -1
- package/dist/types/gitlab-types.d.ts +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/jobs.d.ts +5 -15
- package/dist/utils/gitlab.js +3 -13
- package/dist/utils/index.js +5 -15
- package/examples/__snapshots__/cloud-run-with-sql.ts.snap +1765 -0
- package/examples/__snapshots__/custom-build-job.ts.snap +1174 -0
- package/examples/__snapshots__/custom-envs.ts.snap +261 -0
- package/examples/__snapshots__/wait-for-other-deploy.ts.snap +1626 -0
- package/examples/__utils__/helpers.ts +14 -0
- package/examples/{cloud-sql.ts → cloud-run-with-sql.ts} +12 -15
- package/examples/custom-build-job.ts +4 -1
- package/examples/custom-envs.ts +31 -0
- package/examples/wait-for-other-deploy.ts +36 -0
- package/package.json +2 -2
- package/src/config/{configruedEnvs.test.ts → __tests__/configruedEnvs.test.ts} +3 -3
- package/src/context/{resolveReferences.test.ts → __tests__/resolveReferences.test.ts} +3 -3
- package/src/deploy/cloudRun/index.ts +2 -1
- package/src/deploy/types/googleCloudRun.ts +5 -0
- package/src/pipeline/commitInfo/getBuildId.ts +6 -0
- package/src/pipeline/commitInfo/getCommitInfo.ts +12 -0
- package/src/pipeline/createChildPipeline.ts +6 -1
- package/src/pipeline/createJobs.ts +3 -10
- package/src/pipeline/gitlab/makeGitlabJob.ts +7 -1
- package/src/pipeline/packageManager.ts +4 -38
- package/src/pipeline/yarn/yarnUtils.ts +37 -0
- package/src/types/jobs.ts +2 -1
- package/tsconfig.json +1 -1
- package/dist/build/tests/storybook.test.d.ts +0 -1
- package/dist/pipeline/createChildPipeline.test.d.ts +0 -1
- package/src/build/tests/storybook.test.ts +0 -54
- package/src/pipeline/createChildPipeline.test.ts +0 -49
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Config } from "../../src";
|
|
2
|
+
import { createChildPipeline } from "../../src";
|
|
3
|
+
|
|
4
|
+
const ALL_TRIGGERS = ["mainBranch", "taggedRelease", "mr"] as const;
|
|
5
|
+
|
|
6
|
+
export const createAllPipelines = async (config: Config) =>
|
|
7
|
+
Object.fromEntries(
|
|
8
|
+
await Promise.all(
|
|
9
|
+
ALL_TRIGGERS.map(async (trigger) => [
|
|
10
|
+
trigger,
|
|
11
|
+
await createChildPipeline("gitlab", trigger, config),
|
|
12
|
+
])
|
|
13
|
+
)
|
|
14
|
+
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Config } from "../src";
|
|
2
|
-
|
|
3
|
-
const config: Config
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
const config: Config = {
|
|
4
4
|
appName: "test-app",
|
|
5
5
|
customerName: "pan",
|
|
6
6
|
components: {
|
|
@@ -11,32 +11,29 @@ const config: Config<{ CustomEnvs: "asdf" | "bla" }> = {
|
|
|
11
11
|
},
|
|
12
12
|
deploy: {
|
|
13
13
|
type: "google-cloudrun",
|
|
14
|
-
projectId: "
|
|
14
|
+
projectId: "google-project-id",
|
|
15
15
|
region: "europe-west6",
|
|
16
16
|
cloudSql: {
|
|
17
17
|
type: "unmanaged",
|
|
18
18
|
instanceConnectionName: "projectId:region:instancename",
|
|
19
|
+
dbUser: "my-user",
|
|
19
20
|
},
|
|
20
21
|
jobs: {
|
|
21
22
|
migration: {
|
|
22
23
|
when: "postDeploy",
|
|
23
24
|
command: "yarn migrate",
|
|
24
25
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
asdf: {
|
|
32
|
-
type: "dev",
|
|
33
|
-
},
|
|
34
|
-
bla: {
|
|
35
|
-
type: "dev",
|
|
26
|
+
["send-reminders"]: {
|
|
27
|
+
when: "schedule",
|
|
28
|
+
command: "yarn job:send-reminders",
|
|
29
|
+
schedule: "0 * * * *",
|
|
30
|
+
},
|
|
36
31
|
},
|
|
37
32
|
},
|
|
38
33
|
},
|
|
39
34
|
},
|
|
40
35
|
};
|
|
41
36
|
|
|
42
|
-
|
|
37
|
+
it("matches snapshot", async () => {
|
|
38
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
39
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
2
3
|
|
|
3
4
|
const config: Config = {
|
|
4
5
|
appName: "test-app",
|
|
@@ -22,4 +23,6 @@ const config: Config = {
|
|
|
22
23
|
},
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
it("matches snapshot", async () => {
|
|
27
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
28
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
const config: Config<{ CustomEnvs: "asdf" | "bla" }> = {
|
|
5
|
+
appName: "test-app",
|
|
6
|
+
customerName: "pan",
|
|
7
|
+
components: {
|
|
8
|
+
api: {
|
|
9
|
+
dir: "api",
|
|
10
|
+
build: {
|
|
11
|
+
type: "node",
|
|
12
|
+
},
|
|
13
|
+
deploy: false,
|
|
14
|
+
env: {
|
|
15
|
+
local: {
|
|
16
|
+
port: 4000,
|
|
17
|
+
},
|
|
18
|
+
asdf: {
|
|
19
|
+
type: "dev",
|
|
20
|
+
},
|
|
21
|
+
bla: {
|
|
22
|
+
type: "dev",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
it("matches snapshot", async () => {
|
|
30
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
31
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Config } from "../src";
|
|
2
|
+
import { createAllPipelines } from "./__utils__/helpers";
|
|
3
|
+
|
|
4
|
+
const config: Config<{ CustomEnvs: "asdf" | "bla" }> = {
|
|
5
|
+
appName: "test-app",
|
|
6
|
+
customerName: "pan",
|
|
7
|
+
components: {
|
|
8
|
+
api: {
|
|
9
|
+
dir: "api",
|
|
10
|
+
build: {
|
|
11
|
+
type: "node",
|
|
12
|
+
},
|
|
13
|
+
deploy: {
|
|
14
|
+
type: "custom",
|
|
15
|
+
requiresDocker: false,
|
|
16
|
+
script: ["yarn deploy"],
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
www: {
|
|
20
|
+
dir: "www",
|
|
21
|
+
build: {
|
|
22
|
+
type: "node",
|
|
23
|
+
},
|
|
24
|
+
deploy: {
|
|
25
|
+
waitFor: ["api"],
|
|
26
|
+
type: "custom",
|
|
27
|
+
requiresDocker: false,
|
|
28
|
+
script: ["yarn deploy"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
it("matches snapshot", async () => {
|
|
35
|
+
expect(await createAllPipelines(config)).toMatchSnapshot();
|
|
36
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catladder/pipeline",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.76.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build:tsc": "yarn tsc",
|
|
6
6
|
"build": "yarn build:compile && yarn build:inline-variables && yarn build:bundle",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"build:compile": "yarn tsc",
|
|
9
9
|
"build:inline-variables": "yarn babel --keep-file-extension --extensions \".ts,.js\" --config-file ./babel-inline.json dist --out-dir dist",
|
|
10
10
|
"build:watch": "yarn tsc -w",
|
|
11
|
-
"test": "jest",
|
|
12
11
|
"lint": "eslint \"src/**/*.ts\"",
|
|
13
12
|
"lint:fix": "eslint \"src/**/*.ts\" --fix"
|
|
14
13
|
},
|
|
@@ -23,6 +22,7 @@
|
|
|
23
22
|
"@babel/core": "^7.0.0-0",
|
|
24
23
|
"@babel/plugin-syntax-typescript": "^7.16.7",
|
|
25
24
|
"@babel/preset-typescript": "^7.16.5",
|
|
25
|
+
"@jest/globals": "^29.3.1",
|
|
26
26
|
"@types/child-process-promise": "^2.2.2",
|
|
27
27
|
"@types/jest": "^27.4.0",
|
|
28
28
|
"@types/lodash": "^4.14.185",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getAllEnvsByTrigger } from "
|
|
2
|
-
import type { DeployConfigKubernetesCluster } from "
|
|
3
|
-
import type { Config } from "
|
|
1
|
+
import { getAllEnvsByTrigger } from "..";
|
|
2
|
+
import type { DeployConfigKubernetesCluster } from "../..";
|
|
3
|
+
import type { Config } from "../../types";
|
|
4
4
|
|
|
5
5
|
describe("getAllEnvsByTrigger", () => {
|
|
6
6
|
const cluster: DeployConfigKubernetesCluster = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveReferences,
|
|
3
3
|
translateLegacyFromComponents,
|
|
4
|
-
} from "
|
|
4
|
+
} from "../resolveReferences";
|
|
5
5
|
|
|
6
6
|
describe("resolveReferences", () => {
|
|
7
7
|
it("replaces occurences of ${componentName:VARIABLE_NAME}", async () => {
|
|
@@ -30,12 +30,12 @@ describe("resolveReferences", () => {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
it("replaces self references with structure ${VARIABLE_NAME}", () => {
|
|
33
|
+
it("replaces self references with structure ${VARIABLE_NAME}", async () => {
|
|
34
34
|
const variables = {
|
|
35
35
|
FOO: "hello world",
|
|
36
36
|
BAR: "this: ${FOO}!",
|
|
37
37
|
};
|
|
38
|
-
const result = resolveReferences(variables);
|
|
38
|
+
const result = await resolveReferences(variables);
|
|
39
39
|
|
|
40
40
|
expect(result).toEqual({
|
|
41
41
|
FOO: "hello world",
|
|
@@ -31,11 +31,12 @@ const getCloudSqlVariables = ({
|
|
|
31
31
|
)
|
|
32
32
|
.map(([key, value]) => `&${key}=${value}`)
|
|
33
33
|
.join("");
|
|
34
|
+
|
|
34
35
|
return {
|
|
35
36
|
CLOUD_SQL_INSTANCE_CONNECTION_NAME:
|
|
36
37
|
deployConfigRaw.cloudSql.instanceConnectionName,
|
|
37
38
|
DB_NAME: DB_NAME,
|
|
38
|
-
DB_USER: "postgres",
|
|
39
|
+
DB_USER: deployConfigRaw.cloudSql.dbUser ?? "postgres",
|
|
39
40
|
DB_PASSWORD: "$" + getSecretVarName(env, componentName, "DB_PASSWORD"),
|
|
40
41
|
DATABASE_URL: `postgresql://$DB_USER:$DB_PASSWORD@localhost/$DB_NAME?host=/cloudsql/$CLOUD_SQL_INSTANCE_CONNECTION_NAME${additionalQueryParamsString}`,
|
|
41
42
|
DATABASE_JDBC_URL: `jdbc:postgresql:///$DB_NAME?cloudSqlInstance=$CLOUD_SQL_INSTANCE_CONNECTION_NAME&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=$DB_USER&password=$DB_PASSWORD${additionalQueryParamsString}`,
|
|
@@ -40,6 +40,11 @@ export type Gcloudregion =
|
|
|
40
40
|
export type DeployConfigCloudRunCloudSql = {
|
|
41
41
|
type: "unmanaged";
|
|
42
42
|
instanceConnectionName: string;
|
|
43
|
+
/**
|
|
44
|
+
* the database username, defaults to "postgres"
|
|
45
|
+
*/
|
|
46
|
+
dbUser?: string;
|
|
47
|
+
|
|
43
48
|
/**
|
|
44
49
|
* the prefix of the database, the full db name is this plus the environment slug
|
|
45
50
|
*
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CommitInfo } from "../../types";
|
|
2
|
+
import { getBuildId } from "./getBuildId";
|
|
3
|
+
export const getBaseCommitInfo = async (): Promise<
|
|
4
|
+
Omit<CommitInfo, "trigger">
|
|
5
|
+
> => ({
|
|
6
|
+
refName: process.env.CI_COMMIT_REF_NAME ?? "unknown",
|
|
7
|
+
reviewSlug: process.env.CI_MERGE_REQUEST_IID
|
|
8
|
+
? `mr${process.env.CI_MERGE_REQUEST_IID}`
|
|
9
|
+
: "unknown",
|
|
10
|
+
buildTime: new Date().toISOString(),
|
|
11
|
+
buildId: await getBuildId(),
|
|
12
|
+
});
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { getAllEnvsByTrigger, getAllEnvsInAllComponents } from "../config";
|
|
2
2
|
import { RULES_ALWAYS } from "../rules";
|
|
3
3
|
import { getRunnerImage } from "../runner";
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
GitlabPipeline,
|
|
6
|
+
Pipeline,
|
|
7
|
+
PipelineJob,
|
|
8
|
+
PipelineType,
|
|
9
|
+
} from "../types";
|
|
5
10
|
import type { Config, PipelineTrigger } from "../types/config";
|
|
6
11
|
import { BASE_STAGES } from "../types/jobs";
|
|
7
12
|
import { createJobs } from "./createJobs";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { exec } from "child-process-promise";
|
|
2
1
|
import { isFunction, isObject } from "lodash";
|
|
3
2
|
import { BUILD_TYPES } from "../build";
|
|
4
3
|
import { createContext } from "../context";
|
|
@@ -6,8 +5,9 @@ import { DEPLOY_TYPES } from "../deploy";
|
|
|
6
5
|
import type { PipelineJob, PipelineType } from "../types";
|
|
7
6
|
import type { Config, PipelineTrigger } from "../types/config";
|
|
8
7
|
import type { CommitInfo, Context } from "../types/context";
|
|
9
|
-
import type { CatladderJob } from "../types/jobs";
|
|
8
|
+
import type { CatladderJob, CatladderJobNeed } from "../types/jobs";
|
|
10
9
|
import { notNil } from "../utils";
|
|
10
|
+
import { getBaseCommitInfo } from "./commitInfo/getCommitInfo";
|
|
11
11
|
import { makeGitlabJob } from "./gitlab/makeGitlabJob";
|
|
12
12
|
import { getPackageManagerInfo } from "./packageManager";
|
|
13
13
|
|
|
@@ -153,14 +153,7 @@ export const createJobs = async <T extends PipelineType>(
|
|
|
153
153
|
trigger: PipelineTrigger
|
|
154
154
|
): Promise<Record<string, PipelineJob<T>>> => {
|
|
155
155
|
const commitInfo: CommitInfo = {
|
|
156
|
-
|
|
157
|
-
reviewSlug: process.env.CI_MERGE_REQUEST_IID
|
|
158
|
-
? `mr${process.env.CI_MERGE_REQUEST_IID}`
|
|
159
|
-
: "unknown",
|
|
160
|
-
buildTime: new Date().toISOString(),
|
|
161
|
-
buildId: await exec("git describe --tags || git rev-parse HEAD").then((s) =>
|
|
162
|
-
s.stdout.trim()
|
|
163
|
-
),
|
|
156
|
+
...(await getBaseCommitInfo()),
|
|
164
157
|
trigger,
|
|
165
158
|
};
|
|
166
159
|
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
+
import { isObject } from "lodash";
|
|
1
2
|
import { BASE_RETRY } from "../../defaults";
|
|
2
3
|
import type { GitlabJobDef } from "../../types";
|
|
3
|
-
import type { CatladderJob } from "../../types/jobs";
|
|
4
|
+
import type { CatladderJob, CatladderJobNeed } from "../../types/jobs";
|
|
5
|
+
const getJobName = (need: CatladderJobNeed) =>
|
|
6
|
+
isObject(need) ? need.job : need;
|
|
4
7
|
|
|
5
8
|
export const makeGitlabJob = ({
|
|
6
9
|
envMode,
|
|
7
10
|
needsStages,
|
|
8
11
|
needsOtherComponent,
|
|
9
12
|
name,
|
|
13
|
+
needs,
|
|
10
14
|
...rest
|
|
11
15
|
}: CatladderJob<string>): GitlabJobDef => {
|
|
12
16
|
return {
|
|
13
17
|
...rest,
|
|
18
|
+
// sort in a predictable manner for snapshot tests
|
|
19
|
+
needs: needs?.sort((a, b) => getJobName(a).localeCompare(getJobName(b))),
|
|
14
20
|
retry: BASE_RETRY,
|
|
15
21
|
interruptible: true,
|
|
16
22
|
};
|
|
@@ -1,43 +1,9 @@
|
|
|
1
|
-
import { exec } from "child-process-promise";
|
|
2
|
-
import type { Config, PackageManagerInfo } from "../types";
|
|
3
|
-
import { pathEqual } from "path-equal";
|
|
4
|
-
import memoizee from "memoizee";
|
|
5
|
-
import { join } from "path";
|
|
6
1
|
import { existsSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { pathEqual } from "path-equal";
|
|
4
|
+
import type { Config, PackageManagerInfo } from "../types";
|
|
5
|
+
import { getWorkspaces, getYarnVersion } from "./yarn/yarnUtils";
|
|
7
6
|
|
|
8
|
-
const execOrFail = async (cmd: string, onFail: string): Promise<string> => {
|
|
9
|
-
try {
|
|
10
|
-
return await exec(cmd).then((r) => r.stdout);
|
|
11
|
-
} catch (e) {
|
|
12
|
-
return onFail ?? null;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const getYarnVersion = memoizee(
|
|
17
|
-
async () => {
|
|
18
|
-
return await execOrFail("yarn --version", "");
|
|
19
|
-
},
|
|
20
|
-
{ promise: true }
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
const getWorkspaces = memoizee(
|
|
24
|
-
async (isClassic: boolean): Promise<PackageManagerInfo["workspaces"]> => {
|
|
25
|
-
return isClassic
|
|
26
|
-
? Object.values(
|
|
27
|
-
JSON.parse(
|
|
28
|
-
JSON.parse(await execOrFail("yarn workspaces --json info", "{}"))
|
|
29
|
-
?.data ?? "{}"
|
|
30
|
-
)
|
|
31
|
-
)
|
|
32
|
-
: JSON.parse(
|
|
33
|
-
`[${(await execOrFail("yarn workspaces list --json --verbose", ""))
|
|
34
|
-
.trim()
|
|
35
|
-
.split("\n")
|
|
36
|
-
.join(",")}]`
|
|
37
|
-
);
|
|
38
|
-
},
|
|
39
|
-
{ promise: true }
|
|
40
|
-
);
|
|
41
7
|
export const getPackageManagerInfo = async (
|
|
42
8
|
config: Config,
|
|
43
9
|
componentName: string
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { exec } from "child-process-promise";
|
|
2
|
+
import memoizee from "memoizee";
|
|
3
|
+
import type { PackageManagerInfo } from "../../types";
|
|
4
|
+
|
|
5
|
+
const execOrFail = async (cmd: string, onFail: string): Promise<string> => {
|
|
6
|
+
try {
|
|
7
|
+
return await exec(cmd).then((r) => r.stdout);
|
|
8
|
+
} catch (e) {
|
|
9
|
+
return onFail ?? null;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
// export for mocking
|
|
13
|
+
export const getYarnVersion = memoizee(
|
|
14
|
+
async () => {
|
|
15
|
+
return await execOrFail("yarn --version", "");
|
|
16
|
+
},
|
|
17
|
+
{ promise: true }
|
|
18
|
+
);
|
|
19
|
+
// export for mocking
|
|
20
|
+
export const getWorkspaces = memoizee(
|
|
21
|
+
async (isClassic: boolean): Promise<PackageManagerInfo["workspaces"]> => {
|
|
22
|
+
return isClassic
|
|
23
|
+
? Object.values(
|
|
24
|
+
JSON.parse(
|
|
25
|
+
JSON.parse(await execOrFail("yarn workspaces --json info", "{}"))
|
|
26
|
+
?.data ?? "{}"
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
: JSON.parse(
|
|
30
|
+
`[${(await execOrFail("yarn workspaces list --json --verbose", ""))
|
|
31
|
+
.trim()
|
|
32
|
+
.split("\n")
|
|
33
|
+
.join(",")}]`
|
|
34
|
+
);
|
|
35
|
+
},
|
|
36
|
+
{ promise: true }
|
|
37
|
+
);
|
package/src/types/jobs.ts
CHANGED
|
@@ -18,6 +18,7 @@ export const BASE_STAGES = [
|
|
|
18
18
|
] as const;
|
|
19
19
|
export type BaseStage = typeof BASE_STAGES[number];
|
|
20
20
|
|
|
21
|
+
export type CatladderJobNeed = string | { job: string; artifacts: boolean };
|
|
21
22
|
export type CatladderJob<S = BaseStage> = {
|
|
22
23
|
/**
|
|
23
24
|
* the name of the job (without any env or app prefix and suffix)
|
|
@@ -52,7 +53,7 @@ export type CatladderJob<S = BaseStage> = {
|
|
|
52
53
|
/**
|
|
53
54
|
* does this require another job (from the same component)?
|
|
54
55
|
*/
|
|
55
|
-
needs?: Array<
|
|
56
|
+
needs?: Array<CatladderJobNeed>;
|
|
56
57
|
|
|
57
58
|
needsOtherComponent?: Array<{
|
|
58
59
|
componentName: string;
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../../types";
|
|
2
|
-
import { createChildPipeline } from "../../";
|
|
3
|
-
|
|
4
|
-
describe("storybook build", () => {
|
|
5
|
-
describe("creates two build jobs", () => {
|
|
6
|
-
const config: Config = {
|
|
7
|
-
appName: "test",
|
|
8
|
-
customerName: "pan",
|
|
9
|
-
components: {
|
|
10
|
-
"my-app": {
|
|
11
|
-
dir: "myapp",
|
|
12
|
-
build: {
|
|
13
|
-
type: "storybook",
|
|
14
|
-
},
|
|
15
|
-
deploy: {
|
|
16
|
-
type: "kubernetes",
|
|
17
|
-
cluster: {
|
|
18
|
-
name: "production",
|
|
19
|
-
projectId: "bla",
|
|
20
|
-
region: "europe",
|
|
21
|
-
type: "gcloud",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
it("creates a pipeline for storybook that does not contain test stages", async () => {
|
|
29
|
-
const { jobs } = await createChildPipeline(
|
|
30
|
-
"gitlab",
|
|
31
|
-
"mainBranch",
|
|
32
|
-
config
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
expect(Object.keys(jobs)).toEqual([
|
|
36
|
-
"dev my-app app-build",
|
|
37
|
-
"dev my-app docker-build",
|
|
38
|
-
"dev my-app deploy-to-kubernetes",
|
|
39
|
-
"dev my-app kubernetes-stop",
|
|
40
|
-
]);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("runs build and renames folder", async () => {
|
|
44
|
-
const { jobs } = await createChildPipeline(
|
|
45
|
-
"gitlab",
|
|
46
|
-
"mainBranch",
|
|
47
|
-
config
|
|
48
|
-
);
|
|
49
|
-
const buildJob = jobs["dev my-app app-build"];
|
|
50
|
-
expect(buildJob.script).toContain("yarn storybook");
|
|
51
|
-
expect(buildJob.script).toContain("mv ./storybook-out /dist");
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../types";
|
|
2
|
-
import { createChildPipeline } from "./createChildPipeline";
|
|
3
|
-
|
|
4
|
-
describe("createChildPipeline", () => {
|
|
5
|
-
describe("node-app to kuberntes", () => {
|
|
6
|
-
const config: Config = {
|
|
7
|
-
appName: "test",
|
|
8
|
-
customerName: "pan",
|
|
9
|
-
components: {
|
|
10
|
-
"my-app": {
|
|
11
|
-
dir: "myapp",
|
|
12
|
-
build: {
|
|
13
|
-
type: "node",
|
|
14
|
-
},
|
|
15
|
-
deploy: {
|
|
16
|
-
type: "kubernetes",
|
|
17
|
-
cluster: {
|
|
18
|
-
type: "gcloud",
|
|
19
|
-
name: "mega-cluster",
|
|
20
|
-
projectId: "super-google-project",
|
|
21
|
-
region: "ch-blabla",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
it("creates a pipeline for a single app on the main branch", async () => {
|
|
29
|
-
const { image, jobs } = await createChildPipeline(
|
|
30
|
-
"gitlab",
|
|
31
|
-
"mainBranch",
|
|
32
|
-
config
|
|
33
|
-
);
|
|
34
|
-
expect(image).toEqual(
|
|
35
|
-
"git.panter.ch:5001/catladder/catladder/base-pipeline:"
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
expect(Object.keys(jobs)).toEqual([
|
|
39
|
-
"my-app audit",
|
|
40
|
-
"my-app lint",
|
|
41
|
-
"my-app test",
|
|
42
|
-
"dev my-app app-build",
|
|
43
|
-
"dev my-app docker-build",
|
|
44
|
-
"dev my-app deploy-to-kubernetes",
|
|
45
|
-
"dev my-app kubernetes-stop",
|
|
46
|
-
]);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
});
|