2024-12-01 02:13:49 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Rules for generating semantic versioning
|
|
|
|
# major: breaking change
|
|
|
|
# minor: feat, style
|
|
|
|
# patch: build, fix, perf, refactor, revert
|
|
|
|
|
|
|
|
PREVENT_REMOVE_FILE=$1
|
|
|
|
TEMP_FILE_PATH=.gitea/conventional_commits/tmp
|
|
|
|
|
|
|
|
LAST_TAG=$(git describe --tags --abbrev=0 --always)
|
|
|
|
echo "Last tag: #$LAST_TAG#"
|
|
|
|
PATTERN="^[0-9]+\.[0-9]+\.[0-9]+$"
|
|
|
|
|
|
|
|
increment_version() {
|
|
|
|
local version=$1
|
|
|
|
local increment=$2
|
|
|
|
local major=$(echo $version | cut -d. -f1)
|
|
|
|
local minor=$(echo $version | cut -d. -f2)
|
|
|
|
local patch=$(echo $version | cut -d. -f3)
|
|
|
|
|
|
|
|
if [ "$increment" == "major" ]; then
|
|
|
|
major=$((major + 1))
|
|
|
|
minor=0
|
|
|
|
patch=0
|
|
|
|
elif [ "$increment" == "minor" ]; then
|
|
|
|
minor=$((minor + 1))
|
|
|
|
patch=0
|
|
|
|
elif [ "$increment" == "patch" ]; then
|
|
|
|
patch=$((patch + 1))
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${major}.${minor}.${patch}"
|
|
|
|
}
|
|
|
|
|
|
|
|
create_file() {
|
|
|
|
local with_range=$1
|
|
|
|
if [ -s $TEMP_FILE_PATH/messages.txt ]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ "$with_range" == "true" ]; then
|
|
|
|
git log $LAST_TAG..HEAD --no-decorate --pretty=format:"%s" > $TEMP_FILE_PATH/messages.txt
|
|
|
|
else
|
|
|
|
git log --no-decorate --pretty=format:"%s" > $TEMP_FILE_PATH/messages.txt
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
get_commit_range() {
|
2024-12-02 11:05:52 +01:00
|
|
|
rm -f $TEMP_FILE_PATH/messages.txt
|
2024-12-01 02:13:49 -08:00
|
|
|
if [[ $LAST_TAG =~ $PATTERN ]]; then
|
|
|
|
create_file true
|
|
|
|
else
|
|
|
|
create_file
|
|
|
|
LAST_TAG="0.0.0"
|
|
|
|
fi
|
|
|
|
echo " " >> $TEMP_FILE_PATH/messages.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
mkdir -p $TEMP_FILE_PATH
|
|
|
|
get_commit_range
|
|
|
|
new_version=$LAST_TAG
|
|
|
|
increment_type=""
|
|
|
|
|
|
|
|
while read message; do
|
|
|
|
echo $message
|
|
|
|
if echo $message | grep -Pq '(feat|style)(\([\w]+\))?!:([a-zA-Z0-9-_!\&\.\%\(\)\=\w\s]+)\s?(,?\s?)((ref(s?):?\s?)(([A-Z0-9]+\-[0-9]+)|(NOISSUE)))'; then
|
|
|
|
increment_type="major"
|
|
|
|
break
|
|
|
|
elif echo $message | grep -Pq '(feat|style)(\([\w]+\))?:([a-zA-Z0-9-_!\&\.\%\(\)\=\w\s]+)\s?(,?\s?)((ref(s?):?\s?)(([A-Z0-9]+\-[0-9]+)|(NOISSUE)))'; then
|
|
|
|
if [ -z "$increment_type" ] || [ "$increment_type" == "patch" ]; then
|
|
|
|
increment_type="minor"
|
|
|
|
fi
|
|
|
|
elif echo $message | grep -Pq '(build|fix|perf|refactor|revert)(\(.+\))?:\s([a-zA-Z0-9-_!\&\.\%\(\)\=\w\s]+)\s?(,?\s?)((ref(s?):?\s?)(([A-Z0-9]+\-[0-9]+)|(NOISSUE)))'; then
|
|
|
|
if [ -z "$increment_type" ]; then
|
|
|
|
increment_type="patch"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done < $TEMP_FILE_PATH/messages.txt
|
|
|
|
|
|
|
|
if [ -n "$increment_type" ]; then
|
|
|
|
new_version=$(increment_version $LAST_TAG $increment_type)
|
|
|
|
echo "New version: $new_version"
|
|
|
|
|
|
|
|
gitchangelog | grep -v "[rR]elease:" > HISTORY.md
|
2024-12-02 10:54:04 +01:00
|
|
|
echo $new_version > TextParser/VERSION
|
2024-12-02 11:34:33 +01:00
|
|
|
git add TextParser/VERSION
|
|
|
|
git add HISTORY.md
|
2024-12-01 02:13:49 -08:00
|
|
|
git commit -m "release: version $new_version 🚀"
|
|
|
|
echo "creating git tag : $new_version"
|
|
|
|
git tag $new_version
|
|
|
|
git push -u origin HEAD --tags
|
|
|
|
echo "Gitea Actions will detect the new tag and release the new version."
|
|
|
|
else
|
|
|
|
echo "No changes requiring a version increment."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
start
|
|
|
|
|
|
|
|
if [ -z "$PREVENT_REMOVE_FILE" ]; then
|
|
|
|
rm -f $TEMP_FILE_PATH/messages.txt
|
|
|
|
fi
|