Skip to content

Commit

Permalink
Improve app version control (#25)
Browse files Browse the repository at this point in the history
* New version control

* check dependencies

* fix error code 128

* test fix

* test fix 2

* test fix 3

* test fix 4

* test fix 5

* test fix 6

* test fix 7

* test fix 8

* test fix 9

* test fix 10

* test fix 11

* test fix 12

* test fix 13

* test fix 14

* test fix 15

* test fix 15

* test fix 16

* test fix 17

* test fix 18

* test fix 19

* test fix 20

* test fix 21

* final fix?

* improving for pr

* another fix

* fixing again -_-
  • Loading branch information
FEDERICOMB96 authored Jul 23, 2024
1 parent a92b207 commit b0d5573
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 39 deletions.
33 changes: 27 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

pull_request:
types: [opened, reopened, synchronize]

release:
types: [published]
tags:
Expand All @@ -19,7 +20,6 @@ jobs:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.declare_sha.outputs.sha }}
semver: ${{ steps.declare_sha.outputs.semver }}

steps:
- name: Checkout
Expand All @@ -35,6 +35,27 @@ jobs:
echo "COMMIT_SHA=${SHA}" >> $GITHUB_ENV
echo "sha=$SHA" >> $GITHUB_OUTPUT
- name: Updating app version (only pull requests)
if: |
github.event_name == 'pull_request'
shell: bash
run: |
chmod +x ${GITHUB_WORKSPACE}/version/appversion_pr.sh
${GITHUB_WORKSPACE}/version/appversion_pr.sh ${GITHUB_WORKSPACE} ${{ github.event.pull_request.number }}
- name: Updating app version (non pull requests)
if: |
github.event_name != 'pull_request'
shell: bash
run: |
chmod +x ${GITHUB_WORKSPACE}/version/appversion.sh
${GITHUB_WORKSPACE}/version/appversion.sh ${GITHUB_WORKSPACE}
- name: Moving app version files
run: |
mv -f version/version.inc addons/amxmodx/scripting/include/mm_incs/
mv -f version/multimod_manager_version.inc addons/amxmodx/scripting/include/
- name: Setup AMXXPawn Compiler
uses: wopox1337/setup-amxxpawn@master
with:
Expand All @@ -54,11 +75,11 @@ jobs:
xargs wget
7z x *.zip
echo "REAPI_INCLUDE_PATH=$(pwd)/addons/amxmodx/scripting/include" >> $GITHUB_ENV
- name: Compile AMXX plugins
working-directory: addons/amxmodx/scripting/
env:
REAPI_INCLUDE: ${{env.REAPI_INCLUDE_PATH}}
REAPI_INCLUDE: ${{ env.REAPI_INCLUDE_PATH }}
run: |
mkdir ../plugins/
for sourcefile in *.sma;
Expand All @@ -68,7 +89,7 @@ jobs:
amxxpc $(basename $sourcefile) -o"../plugins/$(basename $amxxfile)" -i"include" -i"$REAPI_INCLUDE"
done
- name: Move files
- name: Moving files to publish
run: |
mkdir publish
mv addons/ -t publish/
Expand All @@ -88,7 +109,7 @@ jobs:
- name: Deploying resources artifacts
uses: actions/download-artifact@v4
with:
name: MultiModManagerCS-${{needs.build.outputs.sha}}
name: MultiModManagerCS-${{ needs.build.outputs.sha }}

- name: Packaging binaries
id: packaging-job
Expand All @@ -97,7 +118,7 @@ jobs:
github.event.action == 'published' &&
startsWith(github.ref, 'refs/tags/')
run: |
7z a -mm=Deflate -mfb=258 -mpass=15 -r MultiModManagerCS-v${{needs.build.outputs.semver}}.zip addons/
7z a -mm=Deflate -mfb=258 -mpass=15 -r MultiModManagerCS-v${{ env.NEW_VERSION }}.zip addons/
- name: Publish artifacts
uses: softprops/action-gh-release@v2
Expand Down
20 changes: 20 additions & 0 deletions addons/amxmodx/scripting/include/mm_incs/checks.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#if defined _mm_checks_included_
#endinput
#endif
#define _mm_checks_included_

// Do NOT modify this file!

/**
* AMX Mod X version check
*/
#if AMXX_VERSION_NUM < 200
#error "Multimod Manager CS requires AMX Mod X 1.10 or higher. Download from: https://www.amxmodx.org/downloads-new.php?branch=master"
#endif

/**
* ReAPI version check
*/
#if REAPI_VERSION < 524300
#error "Multimod Manager CS requires ReAPI 5.24.300 or higher. Download from: https://github.com/s1lentq/reapi/releases/latest"
#endif
22 changes: 4 additions & 18 deletions addons/amxmodx/scripting/include/mm_incs/version.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@

// Do NOT modify this file!

/**
* AMX Mod X version check
*/
#if AMXX_VERSION_NUM < 200
#error "Multimod Manager CS requires AMX Mod X 1.10 or higher. Download from: https://www.amxmodx.org/downloads-new.php?branch=master"
#endif

/**
* ReAPI version check
*/
#if REAPI_VERSION < 524300
#error "Multimod Manager CS requires ReAPI 5.24.300 or higher. Download from: https://github.com/s1lentq/reapi/releases/latest"
#endif

#define MM_VERSION_MAJOR 2
#define MM_VERSION_MINOR 3
#define MM_VERSION_COMMIT 219
#define MM_VERSION_MAJOR 2
#define MM_VERSION_MINOR 3
#define MM_VERSION_MAINTENANCE 0

#define PLUGIN_VERSION fmt("v%d.%d.%d", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_COMMIT)
#define PLUGIN_VERSION fmt("v%d.%d.%d.(%s %s)", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_MAINTENANCE, __DATE__, __TIME__)
17 changes: 17 additions & 0 deletions addons/amxmodx/scripting/include/multimod_manager_checks.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if defined _multimod_manager_checks_included_
#endinput
#endif
#define _multimod_manager_checks_included_

// Do NOT modify this file!

/**
* AMX Mod X version check
*/
#if defined AMXX_VERSION_NUM
#if AMXX_VERSION_NUM < 200
#error "[API] Multimod Manager CS requires AMX Mod X 1.10 or higher. Download from: https://www.amxmodx.org/downloads-new.php?branch=master"
#endif
#else
#error "[API] Multimod Manager CS: please include multimod_manager_natives.inc after including amxmodx.inc."
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#endif
#define _multimod_manager_natives_included_

#include <multimod_manager_checks>
#include <multimod_manager_version>

/**
Expand Down
19 changes: 4 additions & 15 deletions addons/amxmodx/scripting/include/multimod_manager_version.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@

// Do NOT modify this file!

/**
* AMX Mod X version check
*/
#if defined AMXX_VERSION_NUM
#if AMXX_VERSION_NUM < 200
#error "[API] Multimod Manager CS requires AMX Mod X 1.10 or higher. Download from: https://www.amxmodx.org/downloads-new.php?branch=master"
#endif
#else
#error "[API] Multimod Manager CS: please include multimod_manager_natives.inc after including amxmodx.inc."
#endif

#define MM_VERSION_MAJOR 2
#define MM_VERSION_MINOR 3
#define MM_VERSION_COMMIT 219
#define MM_VERSION_MAJOR 2
#define MM_VERSION_MINOR 3
#define MM_VERSION_MAINTENANCE 0

#define MM_NATIVES_API_VER fmt("v%d.%d.%d", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_COMMIT)
#define MM_NATIVES_API_VER fmt("v%d.%d.%d.(%s %s)", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_MAINTENANCE, __DATE__, __TIME__)
1 change: 1 addition & 0 deletions addons/amxmodx/scripting/multimod_manager.sma
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <amxmisc>
#include <reapi>
#include <json>
#include "mm_incs/checks"
#include "mm_incs/version"
#include "mm_incs/defines"
#include "mm_incs/global"
Expand Down
84 changes: 84 additions & 0 deletions version/appversion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

