Skip to content

Commit

Permalink
fix(core): fix to task deps for DeployTask
Browse files Browse the repository at this point in the history
`DeployTask`'s `getDependencies` method now always returns task
dependencies initialized with `force = false`.

The underlying semantic is that unless the task dependency's module
sources have changed, there's no need to re-run them when
force-deploying the dependant service.

I.e. the decision to run or not run the task dependency is delegated to
the `TaskTask` in the normal way.
  • Loading branch information
thsig authored and edvald committed Feb 20, 2020
1 parent 1eda1d1 commit 9b35d74
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 107 deletions.
75 changes: 52 additions & 23 deletions garden-service/src/commands/dev.ts
Expand Up @@ -34,6 +34,8 @@ import { getHotReloadServiceNames, validateHotReloadServiceNames } from "./helpe
import { GardenServer, startServer } from "../server/server"
import { BuildTask } from "../tasks/build"
import { DeployTask } from "../tasks/deploy"
import { Garden } from "../garden"
import { LogEntry } from "../logger/log-entry"

const ansiBannerPath = join(STATIC_DIR, "garden-banner-2.txt")

Expand Down Expand Up @@ -184,41 +186,68 @@ export class DevCommand extends Command<DevCommandArgs, DevCommandOpts> {
watch: true,
initialTasks,
changeHandler: async (updatedGraph: ConfigGraph, module: Module) => {
const tasks = await getModuleWatchTasks({
return getDevCommandWatchTasks({
garden,
log,
graph: updatedGraph,
updatedGraph,
module,
hotReloadServiceNames,
testNames: opts["test-names"],
skipTests,
})

if (!skipTests) {
const filterNames = opts["test-names"]
const testModules: Module[] = await updatedGraph.withDependantModules([module])
tasks.push(
...flatten(
await Bluebird.map(testModules, (m) =>
getTestTasks({
garden,
log,
module: m,
graph: updatedGraph,
filterNames,
hotReloadServiceNames,
})
)
)
)
}

return tasks
},
})

return handleTaskResults(footerLog, "dev", results)
}
}

export async function getDevCommandWatchTasks({
garden,
log,
updatedGraph,
module,
hotReloadServiceNames,
testNames,
skipTests,
}: {
garden: Garden
log: LogEntry
updatedGraph: ConfigGraph
module: Module
hotReloadServiceNames: string[]
testNames: string[] | undefined
skipTests: boolean
}) {
const tasks = await getModuleWatchTasks({
garden,
log,
graph: updatedGraph,
module,
hotReloadServiceNames,
})

if (!skipTests) {
const testModules: Module[] = await updatedGraph.withDependantModules([module])
tasks.push(
...flatten(
await Bluebird.map(testModules, (m) =>
getTestTasks({
garden,
log,
module: m,
graph: updatedGraph,
filterNames: testNames,
hotReloadServiceNames,
})
)
)
)
}

return tasks
}

function getGreetingTime() {
const m = moment()

Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/tasks/deploy.ts
Expand Up @@ -124,7 +124,7 @@ export class DeployTask extends BaseTask {
garden: this.garden,
log: this.log,
graph: this.graph,
force: this.force,
force: false,
forceBuild: this.forceBuild,
})
})
Expand Down
41 changes: 40 additions & 1 deletion garden-service/test/unit/src/commands/dev.ts
Expand Up @@ -8,7 +8,7 @@

import pEvent from "p-event"
import { expect } from "chai"
import { DevCommand, DevCommandArgs, DevCommandOpts } from "../../../../src/commands/dev"
import { DevCommand, DevCommandArgs, DevCommandOpts, getDevCommandWatchTasks } from "../../../../src/commands/dev"
import { makeTestGardenA, withDefaultGlobalOpts, TestGarden } from "../../../helpers"
import { ParameterValues } from "../../../../src/commands/base"
import { GlobalOptions } from "../../../../src/cli/cli"
Expand Down Expand Up @@ -233,3 +233,42 @@ describe("DevCommand", () => {
return promise
})
})

describe("getDevCommandWatchTasks", () => {
it("should deploy, run and test appropriately on watch change", async () => {
const garden = await makeTestGardenA()
const log = garden.log
const graph = await garden.getConfigGraph(log)

const watchTasks = await getDevCommandWatchTasks({
garden,
log,
updatedGraph: graph,
module: await graph.getModule("module-b"),
hotReloadServiceNames: [],
testNames: undefined,
skipTests: false,
})

const results = await garden.processTasks(watchTasks)
expect(Object.keys(results).sort()).to.eql([
"build.module-a",
"build.module-b",
"build.module-c",
"deploy.service-a",
"deploy.service-b",
"deploy.service-c",
"get-service-status.service-a",
"get-service-status.service-b",
"get-service-status.service-c",
"get-task-result.task-c",
"stage-build.module-a",
"stage-build.module-b",
"stage-build.module-c",
"task.task-c",
"test.module-b.unit",
"test.module-c.integ",
"test.module-c.unit",
])
})
})

0 comments on commit 9b35d74

Please sign in to comment.