Created
February 25, 2025 19:03
-
-
Save levancho/848699b072ffea0cc251963c547898d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const yaml = require('js-yaml'); | |
// Paths to files | |
const versionTagPath = path.join(__dirname, 'version-tag'); | |
const packageJsonPath = path.join(__dirname, 'package.json'); | |
const devYamlPath = path.join(__dirname, 'html/environments/dev.yaml'); | |
// Read version from version-tag file | |
const version = fs.readFileSync(versionTagPath, 'utf-8').trim(); | |
if (!version) { | |
console.error('No version found in version-tag file'); | |
process.exit(1); | |
} | |
// Update package.json | |
try { | |
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); | |
packageJson.version = version; | |
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); | |
console.log(`Updated package.json to version ${version}`); | |
} catch (e) { | |
console.error(`Failed to update package.json: ${e.message}`); | |
} | |
// Update dev.yaml | |
try { | |
const devYamlContent = fs.readFileSync(devYamlPath, 'utf-8'); | |
const devYaml = yaml.load(devYamlContent); | |
// Assuming the 'image' key exists at the root level | |
if (devYaml.image) { | |
// Replace the version number in the image string | |
devYaml.image = devYaml.image.replace(/:[^:]+$/, `:${version}`); | |
const newYamlContent = yaml.dump(devYaml, { lineWidth: -1 }); | |
fs.writeFileSync(devYamlPath, newYamlContent, 'utf-8'); | |
console.log(`Updated dev.yaml to version ${version}`); | |
} else { | |
console.error('No image key found in dev.yaml'); | |
} | |
} catch (e) { | |
console.error(`Failed to update dev.yaml: ${e.message}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment