Skip to content

Commit

Permalink
fix(core): fix config error when using project.modules (#5626)
Browse files Browse the repository at this point in the history
Before this fix, an error would be thrown if using `scan.git.mode` and
`module.include` or `module.exclude` together (since the Joi helper for
renaming fields fails if there's already a value at the destination).
  • Loading branch information
thsig committed Jan 15, 2024
1 parent 68ad763 commit 4d017e4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
14 changes: 14 additions & 0 deletions core/src/config/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,20 @@ function handleProjectModules(log: Log, projectSpec: ProjectConfig): ProjectConf
log,
"Project configuration field `modules` is deprecated in 0.13 and will be removed in 0.14. Please use the `scan` field instead."
)
const scanConfig = projectSpec.scan || {}
for (const key of ["include", "exclude"]) {
if (projectSpec["modules"][key]) {
if (!scanConfig[key]) {
scanConfig[key] = projectSpec["modules"][key]
} else {
log.warn(
`Project-level \`${key}\` is set both in \`modules.${key}\` and \`scan.${key}\`. The value from \`scan.${key}\` will be used (and the value from \`modules.${key}\` will not have any effect).`
)
}
}
}
projectSpec.scan = scanConfig
delete projectSpec["modules"]
}

return projectSpec
Expand Down
5 changes: 2 additions & 3 deletions core/src/config/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { memoize } from "lodash-es"
import type { GenericProviderConfig } from "./provider.js"
import { providerConfigBaseSchema } from "./provider.js"
import type { GitScanMode } from "../constants.js"
import { DOCS_BASE_URL, GardenApiVersion, gitScanModes } from "../constants.js"
import { DOCS_BASE_URL, GardenApiVersion, defaultGitScanMode, gitScanModes } from "../constants.js"
import { defaultDotIgnoreFile } from "../util/fs.js"
import type { CommandInfo } from "../plugin-context.js"
import type { VcsInfo } from "../vcs/vcs.js"
Expand Down Expand Up @@ -267,7 +267,7 @@ const projectScanSchema = createSchema({
.string()
.allow(...gitScanModes)
.only()
.default("subtree")
.default(defaultGitScanMode)
.description(
"Choose how to perform scans of git repositories. The default (`subtree`) runs individual git scans on each action/module path. The `repo` mode scans entire repositories and then filters down to files matching the paths, includes and excludes for each action/module. This can be considerably more efficient for large projects with many actions/modules."
),
Expand Down Expand Up @@ -424,7 +424,6 @@ export const projectSchema = createSchema({
"Key/value map of variables to configure for all environments. " + joiVariablesDescription
),
}),
rename: [["modules", "scan"]],
})

export function getDefaultEnvironmentName(defaultName: string, config: ProjectConfig): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ environments:
- name: local
providers:
- name: test-plugin
# We use the old `modules.<include|exclude>` fields to test the renaming/moving of the fields to
# `scan.<include|exclude>` during project config preprocessing (see the `prepareProjectResource` helper).
scan:
git:
mode: repo
modules:
include:
- module*/**/*
exclude:
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/project-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ scan:
# action/module path. The `repo` mode scans entire repositories and then filters down to files matching the paths,
# includes and excludes for each action/module. This can be considerably more efficient for large projects with
# many actions/modules.
mode: subtree
mode: repo

# A list of output values that the project should export. These are exported by the `garden get outputs` command, as
# well as when referencing a project as a sub-project within another project.
Expand Down Expand Up @@ -578,9 +578,9 @@ scan:

Choose how to perform scans of git repositories. The default (`subtree`) runs individual git scans on each action/module path. The `repo` mode scans entire repositories and then filters down to files matching the paths, includes and excludes for each action/module. This can be considerably more efficient for large projects with many actions/modules.

| Type | Allowed Values | Default | Required |
| -------- | ----------------- | ----------- | -------- |
| `string` | "repo", "subtree" | `"subtree"` | Yes |
| Type | Allowed Values | Default | Required |
| -------- | ----------------- | -------- | -------- |
| `string` | "repo", "subtree" | `"repo"` | Yes |

### `outputs[]`

Expand Down

0 comments on commit 4d017e4

Please sign in to comment.