@catladder/pipeline 3.29.1 → 3.30.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.
@@ -0,0 +1,11 @@
1
+ import { createYamlLocalPipeline } from "./__utils__/helpers";
2
+ import config from "./cloud-run-execute-script-on-deploy";
3
+
4
+ /**
5
+ * This test is auto-generated.
6
+ * Modifications will be overwritten on every `yarn test` run!
7
+ */
8
+
9
+ it("matches snapshot for cloud-run-execute-script-on-deploy local pipeline YAML", async () => {
10
+ expect(await createYamlLocalPipeline(config)).toMatchSnapshot();
11
+ });
@@ -0,0 +1,47 @@
1
+ import type { Config } from "../src";
2
+
3
+ const config = {
4
+ appName: "test-app",
5
+ customerName: "pan",
6
+ components: {
7
+ app: {
8
+ dir: "app",
9
+ build: {
10
+ type: "node",
11
+ },
12
+ deploy: {
13
+ type: "google-cloudrun",
14
+ projectId: "google-project-id",
15
+ region: "europe-west6",
16
+ execute: {
17
+ "pre-deploy-script": {
18
+ type: "script",
19
+ script: ["echo 'deploying'"],
20
+ when: "preDeploy",
21
+ },
22
+ "post-deploy-script": {
23
+ type: "script",
24
+ script: ["echo 'deployed'"],
25
+ when: "postDeploy",
26
+ },
27
+ "pre-stop-script": {
28
+ type: "script",
29
+ script: ["echo 'stopping'"],
30
+ when: "preStop",
31
+ },
32
+ "post-stop-script": {
33
+ type: "script",
34
+ script: ["echo 'stopped'"],
35
+ when: "postStop",
36
+ },
37
+ },
38
+ },
39
+ },
40
+ },
41
+ } satisfies Config;
42
+
43
+ export default config;
44
+
45
+ export const information = {
46
+ title: "Cloud Run: Execute script on deploy",
47
+ };
package/package.json CHANGED
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "3.29.1",
56
+ "version": "3.30.0",
57
57
  "scripts": {
58
58
  "build:tsc": "yarn tsc",
59
59
  "build": "yarn build:compile && yarn build:inline-variables",
@@ -1,10 +1,8 @@
1
1
  import type { StringOrBashExpression } from "../../../../bash";
2
2
  import type { ComponentContext } from "../../../../types/context";
3
- import type {
4
- DeployConfigCloudRunExecuteOnDeploy,
5
- DeployConfigCloudRunJob,
6
- DeployConfigCloudRunService,
7
- } from "../../../types/googleCloudRun";
3
+ import { ensureArray } from "../../../../utils";
4
+ import type { DeployConfigBaseExecuteOnDeploy } from "../../../types/executeBase";
5
+ import type { DeployConfigCloudRunExecuteOnDeploy } from "../../../types/googleCloudRun";
8
6
  import { createArgsString } from "../../utils/createArgsString";
9
7
  import { getCloudRunServiceOrJobArgsArg } from "../../utils/getJobOrServiceArgs";
10
8
  import { getFullJobName } from "../../utils/jobName";
@@ -17,7 +15,7 @@ import {
17
15
 
18
16
  type Execute = {
19
17
  jobName: StringOrBashExpression;
20
- config: DeployConfigCloudRunExecuteOnDeploy;
18
+ config: DeployConfigCloudRunExecuteOnDeploy | DeployConfigBaseExecuteOnDeploy;
21
19
  };
22
20
  export const getOnDeployExecuteScript = (
23
21
  context: ComponentContext,
@@ -27,7 +25,7 @@ export const getOnDeployExecuteScript = (
27
25
 
28
26
  return executes
29
27
  .filter(({ config }) => config.when === when)
30
- .map((execute) => {
28
+ .flatMap((execute) => {
31
29
  return getJobRunScriptForExecute(context, execute);
32
30
  });
33
31
  };
@@ -37,7 +35,8 @@ const getExecutes = (context: ComponentContext): Execute[] => {
37
35
  return [
38
36
  ...getLegacyExecutes(context),
39
37
  ...Object.entries(deployConfig.execute ?? {}).flatMap(([key, value]) => {
40
- if (!value || (value.when !== "schedule" && value.type !== "job")) {
38
+ // remove all schedule executes
39
+ if (!value) {
41
40
  return [];
42
41
  }
43
42
  return [
@@ -81,22 +80,30 @@ const getLegacyExecutes = (context: ComponentContext): Execute[] => {
81
80
  const getJobRunScriptForExecute = (
82
81
  context: ComponentContext,
83
82
  { jobName, config }: Execute,
84
- ) => {
85
- const commonArgs = getCommonCloudRunArgs(context);
83
+ ): string[] => {
84
+ const type = config.type;
85
+ if (type === "script") {
86
+ return ensureArray(config.script);
87
+ } else if (type === "job") {
88
+ const commonArgs = getCommonCloudRunArgs(context);
86
89
 
87
- // always wait for completion for preStop and postStop jobs
88
- // since stop will delete the jobs afterwards, so they will fail
89
- const waitForCompletion = ["preStop", "postStop"].includes(config.when)
90
- ? true // always
91
- : "waitForCompletion" in config
92
- ? (config.waitForCompletion ?? false) // depends on config
93
- : false;
90
+ // always wait for completion for preStop and postStop jobs
91
+ // since stop will delete the jobs afterwards, so they will fail
92
+ const waitForCompletion = ["preStop", "postStop"].includes(config.when)
93
+ ? true // always
94
+ : "waitForCompletion" in config
95
+ ? (config.waitForCompletion ?? false) // depends on config
96
+ : false;
94
97
 
95
- const argString = createArgsString({
96
- ...commonArgs,
97
- wait: waitForCompletion === true ? true : undefined,
98
- args: getCloudRunServiceOrJobArgsArg(config.args),
99
- });
100
- const fullJobName = getFullJobName(context, jobName);
101
- return `${gcloudRunCmd()} jobs execute ${fullJobName.toString()} ${argString}`;
98
+ const argString = createArgsString({
99
+ ...commonArgs,
100
+ wait: waitForCompletion === true ? true : undefined,
101
+ args: getCloudRunServiceOrJobArgsArg(config.args),
102
+ });
103
+ const fullJobName = getFullJobName(context, jobName);
104
+ return [
105
+ `${gcloudRunCmd()} jobs execute ${fullJobName.toString()} ${argString}`,
106
+ ];
107
+ }
108
+ throw new Error(`unsupported execute type: ${type}`);
102
109
  };
@@ -1,4 +1,5 @@
1
1
  import type { EnvVars } from "../../types/config";
2
+ import type { DeployConfigBaseExecute } from "./executeBase";
2
3
 
3
4
  export type DeployConfigBase = {
4
5
  /**
@@ -0,0 +1,27 @@
1
+ type DeployConfigBaseExecuteScript = {
2
+ type: "script";
3
+ script: string | string[];
4
+ };
5
+ /**
6
+ * currently only supported for cloud run deployments
7
+ */
8
+ export type DeployConfigBaseExecuteOnDeploy = DeployConfigBaseExecuteScript &
9
+ (
10
+ | {
11
+ /**
12
+ * run the job before or after the deploy
13
+ */
14
+ when: "preDeploy" | "postDeploy";
15
+ /**
16
+ * whether to wait for completion of the job
17
+ */
18
+ waitForCompletion?: boolean;
19
+ }
20
+ | {
21
+ /**
22
+ * run the job before or after the environment is stopped
23
+ */
24
+ when: "preStop" | "postStop";
25
+ }
26
+ );
27
+ export type DeployConfigBaseExecute = DeployConfigBaseExecuteOnDeploy;
@@ -1,5 +1,9 @@
1
1
  import type { DBVariablesMode } from "../cloudRun/utils/database";
2
2
  import type { DeployConfigBase } from "./base";
3
+ import type {
4
+ DeployConfigBaseExecute,
5
+ DeployConfigBaseExecuteOnDeploy,
6
+ } from "./executeBase";
3
7
 
4
8
  export type Gcloudregion =
5
9
  | "asia-east1"
@@ -424,7 +428,7 @@ export type DeployConfigCloudRunJob =
424
428
  | DeployConfigCloudRunJobNormal
425
429
  | DeployConfigCloudRunJobWithSchedule;
426
430
 
427
- export type DeployConfigCloudRun = {
431
+ export type DeployConfigCloudRun = Omit<DeployConfigBase, "execute"> & {
428
432
  /**
429
433
  * cloud run deployment.
430
434
  *
@@ -469,7 +473,7 @@ export type DeployConfigCloudRun = {
469
473
  execute?: Record<string, DeployConfigCloudRunExecute | null>;
470
474
 
471
475
  debug?: boolean;
472
- } & DeployConfigBase;
476
+ };
473
477
 
474
478
  export type DeployConfigCloudRunVolumes = Record<
475
479
  string,
@@ -543,6 +547,7 @@ export type DeployConfigCloudRunExecuteOnDeploy =
543
547
  );
544
548
 
545
549
  export type DeployConfigCloudRunExecuteJob =
550
+ | DeployConfigBaseExecute
546
551
  | DeployConfigCloudRunExecuteJobScheduled
547
552
  | DeployConfigCloudRunExecuteOnDeploy;
548
553
 
@@ -573,6 +578,7 @@ export type DeployConfigCloudRunExecuteHttp = {
573
578
  } & WithSchedule;
574
579
 
575
580
  export type DeployConfigCloudRunExecute =
581
+ | DeployConfigBaseExecute
576
582
  | DeployConfigCloudRunExecuteJob
577
583
  | DeployConfigCloudRunExecuteHttp;
578
584