Skip to content

Commit

Permalink
chore: fix edge version (#5440)
Browse files Browse the repository at this point in the history
Currently edge versions pretend to be production version.

This commit fixes that, to ensure that we do not confuse edge builds
with production builds and to ensure that our analytics is correct.
  • Loading branch information
stefreak authored Nov 17, 2023
1 parent 714c1dc commit c0d1ff5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
23 changes: 17 additions & 6 deletions cli/src/build-pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,19 @@ async function zipAndHash({ targetDir, archiveName, cwd, prefix, fileNames }: Zi

async function buildBinaries(args: string[]) {
const argv = minimist(args)
const version = argv.version || getPackageVersion()

let version: string

if (argv.version === "edge" || argv.version.startsWith("edge-")) {
const gitHash = await exec("git", ["rev-parse", "--short", "HEAD"])
version = `${getPackageVersion()}-${argv.version}-${gitHash.stdout}`
} else if (argv.version) {
console.log(`Cannot set Garden to version ${argv.version}. Please update the package.json files instead.`)
process.exit(1)
} else {
version = getPackageVersion()
}

const selected = argv._.length > 0 ? pick(targets, argv._) : targets

if (Object.keys(selected).length === 0) {
Expand Down Expand Up @@ -271,10 +283,9 @@ async function buildBinaries(args: string[]) {
packageJson.dependencies[depName] = "file:" + relPath
}

if (version === "edge" || version.startsWith("edge-")) {
const gitHash = await exec("git", ["rev-parse", "--short", "HEAD"])
packageJson.version = `${packageJson.version}-${version}-${gitHash.stdout}`
console.log("Set package version to " + packageJson.version)
if (version) {
packageJson.version = version
console.log(`Updated version to ${packageJson.version} in ${packageJsonPath}`)
}

await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
Expand All @@ -299,7 +310,7 @@ async function buildBinaries(args: string[]) {
console.log(chalk.cyan("Bundling source code"))

await remove(rollupTmpDir)
await exec("npm", ["run", "rollup"], { cwd: repoRoot, stdio: "inherit" })
await exec("npm", ["run", "rollup"], { cwd: repoRoot, stdio: "inherit", env: { GARDEN_CORE_VERSION: version } })

await zipAndHash({
archiveName: "source",
Expand Down
1 change: 1 addition & 0 deletions core/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function registerCleanupFunction(name: string, func: HookCallback) {
}

export function getPackageVersion(): string {
// This code will be replaced by the version number during the build process in rollup.config.js. Please update the rollup config as well if you change the following line.
const { version } = corePackageJson as { version: string }
return version
}
Expand Down
12 changes: 10 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ export default {
}
}
},

// we import the package.json file for version number detection
// Hack: Replace version in `getPackageVersion()` function, because the `json()` plugin below somehow loads the wrong package.json file.
replace({
include: [/core.*\.js/],
values: {
"const { version } = corePackageJson": `const version = ${JSON.stringify(process.env.GARDEN_CORE_VERSION || "0.0.0-dev")}`,
},
delimiters: ["", ""],
}),
// we import the package.json file for version number detection, but for some reasons rollup reads the package.json files in ./ instead of in ./garden-sea/tmp/source/
// That's why we also need the hack above unfortunately...
json(),

// NOTE: You may need the following hacks if we ever decide to update ink to the latest version
Expand Down

0 comments on commit c0d1ff5

Please sign in to comment.