fix(ci): fix the version update scripts for pre-releases
MODIFY
.github/workflows/release_cli.yml
.github/workflows/release_cli.yml
@@ -93,7 +93,7 @@ jobs:
if: needs.check.outputs.prerelease == 'true'
run: |
echo "prerelease=true" >> $GITHUB_ENV
- node npm/rome/scripts/update-nightly-version.mjs >> $GITHUB_ENV
+ echo "version=$(node npm/rome/scripts/update-nightly-version.mjs)" >> $GITHUB_ENV
- name: Set release infos
if: needs.check.outputs.prerelease != 'true'
run: |

MODIFY
.github/workflows/release_lsp.yml
.github/workflows/release_lsp.yml
@@ -56,7 +56,7 @@ jobs:
if: env.nightly == 'true' || steps.version.outputs.type == 'prerelease' || steps.version.outputs.type == 'prepatch' || steps.version.outputs.type == 'premajor' || steps.version.outputs.type == 'preminor'
run: |
echo "prerelease=true" >> $GITHUB_ENV
- echo "version=$(node ./editors/vscode/scripts/updateVersionForPrerelease.mjs)" >> $GITHUB_ENV
+ node ./editors/vscode/scripts/update-nightly-version.mjs >> $GITHUB_ENV
echo "rome_version=$(node ./npm/rome/scripts/update-nightly-version.mjs)" >> $GITHUB_ENV
- name: Check version status
@@ -149,7 +149,7 @@ jobs:
if: needs.check.outputs.prerelease == 'true'
working-directory: editors/vscode
run: |
- node ./scripts/updateVersionForPrerelease.mjs >> $GITHUB_ENV
+ node ./scripts/update-nightly-version.mjs >> $GITHUB_ENV
echo "prerelease=true" >> $GITHUB_ENV
- name: Set release infos
if: needs.check.outputs.prerelease != 'true'

MODIFY
editors/vscode/scripts/update-nightly-version.mjs
editors/vscode/scripts/update-nightly-version.mjs
-import { resolve } from "node:path";
+import { readFile, writeFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
-import * as fs from "node:fs";
-
-const ROMECLI_ROOT = resolve(fileURLToPath(import.meta.url), "../");
-const MANIFEST_PATH = resolve(ROMECLI_ROOT, "package.json");
+import { resolve } from "node:path";
-const rootManifest = JSON.parse(
- fs.readFileSync(MANIFEST_PATH).toString("utf-8"),
-);
+const EXTENSION_ROOT = resolve(fileURLToPath(import.meta.url), "../..");
+const MANIFEST_PATH = resolve(EXTENSION_ROOT, "package.json");
-let version = rootManifest["version"];
-if (
- typeof process.env.GITHUB_SHA !== "string" ||
- process.env.GITHUB_SHA === ""
-) {
- throw new Error("GITHUB_SHA environment variable is undefined");
+function pad(date) {
+ if (date < 10) {
+ return `0${date}`;
+ }
+ return `${date}`;
}
-version += `.${process.env.GITHUB_SHA.substring(0, 7)}`;
-rootManifest["version"] = version;
-
-const content = JSON.stringify(rootManifest);
-fs.writeFileSync(MANIFEST_PATH, content);
+// read the package.json file
+readFile(MANIFEST_PATH, "utf8")
+ .then(async (value) => {
+ const manifest = JSON.parse(value);
+ const currentVersion = manifest.version;
+ const versionAsSemver = currentVersion.split(".");
+ // first one is the major
+ const currentMajor = parseInt(versionAsSemver[0]);
+ // second one is the minor
+ const currentMinor = parseInt(versionAsSemver[1]);
-console.log(`version=${version}`);
+ const date = new Date();
+ const newMinor = currentMinor + 1;
+ const newPatch = [
+ pad(date.getFullYear()),
+ pad(date.getMonth() + 1),
+ pad(date.getDate()),
+ ].join("");
+ // update the version field
+ manifest.version = `${currentMajor}.${newMinor}.${newPatch}`;
+ try {
+ await writeFile(MANIFEST_PATH, JSON.stringify(manifest, null, "\t"));
+ console.log(`version=${manifest.version}`);
+ } catch {
+ console.log(`Could not write the package.json file at ${MANIFEST_PATH}`);
+ process.exit(1);
+ }
+ })
+ .catch(() => {
+ console.log(`Could not read the package.json file at ${MANIFEST_PATH}`);
+ process.exit(1);
+ });

MODIFY
npm/rome/scripts/update-nightly-version.mjs
npm/rome/scripts/update-nightly-version.mjs
@@ -24,4 +24,4 @@ rootManifest["version"] = version;
const content = JSON.stringify(rootManifest);
fs.writeFileSync(MANIFEST_PATH, content);
-console.log(`version=${version}`);
+console.log(version);

fix(ci): fix the version update scripts for pre-releases (#3484)