|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Check if readme.txt exists |
| 4 | +if [ ! -f readme.txt ]; then |
| 5 | + echo "readme.txt file not found!" |
| 6 | + exit 1 |
| 7 | +fi |
| 8 | + |
| 9 | +# Determine the latest changelog version in readme.txt |
| 10 | +latest_version=$(sed -n 's/^= \([0-9]\+\.[0-9]\+\.[0-9]\+\) =$/\1/p' readme.txt | head -n 1) |
| 11 | + |
| 12 | +if [ -z "$latest_version" ]; then |
| 13 | + echo "No latest version found in readme.txt!" |
| 14 | + exit 0 |
| 15 | +fi |
| 16 | + |
| 17 | +# Get the latest changelog section from readme.txt |
| 18 | +latest_section=$(sed -n "/^= $latest_version =$/,/^= [0-9]\+\.[0-9]\+\.[0-9]\+ =$/ { /^= [0-9]\+\.[0-9]\+\.[0-9]\+ =$/!p; }" readme.txt) |
| 19 | +latest_section="= ${latest_version} =\n${latest_section}\n" |
| 20 | + |
| 21 | +# Remove the latest changelog section from changelog.txt |
| 22 | +sed -i "/^= $latest_version =$/,/^= [0-9]\+\.[0-9]\+\.[0-9]\+ =$/ {/^= $latest_version =$/d; /^= [0-9]\+\.[0-9]\+\.[0-9]\+ =$/!d;}" changelog.txt |
| 23 | + |
| 24 | +# Append the latest changelog section from readme.txt to changelog.txt |
| 25 | +{ echo -e "$latest_section"; cat changelog.txt; } > temp.txt && mv temp.txt changelog.txt |
| 26 | + |
| 27 | +# Check if there are changes in changelog.txt |
| 28 | +if git diff --quiet changelog.txt; then |
| 29 | + echo "No changes in changelog.txt." |
| 30 | + exit 0 |
| 31 | +fi |
| 32 | + |
| 33 | +# Configure Git commit information |
| 34 | +#git config --global user.name "github-actions[bot]" |
| 35 | +#git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 36 | + |
| 37 | +# Add, commit, and push changes |
| 38 | +git add changelog.txt |
| 39 | +git commit -m "Update changelog from readme.txt" |
| 40 | +git push |
| 41 | + |
| 42 | +echo "Changelog successfully updated and pushed to the repository." |
0 commit comments