init()
{
SOURCE_DIR=$1
GIT_DIR=$SOURCE_DIR
VERSION_FILE=$SOURCE_DIR/version/version.h
APPVERSION_FILE=$SOURCE_DIR/version/version.inc
APPVERSION_FILE_NATIVES=$SOURCE_DIR/version/multimod_manager_version.inc

MAJOR=$(cat "$VERSION_FILE" | grep -wi 'MM_VERSION_MAJOR' | sed -e 's/.*MM_VERSION_MAJOR.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g')
if [ $? -ne 0 -o "$MAJOR" = "" ]; then
MAJOR=0
fi

MINOR=$(cat "$VERSION_FILE" | grep -wi 'MM_VERSION_MINOR' | sed -e 's/.*MM_VERSION_MINOR.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g')
if [ $? -ne 0 -o "$MINOR" = "" ]; then
MINOR=0
fi

MAINTENANCE=$(cat "$VERSION_FILE" | grep -i 'MM_VERSION_MAINTENANCE' | sed -e 's/.*MM_VERSION_MAINTENANCE.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g')
if [ $? -ne 0 -o "$MAINTENANCE" = "" ]; then
MAINTENANCE=0
fi

BRANCH_NAME=$(git -C "$GIT_DIR" rev-parse --abbrev-ref HEAD)
if [ $? -ne 0 -o "$BRANCH_NAME" = "" ]; then
BRANCH_NAME=master
fi

COMMIT_COUNT=$(git -C "$GIT_DIR" rev-list --count $BRANCH_NAME)
if [ $? -ne 0 -o "$COMMIT_COUNT" = "" ]; then
COMMIT_COUNT=0
fi

NEW_VERSION_INC="$MAJOR$MINOR$MAINTENANCE$COMMIT_COUNT"
NEW_VERSION="$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT"

echo "NEW_VERSION_INC=${NEW_VERSION_INC}" >> $GITHUB_ENV
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV

update_appversion
}

update_appversion()
{
echo Updating $APPVERSION_FILE, new version is '"'$NEW_VERSION'"'

echo -e "#if defined _mm_version_included_\r">$APPVERSION_FILE
echo -e " #endinput\r">>$APPVERSION_FILE
echo -e "#endif\r">>$APPVERSION_FILE
echo -e "#define _mm_version_included_\r">>$APPVERSION_FILE
echo -e "\r">>$APPVERSION_FILE
echo -e "// MultiMod Manager version\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION $NEW_VERSION_INC\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_MAJOR $MAJOR\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_MINOR $MINOR\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_MAINTENANCE $MAINTENANCE\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_COMMIT $COMMIT_COUNT\r">>$APPVERSION_FILE
echo -e "\r">>$APPVERSION_FILE
echo -e "#define PLUGIN_VERSION fmt(\"v%d.%d.%d.%d\", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_MAINTENANCE, MM_VERSION_COMMIT)\r">>$APPVERSION_FILE

echo Updating $APPVERSION_FILE_NATIVES, new version is '"'$NEW_VERSION'"'

echo -e "#if defined _multimod_manager_version_included_\r">$APPVERSION_FILE_NATIVES
echo -e " #endinput\r">>$APPVERSION_FILE_NATIVES
echo -e "#endif\r">>$APPVERSION_FILE_NATIVES
echo -e "#define _multimod_manager_version_included_\r">>$APPVERSION_FILE_NATIVES
echo -e "\r">>$APPVERSION_FILE_NATIVES
echo -e "// MultiMod Manager version\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION $NEW_VERSION_INC\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_MAJOR $MAJOR\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_MINOR $MINOR\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_MAINTENANCE $MAINTENANCE\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_COMMIT $COMMIT_COUNT\r">>$APPVERSION_FILE_NATIVES
echo -e "\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_NATIVES_API_VER fmt(\"v%d.%d.%d.%d\", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_MAINTENANCE, MM_VERSION_COMMIT)\r">>$APPVERSION_FILE_NATIVES
}

# Initialise
init $*

# Exit normally
exit 0
87 changes: 87 additions & 0 deletions version/appversion_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

