Skip to content

Commit

Permalink
fix(core): fix config error when using project.modules
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 11, 2024
1 parent f2236b2 commit 953dc1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 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

0 comments on commit 953dc1d

Please sign in to comment.