From 7b23dda06c776acc7277192ec3bb5dd8258ed698 Mon Sep 17 00:00:00 2001 From: MasterLaplace Date: Fri, 20 Oct 2023 06:44:05 +0200 Subject: [PATCH] feat(worflows): implement workflows to increment the current version in code --- .github/workflows/increment_major.yml | 66 +++++++++++++++++++++++++++ .github/workflows/increment_minor.yml | 60 ++++++++++++++++++++++++ .github/workflows/increment_patch.yml | 60 ++++++++++++++++++++++++ Engine/Config/Version/version.h | 2 +- VERSION | 2 +- 5 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/increment_major.yml create mode 100644 .github/workflows/increment_minor.yml create mode 100644 .github/workflows/increment_patch.yml diff --git a/.github/workflows/increment_major.yml b/.github/workflows/increment_major.yml new file mode 100644 index 0000000..1ef2555 --- /dev/null +++ b/.github/workflows/increment_major.yml @@ -0,0 +1,66 @@ +name: Increment Major Version + +on: + pull_request: + branches: + - 'main' + - 'master' + - 'release' + - 'release/*' + +jobs: + increment_major_version: + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Increment Major Version + run: | + # Get the latest tag from the repository + latest_tag=$(git describe --tags --abbrev=0) + + # Extract the major, minor, and patch versions from the tag + regex="([0-9]+)\.([0-9]+)\.([0-9]+)" + if [[ $latest_tag =~ $regex ]]; then + major_version="${BASH_REMATCH[1]}" + old_major_version="${BASH_REMATCH[1]}" + minor_version="${BASH_REMATCH[2]}" + old_minor_version="${BASH_REMATCH[2]}" + patch_version="${BASH_REMATCH[3]}" + old_patch_version="${BASH_REMATCH[3]}" + else + echo "Failed to parse the latest tag version." + exit 1 + fi + + # Increment the major version + ((major_version++)) + + # Set the minor and patch versions to 0 + minor_version=0 + patch_version=0 + + # Construct the new version + new_version="v${major_version}.${minor_version}.${patch_version}" + + # Replace the version in all relevant files except those in the 'Launcher' and 'Libs' folders + find . -type f -not -path "./Launcher/*" -not -path "./Libs/*" -exec sed -i "s/$latest_tag/$new_version/g" {} \; + find ./Engine/Config/Version/version.h -type f -exec sed -i "s/#define ENGINE_VERSION_MAJOR $old_major_version/#define ENGINE_VERSION_MAJOR $major_version/g" {} \; + find ./Engine/Config/Version/version.h -type f -exec sed -i "s/#define ENGINE_VERSION_MINOR $old_minor_version/#define ENGINE_VERSION_MINOR $minor_version/g" {} \; + find ./Engine/Config/Version/version.h -type f -exec sed -i "s/#define ENGINE_VERSION_PATCH $old_patch_version/#define ENGINE_VERSION_PATCH $patch_version/g" {} \; + + # Commit the changes + git config user.name "Laplace-Engine-3D-Bot" + git config user.email "guillaume.papineau@epitech.eu" + git add . + git commit -m "update(root): Increment major version to $new_version" + git push + + # Create a new tag + git tag -a $new_version -m "Engine-3D $new_version" + git push --tags + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/increment_minor.yml b/.github/workflows/increment_minor.yml new file mode 100644 index 0000000..b18bc27 --- /dev/null +++ b/.github/workflows/increment_minor.yml @@ -0,0 +1,60 @@ +name: Increment Minor Version + +on: + pull_request: + branches: + - 'dev' + +jobs: + increment_minor_version: + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Increment Minor Version + run: | + # Get the latest tag from the repository + latest_tag=$(git describe --tags --abbrev=0) + + # Extract the major, minor, and patch versions from the tag + regex="([0-9]+)\.([0-9]+)\.([0-9]+)" + if [[ $latest_tag =~ $regex ]]; then + major_version="${BASH_REMATCH[1]}" + minor_version="${BASH_REMATCH[2]}" + old_minor_version="${BASH_REMATCH[2]}" + patch_version="${BASH_REMATCH[3]}" + old_patch_version="${BASH_REMATCH[3]}" + else + echo "Failed to parse the latest tag version." + exit 1 + fi + + # Increment the minor version + ((minor_version++)) + + # Set the patch version to 0 + patch_version=0 + + # Construct the new version + new_version="v${major_version}.${minor_version}.${patch_version}" + + # Replace the version in all relevant files except those in the 'Launcher' and 'Libs' folders + find . -type f -not -path "./Launcher/*" -not -path "./Libs/*" -exec sed -i "s/$latest_tag/$new_version/g" {} \; + find ./Engine/Config/Version/version.h -type f -exec sed -i "s/#define ENGINE_VERSION_MINOR $old_minor_version/#define ENGINE_VERSION_MINOR $minor_version/g" {} \; + find ./Engine/Config/Version/version.h -type f -exec sed -i "s/#define ENGINE_VERSION_PATCH $old_patch_version/#define ENGINE_VERSION_PATCH $patch_version/g" {} \; + + # Commit the changes + git config user.name "Laplace-Engine-3D-Bot" + git config user.email "guillaume.papineau@epitech.eu" + git add . + git commit -m "update(root): Increment minor version to $new_version" + git push + + # Create a new tag + git tag -a $new_version -m "Engine-3D $new_version" + git push --tags + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/increment_patch.yml b/.github/workflows/increment_patch.yml new file mode 100644 index 0000000..8b429ac --- /dev/null +++ b/.github/workflows/increment_patch.yml @@ -0,0 +1,60 @@ +name: Increment Patch Version + +on: + pull_request: + branches: + - '*' + - '!dev' + - '!main' + - '!master' + - '!release' + - '!release/*' + +jobs: + increment_version: + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Increment Patch Version + run: | + # Get the latest tag from the repository + latest_tag=$(git describe --tags --abbrev=0) + + # Extract the major, minor, and patch versions from the tag + regex="([0-9]+)\.([0-9]+)\.([0-9]+)" + if [[ $latest_tag =~ $regex ]]; then + major_version="${BASH_REMATCH[1]}" + minor_version="${BASH_REMATCH[2]}" + patch_version="${BASH_REMATCH[3]}" + old_patch_version="${BASH_REMATCH[3]}" + else + echo "Failed to parse the latest tag version." + exit 1 + fi + + # Increment the patch version + ((patch_version++)) + + # Construct the new version + new_version="v${major_version}.${minor_version}.${patch_version}" + + # Replace the version in all relevant files except those in the 'Launcher' and 'Libs' folders + find . -type f -not -path "./Launcher/*" -not -path "./Libs/*" -exec sed -i "s/$latest_tag/$new_version/g" {} \; + find ./Engine/Config/Version/version.h -type f -exec sed -i "s/#define ENGINE_VERSION_PATCH $old_patch_version/#define ENGINE_VERSION_PATCH $patch_version/g" {} \; + + # Commit the changes + git config user.name "Laplace-Engine-3D-Bot" + git config user.email "guillaume.papineau@epitech.eu" + git add . + git commit -m "update(root): Increment patch version to $new_version" + git push + + # Create a new tag + git tag -a $new_version -m "Engine-3D $new_version" + git push --tags + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Engine/Config/Version/version.h b/Engine/Config/Version/version.h index 97e94c3..764d3ba 100644 --- a/Engine/Config/Version/version.h +++ b/Engine/Config/Version/version.h @@ -28,7 +28,7 @@ #ifdef FLAG_VERSION_PATCH #define ENGINE_VERSION_PATCH FLAG_VERSION_PATCH #else - #define ENGINE_VERSION_PATCH 0 + #define ENGINE_VERSION_PATCH 6 #endif //////////////////////////////////////////////////////////// diff --git a/VERSION b/VERSION index 8c239aa..512717d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Engine-3D v0.1.0 +Engine-3D v0.1.6