Skip to content

Commit 7c78110

Browse files
committed
Generate changelog.txt from readme.txt on CI.
1 parent 8f624ab commit 7c78110

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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."

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
with:
3434
path: ${{ env.wp-plugin-directory }}
3535

36+
- name: Update changelog
37+
if: ${{ matrix.php-version == '8.4' }}
38+
run: ./update-changelog.sh
39+
3640
- name: Setup PHP
3741
uses: shivammathur/setup-php@v2
3842
with:

0 commit comments

Comments
 (0)