Skip to content

Commit

Permalink
Added pipeline option hotfix or release
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuncion committed Dec 8, 2024
1 parent f9f4056 commit d6c58d6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
50 changes: 32 additions & 18 deletions .github/actions/update-manifest-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`);

Expand Down Expand Up @@ -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}`;
}
11 changes: 9 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down Expand Up @@ -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 }}

Expand Down

0 comments on commit d6c58d6

Please sign in to comment.