Skip to content

Commit

Permalink
fix(core): more narrow set of config fields to hash for module versions
Browse files Browse the repository at this point in the history
Cherry-picked from commits:
(cherry picked from commit c17a6cf)
(cherry picked from commit 57d884a)

---------

Co-authored-by: Vladimir Vagaytsev <vladimir.vagaitsev@gmail.com>
  • Loading branch information
edvald and vvagaytsev committed Oct 5, 2023
1 parent 66f0b1f commit a34bc42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions core/src/vcs/vcs.ts
Expand Up @@ -8,7 +8,7 @@

import Joi from "@hapi/joi"
import normalize = require("normalize-path")
import { sortBy, omit } from "lodash"
import { sortBy, pick } from "lodash"
import { createHash } from "crypto"
import { validateSchema } from "../config/validation"
import { join, relative, isAbsolute } from "path"
Expand Down Expand Up @@ -294,7 +294,7 @@ export function hashModuleVersion(
// build output.
const configToHash =
moduleConfig.buildConfig ||
omit(moduleConfig, ["configPath", "path", "outputs", "serviceConfigs", "taskConfigs", "testConfigs"])
pick(moduleConfig, ["apiVersion", "name", "spec", "type", "variables", "varfile", "inputs"])

const configString = serializeConfig(configToHash)

Expand Down
16 changes: 11 additions & 5 deletions core/test/unit/src/garden.ts
Expand Up @@ -53,6 +53,7 @@ import execa from "execa"
import { getLinkedSources, addLinkedSources } from "../../../src/util/ext-source-util"
import { safeDump } from "js-yaml"
import { TestVcsHandler } from "./vcs/vcs"
import { TreeCache } from "../../../src/cache"

describe("Garden", () => {
let tmpDir: tmp.DirectoryResult
Expand Down Expand Up @@ -4533,16 +4534,21 @@ describe("Garden", () => {
gardenA.projectRoot,
join(gardenA.projectRoot, ".garden"),
defaultDotIgnoreFiles,
gardenA.cache
new TreeCache()
)
})

it("should return module version if there are no dependencies", async () => {
const module = await gardenA.resolveModule("module-a")
gardenA.vcs = handlerA
const result = await gardenA.resolveModuleVersion(gardenA.log, module, [])

// We use resolveTreeVersion here (against getTreeVersion in 0.13),
// because in 0.12 we do support and use version files. In 0.13 version files are no longer used.
const treeVersion = await handlerA.resolveTreeVersion(gardenA.log, gardenA.projectName, module)

expect(result).to.eql({
versionString: getModuleVersionString(module, { ...treeVersionA, name: "module-a" }, []),
versionString: getModuleVersionString(module, { ...treeVersion, name: "module-a" }, []),
dependencyVersions: {},
files: [],
})
Expand Down Expand Up @@ -4631,9 +4637,9 @@ describe("Garden", () => {
})

context("test against fixed version hashes", async () => {
const moduleAVersionString = "v-48acad3a28"
const moduleBVersionString = "v-68d89c8275"
const moduleCVersionString = "v-68421fafcc"
const moduleAVersionString = "v-65a5457ccb"
const moduleBVersionString = "v-d12dbfae8b"
const moduleCVersionString = "v-c1fd644d0e"

it("should return the same module versions between runtimes", async () => {
const projectRoot = getDataDir("test-projects", "fixed-version-hashes-1")
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/src/vcs/vcs.ts
Expand Up @@ -366,7 +366,7 @@ describe("getModuleVersionString", () => {
const garden = await makeTestGarden(projectRoot, { noCache: true })
const module = await garden.resolveModule("module-a")

const fixedVersionString = "v-48acad3a28"
const fixedVersionString = "v-65a5457ccb"
expect(module.version.versionString).to.eql(fixedVersionString)

delete process.env.TEST_ENV_VAR
Expand Down

0 comments on commit a34bc42

Please sign in to comment.