init()
{
SOURCE_DIR=$1
GIT_DIR=$SOURCE_DIR
VERSION_FILE=$SOURCE_DIR/version/version.h
APPVERSION_FILE=$SOURCE_DIR/version/version.inc
APPVERSION_FILE_NATIVES=$SOURCE_DIR/version/multimod_manager_version.inc
PULL_REQUEST_ID=$2

MAJOR=$(cat "$VERSION_FILE" | grep -wi 'MM_VERSION_MAJOR' | sed -e 's/.*MM_VERSION_MAJOR.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g')
if [ $? -ne 0 -o "$MAJOR" = "" ]; then
MAJOR=0
fi

MINOR=$(cat "$VERSION_FILE" | grep -wi 'MM_VERSION_MINOR' | sed -e 's/.*MM_VERSION_MINOR.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g')
if [ $? -ne 0 -o "$MINOR" = "" ]; then
MINOR=0
fi

MAINTENANCE=$(cat "$VERSION_FILE" | grep -i 'MM_VERSION_MAINTENANCE' | sed -e 's/.*MM_VERSION_MAINTENANCE.*[^0-9]\([0-9][0-9]*\).*/\1/i' -e 's/\r//g')
if [ $? -ne 0 -o "$MAINTENANCE" = "" ]; then
MAINTENANCE=0
fi

BRANCH_NAME=$(git -C "$GIT_DIR" rev-parse --abbrev-ref HEAD)
if [ $? -ne 0 -o "$BRANCH_NAME" = "" ]; then
BRANCH_NAME=master
fi

COMMIT_COUNT=$(git -C "$GIT_DIR" rev-list --count $BRANCH_NAME)
if [ $? -ne 0 -o "$COMMIT_COUNT" = "" ]; then
COMMIT_COUNT=0
fi

NEW_VERSION_INC="$MAJOR$MINOR$MAINTENANCE$COMMIT_COUNT"
NEW_VERSION="$MAJOR.$MINOR.$MAINTENANCE.$COMMIT_COUNT-pr#$PULL_REQUEST_ID"

echo "NEW_VERSION_INC=${NEW_VERSION_INC}" >> $GITHUB_ENV
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV

update_appversion
}

update_appversion()
{
echo Updating $APPVERSION_FILE, new version is '"'$NEW_VERSION'"'

echo -e "#if defined _mm_version_included_\r">$APPVERSION_FILE
echo -e " #endinput\r">>$APPVERSION_FILE
echo -e "#endif\r">>$APPVERSION_FILE
echo -e "#define _mm_version_included_\r">>$APPVERSION_FILE
echo -e "\r">>$APPVERSION_FILE
echo -e "// MultiMod Manager version\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION $NEW_VERSION_INC\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_MAJOR $MAJOR\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_MINOR $MINOR\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_MAINTENANCE $MAINTENANCE\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_COMMIT $COMMIT_COUNT\r">>$APPVERSION_FILE
echo -e "#define MM_VERSION_PR_ID $PULL_REQUEST_ID\r">>$APPVERSION_FILE
echo -e "\r">>$APPVERSION_FILE
echo -e "#define PLUGIN_VERSION fmt(\"v%d.%d.%d.%d-pr#%d\", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_MAINTENANCE, MM_VERSION_COMMIT, MM_VERSION_PR_ID)\r">>$APPVERSION_FILE

echo Updating $APPVERSION_FILE_NATIVES, new version is '"'$NEW_VERSION'"'

echo -e "#if defined _multimod_manager_version_included_\r">$APPVERSION_FILE_NATIVES
echo -e " #endinput\r">>$APPVERSION_FILE_NATIVES
echo -e "#endif\r">>$APPVERSION_FILE_NATIVES
echo -e "#define _multimod_manager_version_included_\r">>$APPVERSION_FILE_NATIVES
echo -e "\r">>$APPVERSION_FILE_NATIVES
echo -e "// MultiMod Manager version\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION $NEW_VERSION_INC\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_MAJOR $MAJOR\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_MINOR $MINOR\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_MAINTENANCE $MAINTENANCE\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_COMMIT $COMMIT_COUNT\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_VERSION_PR_ID $PULL_REQUEST_ID\r">>$APPVERSION_FILE_NATIVES
echo -e "\r">>$APPVERSION_FILE_NATIVES
echo -e "#define MM_NATIVES_API_VER fmt(\"v%d.%d.%d.%d-pr#%d\", MM_VERSION_MAJOR, MM_VERSION_MINOR, MM_VERSION_MAINTENANCE, MM_VERSION_COMMIT, MM_VERSION_PR_ID)\r">>$APPVERSION_FILE_NATIVES
}

# Initialise
init $*

# Exit normally
exit 0
8 changes: 8 additions & 0 deletions version/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Version declaration dependency file
*
*/

#define MM_VERSION_MAJOR 2
#define MM_VERSION_MINOR 3
#define MM_VERSION_MAINTENANCE 0

0 comments on commit b0d5573

Please sign in to comment.