Skip to content

Commit

Permalink
Merge branch 'master' into fix-terraform-cmd-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored Apr 8, 2020
2 parents ccd2ecc + 006ad98 commit a7b339c
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 82 deletions.
212 changes: 212 additions & 0 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion garden-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"winston": "^3.2.1",
"wrap-ansi": "^6.2.0",
"ws": "^7.2.1",
"xml-js": "^1.6.11"
"xml-js": "^1.6.11",
"yaml-lint": "^1.2.4"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
Expand Down
17 changes: 5 additions & 12 deletions garden-service/src/commands/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
*/

import { Command, CommandParams, CommandResult, BooleanParameter, StringsParameter } from "./base"
import yaml, { safeDump } from "js-yaml"
import { safeDump } from "js-yaml"
import { dedent } from "../util/string"
import { readFile, writeFile } from "fs-extra"
import { cloneDeep, isEqual } from "lodash"
import { ConfigurationError, RuntimeError } from "../exceptions"
import { basename, resolve, parse } from "path"
import { resolve, parse } from "path"
import { findConfigPathsInPath, getConfigFilePath } from "../util/fs"
import { GitHandler } from "../vcs/git"
import { DEFAULT_GARDEN_DIR_NAME } from "../constants"
import { exec } from "../util/util"
import { LoggerType } from "../logger/logger"
import Bluebird from "bluebird"
import { loadAndValidateYaml } from "../config/base"

const migrateOptions = {
write: new BooleanParameter({ help: "Update the `garden.yml` in place." }),
Expand Down Expand Up @@ -196,17 +197,9 @@ async function findRoot(path: string): Promise<string | null> {
* Read the contents of a YAML file and dump to JSON
*/
async function readYaml(path: string) {
let rawSpecs: any[]
const fileData = await readFile(path)

try {
rawSpecs = yaml.safeLoadAll(fileData.toString()) || []
} catch (err) {
throw new ConfigurationError(`Could not parse ${basename(path)} in directory ${path} as valid YAML`, err)
}

// Ignore empty resources
return rawSpecs.filter(Boolean)
const rawSpecs = await loadAndValidateYaml(fileData.toString(), path)
return rawSpecs.filter(Boolean) // Ignore empty resources
}

/**
Expand Down
16 changes: 3 additions & 13 deletions garden-service/src/config-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import { TestConfig } from "./config/test"
import { uniqByName, pickKeys } from "./util/util"
import { ConfigurationError } from "./exceptions"
import { deline } from "./util/string"
import {
detectMissingDependencies,
handleDependencyErrors,
DependencyValidationGraph,
} from "./util/validate-dependencies"
import { detectMissingDependencies, DependencyValidationGraph } from "./util/validate-dependencies"
import { ServiceConfig } from "./config/service"
import { TaskConfig } from "./config/task"
import { makeTestTaskName } from "./tasks/helpers"
Expand Down Expand Up @@ -167,7 +163,7 @@ export class ConfigGraph {
}
}

const missingDepsError = detectMissingDependencies(Object.values(this.modules))
detectMissingDependencies(Object.values(this.modules))

// Add relations between nodes
for (const module of modules) {
Expand Down Expand Up @@ -267,17 +263,11 @@ export class ConfigGraph {
const validationGraph = DependencyValidationGraph.fromDependencyGraph(this.dependencyGraph)
const cycles = validationGraph.detectCircularDependencies()

let circularDepsError
if (cycles.length > 0) {
const description = validationGraph.cyclesToString(cycles)
const errMsg = `\nCircular dependencies detected: \n\n${description}\n`
circularDepsError = new ConfigurationError(errMsg, { "circular-dependencies": description })
} else {
circularDepsError = null
throw new ConfigurationError(errMsg, { "circular-dependencies": description })
}

// Throw an error if one or both of these errors is non-null.
handleDependencyErrors(missingDepsError, circularDepsError)
}

// Convenience method used in the constructor above.
Expand Down
Loading

0 comments on commit a7b339c

Please sign in to comment.