From cc616032b40488091a3e6438a7d1536f6b046a5b Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Wed, 31 Jan 2024 18:30:35 +0100 Subject: [PATCH] feat(config): add environments field on actions This allows setting e.g. `environments: [dev]` on actions instead of the more verbose `disabled: ${environment.name != "dev"}`. --- core/src/actions/base.ts | 16 ++-- core/src/actions/types.ts | 1 + core/src/commands/plugins.ts | 7 +- core/src/garden.ts | 2 +- core/src/graph/actions.ts | 13 +-- core/src/graph/config-graph.ts | 12 ++- core/src/tasks/resolve-action.ts | 1 + .../project.garden.yml | 17 ++++ .../src/actions/action-configs-to-graph.ts | 28 ------- core/test/unit/src/actions/base.ts | 82 ++++++++++++++++++- core/test/unit/src/garden.ts | 12 +++ .../reference/action-types/Build/container.md | 8 ++ docs/reference/action-types/Build/exec.md | 8 ++ .../action-types/Build/jib-container.md | 8 ++ .../action-types/Deploy/configmap.md | 8 ++ .../action-types/Deploy/container.md | 8 ++ docs/reference/action-types/Deploy/exec.md | 8 ++ docs/reference/action-types/Deploy/helm.md | 8 ++ .../action-types/Deploy/kubernetes.md | 8 ++ .../Deploy/persistentvolumeclaim.md | 8 ++ docs/reference/action-types/Deploy/pulumi.md | 8 ++ .../action-types/Deploy/terraform.md | 8 ++ docs/reference/action-types/Run/container.md | 8 ++ docs/reference/action-types/Run/exec.md | 8 ++ docs/reference/action-types/Run/helm-pod.md | 8 ++ .../action-types/Run/kubernetes-exec.md | 8 ++ .../action-types/Run/kubernetes-pod.md | 8 ++ .../action-types/Test/conftest-helm.md | 8 ++ docs/reference/action-types/Test/conftest.md | 8 ++ docs/reference/action-types/Test/container.md | 8 ++ docs/reference/action-types/Test/exec.md | 8 ++ docs/reference/action-types/Test/hadolint.md | 8 ++ docs/reference/action-types/Test/helm-pod.md | 8 ++ .../action-types/Test/kubernetes-exec.md | 8 ++ .../action-types/Test/kubernetes-pod.md | 8 ++ docs/reference/commands.md | 20 +++++ examples/disabled-configs/README.md | 2 +- examples/disabled-configs/frontend/garden.yml | 3 +- 38 files changed, 364 insertions(+), 44 deletions(-) create mode 100644 core/test/data/test-projects/config-action-environments/project.garden.yml diff --git a/core/src/actions/base.ts b/core/src/actions/base.ts index fd2f7efa5d..66ec949cb1 100644 --- a/core/src/actions/base.ts +++ b/core/src/actions/base.ts @@ -174,6 +174,14 @@ export const baseActionConfigSchema = createSchema({ ` ) .meta({ templateContext: ActionConfigContext }), + environments: joi + .sparseArray() + .items(joi.string()) + .description( + dedent` + If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the \`disabled\` field with an expression for environments. For example, \`environments: ["prod"]\` is equivalent to \`disabled: \${environment.name != "prod"}\`. + ` + ), // Version/file handling (Note: Descriptions and behaviors are different on Build actions!) include: includeExcludeSchema() @@ -411,8 +419,7 @@ export abstract class BaseAction< isDisabled(): boolean { // TODO: return true if group is disabled - // TODO: implement environments field on action config - return actionIsDisabled(this._config, "TODO") + return actionIsDisabled(this._config, this.graph.environmentName) } /** @@ -888,9 +895,8 @@ export function addActionDependency(dep: ActionDependency, dependencies: ActionD dependencies.push(dep) } -export function actionIsDisabled(config: ActionConfig, _environmentName: string): boolean { - // TODO: implement environment fields and check if environment is disabled - return config.disabled === true +export function actionIsDisabled(config: ActionConfig, environmentName: string): boolean { + return config.disabled === true || (!!config.environments && !config.environments.includes(environmentName)) } /** diff --git a/core/src/actions/types.ts b/core/src/actions/types.ts index e82087a80d..6b1acd57fd 100644 --- a/core/src/actions/types.ts +++ b/core/src/actions/types.ts @@ -75,6 +75,7 @@ export interface BaseActionConfig Templating with ActionConfigContext allowed dependencies?: ActionReference[] disabled?: boolean + environments?: string[] // Version/file handling // -> Templating with ActionConfigContext allowed diff --git a/core/src/commands/plugins.ts b/core/src/commands/plugins.ts index 0f9c3f5c7a..74a2bb07fe 100644 --- a/core/src/commands/plugins.ts +++ b/core/src/commands/plugins.ts @@ -106,7 +106,12 @@ export class PluginsCommand extends Command { const provider = await garden.resolveProvider(log, args.plugin) const ctx = await garden.getPluginContext({ provider, templateContext: undefined, events: undefined }) - let graph = new ConfigGraph({ actions: [], moduleGraph: new ModuleGraph([], {}), groups: [] }) + let graph = new ConfigGraph({ + environmentName: garden.environmentName, + actions: [], + moduleGraph: new ModuleGraph([], {}), + groups: [], + }) // Commands can optionally ask for all the modules in the project/environment if (command.resolveGraph) { diff --git a/core/src/garden.ts b/core/src/garden.ts index e15d63a9d1..6ede2a08d6 100644 --- a/core/src/garden.ts +++ b/core/src/garden.ts @@ -1063,7 +1063,6 @@ export class Garden { moduleGraph, actionModes, linkedSources, - environmentName: this.environmentName, }) // TODO-0.13.1: detect overlap on Build actions @@ -1190,6 +1189,7 @@ export class Garden { const graph = await this.getConfigGraph(params) const resolved = await this.resolveActions({ graph, actions: graph.getActions(), log: params.log }) return new ResolvedConfigGraph({ + environmentName: this.environmentName, actions: Object.values(resolved), moduleGraph: graph.moduleGraph, // TODO: perhaps groups should be resolved here diff --git a/core/src/graph/actions.ts b/core/src/graph/actions.ts index 5e2b48f453..9124d516c1 100644 --- a/core/src/graph/actions.ts +++ b/core/src/graph/actions.ts @@ -78,7 +78,6 @@ export const actionConfigsToGraph = profileAsync(async function actionConfigsToG moduleGraph, actionModes, linkedSources, - environmentName, }: { garden: Garden log: Log @@ -87,7 +86,6 @@ export const actionConfigsToGraph = profileAsync(async function actionConfigsToG moduleGraph: ModuleGraph actionModes: ActionModeMap linkedSources: LinkedSourceMap - environmentName: string }): Promise { const configsByKey: ActionConfigsByKey = {} @@ -100,10 +98,10 @@ export const actionConfigsToGraph = profileAsync(async function actionConfigsToG const existing = configsByKey[key] if (existing) { - if (actionIsDisabled(config, environmentName)) { + if (actionIsDisabled(config, garden.environmentName)) { log.silly(() => `Skipping disabled action ${key} in favor of other action with same key`) return - } else if (actionIsDisabled(existing, environmentName)) { + } else if (actionIsDisabled(existing, garden.environmentName)) { log.silly(() => `Skipping disabled action ${key} in favor of other action with same key`) configsByKey[key] = config return @@ -205,7 +203,12 @@ export const actionConfigsToGraph = profileAsync(async function actionConfigsToG const minimalRoots = await garden.vcs.getMinimalRoots(log, allPaths) // TODO: Maybe we could optimize resolving tree versions, avoid parallel scanning of the same directory etc. - const graph = new MutableConfigGraph({ actions: [], moduleGraph, groups: groupConfigs }) + const graph = new MutableConfigGraph({ + environmentName: garden.environmentName, + actions: [], + moduleGraph, + groups: groupConfigs, + }) await Promise.all( Object.entries(preprocessResults).map(async ([key, res]) => { diff --git a/core/src/graph/config-graph.ts b/core/src/graph/config-graph.ts index d7509df302..e49b700cdc 100644 --- a/core/src/graph/config-graph.ts +++ b/core/src/graph/config-graph.ts @@ -91,16 +91,20 @@ export abstract class BaseConfigGraph< } readonly moduleGraph: ModuleGraph + readonly environmentName: string constructor({ + environmentName, actions, moduleGraph, groups, }: { + environmentName: string actions: Action[] moduleGraph: ModuleGraph groups: GroupConfig[] }) { + this.environmentName = environmentName this.dependencyGraph = {} this.actions = { Build: {}, @@ -132,7 +136,12 @@ export abstract class BaseConfigGraph< } clone() { - const clone = new ConfigGraph({ actions: [], moduleGraph: this.moduleGraph, groups: Object.values(this.groups) }) + const clone = new ConfigGraph({ + environmentName: this.environmentName, + actions: [], + moduleGraph: this.moduleGraph, + groups: Object.values(this.groups), + }) for (const key of Object.getOwnPropertyNames(this)) { clone[key] = cloneDeep(this[key]) } @@ -455,6 +464,7 @@ export abstract class BaseConfigGraph< toMutableGraph() { return new MutableConfigGraph({ + environmentName: this.environmentName, actions: this.getActions(), moduleGraph: this.moduleGraph, groups: Object.values(this.groups), diff --git a/core/src/tasks/resolve-action.ts b/core/src/tasks/resolve-action.ts index 29f3a1db8d..9da926b58d 100644 --- a/core/src/tasks/resolve-action.ts +++ b/core/src/tasks/resolve-action.ts @@ -201,6 +201,7 @@ export class ResolveActionTask extends BaseActionTask { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const actions = graph.getActions() @@ -86,7 +85,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const actions = graph.getActions() @@ -118,7 +116,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const actions = graph.getActions() @@ -150,7 +147,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const actions = graph.getActions() @@ -189,7 +185,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const actions = graph.getActions() @@ -232,7 +227,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("bar") @@ -280,7 +274,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getDeploy("bar") @@ -329,7 +322,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("bar") @@ -379,7 +371,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("bar") @@ -429,7 +420,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getDeploy("bar") @@ -467,7 +457,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -496,7 +485,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("bar") @@ -527,7 +515,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -562,7 +549,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -602,7 +588,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -658,7 +643,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -703,7 +687,6 @@ describe("actionConfigsToGraph", () => { actionModes: { sync: ["deploy.foo"], }, - environmentName: garden.environmentName, }) const action = graph.getDeploy("foo") @@ -734,7 +717,6 @@ describe("actionConfigsToGraph", () => { actionModes: { local: ["deploy.foo"], }, - environmentName: garden.environmentName, }) const action = graph.getDeploy("foo") @@ -771,7 +753,6 @@ describe("actionConfigsToGraph", () => { local: ["deploy.foo"], sync: ["deploy.foo"], }, - environmentName: garden.environmentName, }) const action = graph.getDeploy("foo") @@ -802,7 +783,6 @@ describe("actionConfigsToGraph", () => { actionModes: { local: ["*"], }, - environmentName: garden.environmentName, }) const action = graph.getDeploy("foo") @@ -833,7 +813,6 @@ describe("actionConfigsToGraph", () => { actionModes: { local: ["deploy.f*"], }, - environmentName: garden.environmentName, }) const action = graph.getDeploy("foo") @@ -876,7 +855,6 @@ describe("actionConfigsToGraph", () => { actionModes: { local: ["deploy.*"], }, - environmentName: garden.environmentName, }) const deploy = graph.getDeploy("foo") @@ -908,7 +886,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }), (err) => expect(err.message).to.equal("Unknown action kind: Boop") ) @@ -946,7 +923,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }), { contains: ["Found two actions of the same name and kind"], @@ -985,7 +961,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -1023,7 +998,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -1055,7 +1029,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) const action = graph.getBuild("foo") @@ -1092,7 +1065,6 @@ describe("actionConfigsToGraph", () => { moduleGraph: new ModuleGraph([], {}), actionModes: {}, linkedSources: {}, - environmentName: garden.environmentName, }) it("sets include and exclude", async () => { diff --git a/core/test/unit/src/actions/base.ts b/core/test/unit/src/actions/base.ts index f55233cc7b..c16a4a5ba3 100644 --- a/core/test/unit/src/actions/base.ts +++ b/core/test/unit/src/actions/base.ts @@ -10,7 +10,7 @@ import { expect } from "chai" import { DEFAULT_BUILD_TIMEOUT_SEC } from "../../../../src/constants.js" import type { ActionConfig, BaseActionConfig } from "../../../../src/actions/types.js" import type { NonVersionedActionConfigKey } from "../../../../src/actions/base.js" -import { getActionConfigVersion } from "../../../../src/actions/base.js" +import { actionIsDisabled, getActionConfigVersion } from "../../../../src/actions/base.js" describe("getActionConfigVersion", () => { function minimalActionConfig(): ActionConfig { @@ -58,3 +58,83 @@ describe("getActionConfigVersion", () => { } }) }) + +describe("actionIsDisabled", () => { + it("returns true if the action is disabled", () => { + const config: ActionConfig = { + kind: "Build", + type: "test", + name: "foo", + timeout: DEFAULT_BUILD_TIMEOUT_SEC, + internal: { + basePath: ".", + }, + spec: {}, + disabled: true, + } + expect(actionIsDisabled(config, "foo")).to.eql(true) + }) + + it("returns false if the action is not disabled", () => { + const config: ActionConfig = { + kind: "Build", + type: "test", + name: "foo", + timeout: DEFAULT_BUILD_TIMEOUT_SEC, + internal: { + basePath: ".", + }, + disabled: false, + spec: {}, + } + expect(actionIsDisabled(config, "foo")).to.eql(false) + }) + + it("returns false if action environments field is undefined", () => { + const config: ActionConfig = { + kind: "Build", + type: "test", + name: "foo", + timeout: DEFAULT_BUILD_TIMEOUT_SEC, + internal: { + basePath: ".", + }, + disabled: false, + environments: undefined, + spec: {}, + } + expect(actionIsDisabled(config, "foo")).to.eql(false) + }) + + it("returns false if action environments field is set and contains the environment", () => { + const config: ActionConfig = { + kind: "Build", + type: "test", + name: "foo", + timeout: DEFAULT_BUILD_TIMEOUT_SEC, + internal: { + basePath: ".", + }, + disabled: false, + environments: ["yes"], + spec: {}, + } + expect(actionIsDisabled(config, "yes")).to.eql(false) + }) + + it("returns true if action environments field is set and does not contain the environment", () => { + const config: ActionConfig = { + kind: "Build", + type: "test", + name: "foo", + timeout: DEFAULT_BUILD_TIMEOUT_SEC, + internal: { + basePath: ".", + }, + disabled: false, + environments: ["yes"], + spec: {}, + } + expect(actionIsDisabled(config, "no")).to.eql(true) + }) +}) diff --git a/core/test/unit/src/garden.ts b/core/test/unit/src/garden.ts index 2635bfebf3..c0bdd4bc4d 100644 --- a/core/test/unit/src/garden.ts +++ b/core/test/unit/src/garden.ts @@ -4358,6 +4358,18 @@ describe("Garden", () => { ], }) }) + + it("correctly picks up and handles the environments field on actions", async () => { + const projectRoot = getDataDir("test-projects", "config-action-environments") + const garden = await makeTestGarden(projectRoot, { environmentString: "remote" }) + + const graph = await garden.getConfigGraph({ log: garden.log, emit: false }) + const a = graph.getBuild("a", { includeDisabled: true }) + const b = graph.getBuild("b", { includeDisabled: true }) + + expect(a.isDisabled()).to.be.false + expect(b.isDisabled()).to.be.true + }) }) context("module type has a base", () => { diff --git a/docs/reference/action-types/Build/container.md b/docs/reference/action-types/Build/container.md index d3e6cbae4c..a708021fdc 100644 --- a/docs/reference/action-types/Build/container.md +++ b/docs/reference/action-types/Build/container.md @@ -128,6 +128,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `variables` A map of variables scoped to this particular action. These are resolved before any other parts of the action configuration and take precedence over group-scoped variables (if applicable) and project-scoped variables, in that order. They may reference group-scoped and project-scoped variables, and generally can use any template strings normally allowed when resolving the action. diff --git a/docs/reference/action-types/Build/exec.md b/docs/reference/action-types/Build/exec.md index c4587ca0bf..f9e844a5ac 100644 --- a/docs/reference/action-types/Build/exec.md +++ b/docs/reference/action-types/Build/exec.md @@ -128,6 +128,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `variables` A map of variables scoped to this particular action. These are resolved before any other parts of the action configuration and take precedence over group-scoped variables (if applicable) and project-scoped variables, in that order. They may reference group-scoped and project-scoped variables, and generally can use any template strings normally allowed when resolving the action. diff --git a/docs/reference/action-types/Build/jib-container.md b/docs/reference/action-types/Build/jib-container.md index 1641c328b9..02995646bb 100644 --- a/docs/reference/action-types/Build/jib-container.md +++ b/docs/reference/action-types/Build/jib-container.md @@ -140,6 +140,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `variables` A map of variables scoped to this particular action. These are resolved before any other parts of the action configuration and take precedence over group-scoped variables (if applicable) and project-scoped variables, in that order. They may reference group-scoped and project-scoped variables, and generally can use any template strings normally allowed when resolving the action. diff --git a/docs/reference/action-types/Deploy/configmap.md b/docs/reference/action-types/Deploy/configmap.md index 0720c10d50..3745167ea2 100644 --- a/docs/reference/action-types/Deploy/configmap.md +++ b/docs/reference/action-types/Deploy/configmap.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Deploy/container.md b/docs/reference/action-types/Deploy/container.md index 9b29acf0fc..856d5bf765 100644 --- a/docs/reference/action-types/Deploy/container.md +++ b/docs/reference/action-types/Deploy/container.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Deploy/exec.md b/docs/reference/action-types/Deploy/exec.md index 371b31698c..699259863f 100644 --- a/docs/reference/action-types/Deploy/exec.md +++ b/docs/reference/action-types/Deploy/exec.md @@ -128,6 +128,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Deploy/helm.md b/docs/reference/action-types/Deploy/helm.md index 4792637bef..3861bf599c 100644 --- a/docs/reference/action-types/Deploy/helm.md +++ b/docs/reference/action-types/Deploy/helm.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Deploy/kubernetes.md b/docs/reference/action-types/Deploy/kubernetes.md index 8d40e874d3..9243041743 100644 --- a/docs/reference/action-types/Deploy/kubernetes.md +++ b/docs/reference/action-types/Deploy/kubernetes.md @@ -134,6 +134,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Deploy/persistentvolumeclaim.md b/docs/reference/action-types/Deploy/persistentvolumeclaim.md index a82cf93da1..c75ff1d41f 100644 --- a/docs/reference/action-types/Deploy/persistentvolumeclaim.md +++ b/docs/reference/action-types/Deploy/persistentvolumeclaim.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Deploy/pulumi.md b/docs/reference/action-types/Deploy/pulumi.md index 5d5610f3d7..1bbc8ce38c 100644 --- a/docs/reference/action-types/Deploy/pulumi.md +++ b/docs/reference/action-types/Deploy/pulumi.md @@ -132,6 +132,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Deploy/terraform.md b/docs/reference/action-types/Deploy/terraform.md index dca31b5f83..8184d315fa 100644 --- a/docs/reference/action-types/Deploy/terraform.md +++ b/docs/reference/action-types/Deploy/terraform.md @@ -136,6 +136,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Run/container.md b/docs/reference/action-types/Run/container.md index 2c68dea4c5..3686f03573 100644 --- a/docs/reference/action-types/Run/container.md +++ b/docs/reference/action-types/Run/container.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Run/exec.md b/docs/reference/action-types/Run/exec.md index 8b076701f1..5c0eda0d09 100644 --- a/docs/reference/action-types/Run/exec.md +++ b/docs/reference/action-types/Run/exec.md @@ -128,6 +128,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Run/helm-pod.md b/docs/reference/action-types/Run/helm-pod.md index 11020bb35a..fc88487e5e 100644 --- a/docs/reference/action-types/Run/helm-pod.md +++ b/docs/reference/action-types/Run/helm-pod.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Run/kubernetes-exec.md b/docs/reference/action-types/Run/kubernetes-exec.md index 58ee22ab7c..116d88fd9d 100644 --- a/docs/reference/action-types/Run/kubernetes-exec.md +++ b/docs/reference/action-types/Run/kubernetes-exec.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Run/kubernetes-pod.md b/docs/reference/action-types/Run/kubernetes-pod.md index e4f98b44a7..0db564b175 100644 --- a/docs/reference/action-types/Run/kubernetes-pod.md +++ b/docs/reference/action-types/Run/kubernetes-pod.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/conftest-helm.md b/docs/reference/action-types/Test/conftest-helm.md index 7c164e19b4..57551547a1 100644 --- a/docs/reference/action-types/Test/conftest-helm.md +++ b/docs/reference/action-types/Test/conftest-helm.md @@ -134,6 +134,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/conftest.md b/docs/reference/action-types/Test/conftest.md index e25cc3013c..56c43f1584 100644 --- a/docs/reference/action-types/Test/conftest.md +++ b/docs/reference/action-types/Test/conftest.md @@ -132,6 +132,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/container.md b/docs/reference/action-types/Test/container.md index f52b278931..e210dcc8cd 100644 --- a/docs/reference/action-types/Test/container.md +++ b/docs/reference/action-types/Test/container.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/exec.md b/docs/reference/action-types/Test/exec.md index f20c00451d..e3e7710b9b 100644 --- a/docs/reference/action-types/Test/exec.md +++ b/docs/reference/action-types/Test/exec.md @@ -128,6 +128,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/hadolint.md b/docs/reference/action-types/Test/hadolint.md index f610c4e0fb..976a9e8682 100644 --- a/docs/reference/action-types/Test/hadolint.md +++ b/docs/reference/action-types/Test/hadolint.md @@ -134,6 +134,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/helm-pod.md b/docs/reference/action-types/Test/helm-pod.md index b456ce6fb9..e4a949cae6 100644 --- a/docs/reference/action-types/Test/helm-pod.md +++ b/docs/reference/action-types/Test/helm-pod.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/kubernetes-exec.md b/docs/reference/action-types/Test/kubernetes-exec.md index 3b43485572..05c4e42a0d 100644 --- a/docs/reference/action-types/Test/kubernetes-exec.md +++ b/docs/reference/action-types/Test/kubernetes-exec.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/action-types/Test/kubernetes-pod.md b/docs/reference/action-types/Test/kubernetes-pod.md index c62a8ca283..b53261f4ef 100644 --- a/docs/reference/action-types/Test/kubernetes-pod.md +++ b/docs/reference/action-types/Test/kubernetes-pod.md @@ -130,6 +130,14 @@ For other action kinds, the action is skipped in all scenarios, and dependency d | --------- | ------- | -------- | | `boolean` | `false` | No | +### `environments[]` + +If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is equivalent to `disabled: ${environment.name != "prod"}`. + +| Type | Required | +| --------------- | -------- | +| `array[string]` | No | + ### `include[]` Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus will affect the computed _version_ of the action. diff --git a/docs/reference/commands.md b/docs/reference/commands.md index 6832094cf0..b1e1bbb8f5 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -1803,6 +1803,11 @@ actionConfigs: # conditional expressions. disabled: + # If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand + # for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is + # equivalent to `disabled: ${environment.name != "prod"}`. + environments: + # A map of variables scoped to this particular action. These are resolved before any other parts of the action # configuration and take precedence over group-scoped variables (if applicable) and project-scoped variables, in # that order. They may reference group-scoped and project-scoped variables, and generally can use any template @@ -1973,6 +1978,11 @@ actionConfigs: # conditional expressions. disabled: + # If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand + # for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is + # equivalent to `disabled: ${environment.name != "prod"}`. + environments: + # Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus # will affect the computed _version_ of the action. # @@ -2113,6 +2123,11 @@ actionConfigs: # conditional expressions. disabled: + # If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand + # for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is + # equivalent to `disabled: ${environment.name != "prod"}`. + environments: + # Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus # will affect the computed _version_ of the action. # @@ -2253,6 +2268,11 @@ actionConfigs: # conditional expressions. disabled: + # If set, the action is only enabled for the listed environment types. This is effectively a cleaner shorthand + # for the `disabled` field with an expression for environments. For example, `environments: ["prod"]` is + # equivalent to `disabled: ${environment.name != "prod"}`. + environments: + # Specify a list of POSIX-style paths or globs that should be regarded as source files for this action, and thus # will affect the computed _version_ of the action. # diff --git a/examples/disabled-configs/README.md b/examples/disabled-configs/README.md index b01d07c5ee..2069ada0cb 100644 --- a/examples/disabled-configs/README.md +++ b/examples/disabled-configs/README.md @@ -20,7 +20,7 @@ And the `frontend` config like this: kind: Test name: frontend-integ type: container -disabled: ${environment.name == local} +environments: [remote] # <- Here we use the environments field instead of the expression above # ... spec: command: [npm, run, integ] diff --git a/examples/disabled-configs/frontend/garden.yml b/examples/disabled-configs/frontend/garden.yml index e356ec98f3..9119b6d1b0 100644 --- a/examples/disabled-configs/frontend/garden.yml +++ b/examples/disabled-configs/frontend/garden.yml @@ -47,7 +47,8 @@ type: container build: frontend dependencies: - deploy.frontend -disabled: ${environment.name == "local"} + +environments: [remote] # <- enabling only for the "remote" environment spec: command: [ npm, run, integ ]