Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): fix config error when using project.modules #5626

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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