Skip to content

Commit

Permalink
Merge pull request #15 from 0LNetworkCommunity/feat/lei_changelog
Browse files Browse the repository at this point in the history
[0.0.2] Feat/lei changelog dev
  • Loading branch information
leirbag95 authored Apr 11, 2024
2 parents 6bdda62 + f9ace97 commit f5d60b0
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions web-app/scripts/generate_changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,36 @@ ADDED_ENTRIES=""
CHANGED_ENTRIES=""
REMOVED_ENTRIES=""

VERSION_PATTERN='^\[([0-9]+)\.([0-9]+)\.([0-9]+)\]'

VERSIONS=()
while IFS= read -r line; do
case "$line" in
"[+]"*) ADDED_ENTRIES+="- ${line:4}\n" ;;
"[*]"*) CHANGED_ENTRIES+="- ${line:4}\n" ;;
"[-]"*) REMOVED_ENTRIES+="- ${line:4}\n" ;;
esac
if [[ $line =~ $VERSION_PATTERN ]]; then
VERSIONS+=("${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}")
fi
done < <(git log --pretty=format:"%s" origin/feat/lei_changelog...origin/feat/lei_changelog_dev)


LATEST_VERSION="0.0.0"
for version in "${VERSIONS[@]}"; do
if [[ "$version" > "$LATEST_VERSION" ]]; then
LATEST_VERSION=$version
fi
done

CURRENT_DATE=$(date "+%Y-%m-%d")

if [ -f "CHANGELOG.md" ]; then
LAST_VERSION=$(grep -oP "\[\K[0-9]+\.[0-9]+\.[0-9]+(?=\])" CHANGELOG.md | head -1)
else
LAST_VERSION="0.0.0"
fi

IFS='.' read -ra VERSION <<< "$LAST_VERSION"
MAJOR=${VERSION[0]}
MINOR=${VERSION[1]}
PATCH=${VERSION[2]}
while IFS= read -r commit; do
case "$commit" in
"[+]"*) ADDED_ENTRIES+="- ${commit:4}\n" ;;
"[*]"*) CHANGED_ENTRIES+="- ${commit:4}\n" ;;
"[-]"*) REMOVED_ENTRIES+="- ${commit:4}\n" ;;
esac
done < <(git log --pretty=format:"%s" origin/feat/lei_changelog...origin/feat/lei_changelog_dev)

NEW_MINOR=$((MINOR+1))
NEW_VERSION="$MAJOR.$NEW_MINOR.0"

NEW_ENTRY="## [$NEW_VERSION] - $CURRENT_DATE\n\n### Added\n\n$ADDED_ENTRIES\n### Changed\n\n$CHANGED_ENTRIES\n### Removed\n\n$REMOVED_ENTRIES\n"
NEW_ENTRY="## [$LATEST_VERSION] - $CURRENT_DATE\n\n### Added\n\n$ADDED_ENTRIES\n### Changed\n\n$CHANGED_ENTRIES\n### Removed\n\n$REMOVED_ENTRIES\n"

if [ -f "CHANGELOG.md" ]; then
echo -e "$NEW_ENTRY$(cat CHANGELOG.md)" > TEMP_CHANGELOG.md
Expand Down

0 comments on commit f5d60b0

Please sign in to comment.