Skip to content

Commit

Permalink
Merge pull request #17 from 0LNetworkCommunity/feat/lei_changelog
Browse files Browse the repository at this point in the history
Feat/lei changelog
  • Loading branch information
leirbag95 authored Apr 12, 2024
2 parents deb6fce + 1aa1869 commit b811b0b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: '16'


- name: Install jq
run: sudo apt-get install jq

- name: Set Script Permissions
run: chmod +x ./web-app/scripts/generate_changelog.sh

Expand Down
2 changes: 1 addition & 1 deletion web-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "explorer",
"private": true,
"version": "0.0.0",
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
30 changes: 11 additions & 19 deletions web-app/scripts/generate_changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,17 @@ ADDED_ENTRIES=""
CHANGED_ENTRIES=""
REMOVED_ENTRIES=""

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

VERSIONS=()
while IFS= read -r line; do
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
# Use jq to read the version number directly from package.json
if [ -f "package.json" ]; then
LATEST_VERSION=$(jq -r '.version' package.json)
else
echo "package.json not found. Exiting..."
exit 1
fi

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


# Process git log entries and categorize them into Added, Changed, and Removed
while IFS= read -r commit; do
case "$commit" in
"[+]"*) ADDED_ENTRIES+="- ${commit:4}\n" ;;
Expand All @@ -39,9 +30,9 @@ while IFS= read -r commit; do
esac
done < <(git log --pretty=format:"%s" origin/feat/lei_changelog...origin/feat/lei_changelog_dev)


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"

# Prepend new changelog entries to the existing CHANGELOG.md, or create it if it doesn't exist
if [ -f "CHANGELOG.md" ]; then
echo -e "$NEW_ENTRY$(cat CHANGELOG.md)" > TEMP_CHANGELOG.md
mv TEMP_CHANGELOG.md CHANGELOG.md
Expand All @@ -53,5 +44,6 @@ git add CHANGELOG.md
git commit -m "chore: update changelog"
git push origin main

# Tag the current commit with the latest version and push the tag to the remote repository
git tag -a "$LATEST_VERSION" -m "Release $LATEST_VERSION"
git push origin "$LATEST_VERSION"
git push origin "$LATEST_VERSION"

0 comments on commit b811b0b

Please sign in to comment.