From d6c58d6eb47f3332db1481555b9a65d20cc92a65 Mon Sep 17 00:00:00 2001 From: Tuncion Date: Sun, 8 Dec 2024 17:03:09 +0100 Subject: [PATCH] Added pipeline option hotfix or release --- .github/actions/update-manifest-data.js | 50 ++++++++++++++++--------- .github/workflows/release.yml | 11 +++++- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/.github/actions/update-manifest-data.js b/.github/actions/update-manifest-data.js index 1655683..7b51b3a 100644 --- a/.github/actions/update-manifest-data.js +++ b/.github/actions/update-manifest-data.js @@ -7,7 +7,7 @@ const fs = require("fs"); const { execSync, exec } = require("child_process"); (async () => { - const ReleaseType = process.env.RELEASE_TYPE; + const ReleaseType = process.env.RELEASE_TYPE || 'Release'; let ManifestFile = fs.readFileSync("fxmanifest.lua", { encoding: "utf8" }); // Patch Version @@ -20,7 +20,7 @@ const { execSync, exec } = require("child_process"); // Version const Version = ManifestFile.match(/\bversion\s+["']?([\d.]+)["']?/)[1] || "1.0.0"; - const NewVersion = NextVersionNo(Version); + const NewVersion = NextVersionNo(Version, ReleaseType); execSync(`RELEASE_VERSION=${NewVersion}\necho "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV`); @@ -53,23 +53,37 @@ const { execSync, exec } = require("child_process"); })(); /** - * Increments the given version number by one patch version. - * If the patch version exceeds 9, it resets to 0 and increments the minor version. - * If the minor version exceeds 9, it resets to 0 and increments the major version. + * Increments the given version number based on the update type. + * - "Release" updates follow the schema X.X.X. + * - "Hotfix" updates follow the schema X.X.X.X. * - * @param {string} version - The current version number in the format "major.minor.patch". - * @returns {string} - The next version number in the format "major.minor.patch". + * @param {string} version - The current version number. + * @param {string} updateType - The type of update ("Release" or "Hotfix"). + * @returns {string} - The next version number. */ -function NextVersionNo(version) { - let [major, minor, patch] = version.split(".").map(Number); - patch++; - if (patch > 9) { - patch = 0; - minor++; - } - if (minor > 9) { - minor = 0; - major++; +function NextVersionNo(version, updateType) { + let parts = version.split(".").map(Number); + + if (updateType.toLowerCase() === "release") { + // Ensure the version has 3 parts for release schema + while (parts.length < 3) parts.push(0); + let [major, minor, patch] = parts; + patch++; + if (patch > 9) { + patch = 0; + minor++; + } + if (minor > 9) { + minor = 0; + major++; + } + return `${major}.${minor}.${patch}`; + } else if (updateType.toLowerCase() === "hotfix") { + while (parts.length < 4) parts.push(0); + let [major, minor, patch, hotfix] = parts; + hotfix++; + return `${major}.${minor}.${patch}.${hotfix}`; + } else { + throw new Error("Invalid update type. Use 'Release' or 'Hotfix'."); } - return `${major}.${minor}.${patch}`; } \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f2a9c74..39f149d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,14 @@ on: branches: - main workflow_dispatch: - + inputs: + update_type: + description: "Select the type of update" + required: true + type: choice + options: + - Hotfix + - Release env: REPOSITORY_NAME: ${{ github.event.repository.name }} @@ -52,7 +59,7 @@ jobs: - name: Update Manifest Data run: node .github/actions/update-manifest-data.js env: - RELEASE_TYPE: release + RELEASE_TYPE: ${{ github.event.inputs.update_type }} RELEASE_USER: ${{ github.actor }} RELEASE_PATCH: ${{ env.COMMIT_COUNT }}