From f4fba91ca8084431b5f143e51df8c58dba0fb408 Mon Sep 17 00:00:00 2001 From: IhsenBouallegue Date: Fri, 13 Dec 2024 12:08:47 +0100 Subject: [PATCH] feat(config): refactor version update command and improve error handling in script --- .github/workflows/prepare-release.yml | 2 +- script/version-manager.ts | 31 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index c045ae2632..19380eef0d 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -39,7 +39,7 @@ jobs: id: version run: | set -e # Exit immediately if a command exits with a non-zero status - NEW_VERSION=$(bun script/version-manager.ts ${{ inputs.repository }} ${{ inputs.version_type }}) + NEW_VERSION=$(bun script/version-manager.ts update-version ${{ inputs.repository }} ${{ inputs.version_type }}) if [ $? -ne 0 ]; then echo "::error::Version manager failed" exit 1 diff --git a/script/version-manager.ts b/script/version-manager.ts index 2a87cf5206..75a415ee7c 100644 --- a/script/version-manager.ts +++ b/script/version-manager.ts @@ -236,18 +236,25 @@ if (import.meta.main) { const [command, ...args] = process.argv.slice(2) const manager = new VersionManager() - if (command === "extract-changelog") { - if (args.length !== 1) { - console.error("Usage: bun script/version-manager.ts extract-changelog ") - process.exit(1) - } - process.stdout.write(manager.extractChangelog(args[0])) - } else { - // existing version update logic - if (args.length !== 2) { - console.error("Usage: bun script/version-manager.ts ") + switch (command) { + case "extract-changelog": + if (args.length !== 1) { + console.error("Usage: bun script/version-manager.ts extract-changelog ") + process.exit(1) + } + process.stdout.write(manager.extractChangelog(args[0])) + break + + case "update-version": + if (args.length !== 2) { + console.error("Usage: bun script/version-manager.ts update-version ") + process.exit(1) + } + process.stdout.write(manager.updateVersion(args[0], args[1])) + break + + default: + console.error("Unknown command. Available commands: extract-changelog, update-version") process.exit(1) - } - process.stdout.write(manager.updateVersion(args[0], args[1])) } }