@@ -16,49 +16,56 @@ jobs:
1616 with :
1717 fetch-depth : 0
1818
19- - name : Read version from readme.txt
20- id : read_version
19+ - name : Find Readme File
20+ id : find_readme
2121 run : |
22- VERSION=$(grep -oP 'Stable tag: \K[0-9.]+' readme.txt) # Use \K to only capture the version
23- echo "plugin_version=$VERSION" >> $GITHUB_ENV
24-
25- - name : Get latest tag
26- id : get_latest_tag
27- run : |
28- git fetch --tags
29- LATEST_TAG=$(git describe --tags --abbrev=0) # --abbrev=0 to get full tag name
30- if [[ -z "$LATEST_TAG" ]]; then
31- echo "No tags found"
22+ for file in README.txt README.md Readme.txt Readme.md readme.txt readme.md; do
23+ if [ -f "$file" ]; then
24+ echo "Readme file found: $file"
25+ echo "readme_file=$file" >> $GITHUB_ENV
26+ break
27+ fi
28+ done
29+ if [ -z "${{ env.readme_file }}" ]; then
30+ echo "::error::Readme file not found."
3231 exit 1
3332 fi
34- echo "latest_tag=$LATEST_TAG" >> $GITHUB_ENV
3533
36- - name : Extract Changelog
37- id : extract_changelog
34+ - name : Extract Release Notes
35+ id : release_notes
3836 run : |
39- START=$(grep -n "== Changelog ==" readme.txt | cut -d: -f1)
40- if [[ -z "$START" ]]; then
41- echo "::error::Changelog section not found."
42- exit 1
43- fi
44- START=$((START + 1)) # Start from the line after "== Changelog =="
37+ changelog_section_start="== Changelog =="
38+ readme_file="${{ env.readme_file }}"
4539
46- # Extract changelog until the next top-level heading or end of file
47- END=$(grep -n -m 1 -E "^==|^$" readme.txt | tail -n 1 | cut -d: -f1) # find next heading or EOF
48- if [[ -z "$END" ]]; then
49- END=$(wc -l < readme.txt) # If no next heading, use EOF
50- fi
51- END=$((END - 1)) # End one line before the next heading
40+ # Read lines from the changelog section
41+ in_changelog=0
42+ release_notes=""
43+ while IFS= read -r line; do
44+ # Start extracting once we find the changelog section
45+ if [[ "$line" == "$changelog_section_start" ]]; then
46+ in_changelog=1
47+ continue
48+ fi
49+
50+ # Stop extracting if we reach another section or blank line
51+ if [[ $in_changelog -eq 1 && "$line" =~ ^== ]]; then
52+ break
53+ fi
5254
53- if [[ $START -gt $END ]]; then # Handle cases where there is no changelog content
54- echo "::warning::No changelog content found."
55- echo "" > CHANGELOG.txt # create empty file
56- else
57- sed -n "${START},${END}p" readme.txt > CHANGELOG.txt
55+ # Add valid lines to the release notes
56+ if [[ $in_changelog -eq 1 && -n "$line" ]]; then
57+ release_notes+="$line\n"
58+ fi
59+ done < "$readme_file"
60+
61+ # Check if release notes were extracted
62+ if [[ -z "$release_notes" ]]; then
63+ echo "::error::Failed to extract release notes from the changelog section."
64+ exit 1
5865 fi
5966
60- CHANGELOG_CONTENT=$(cat CHANGELOG.txt)
61- echo "changelog=$CHANGELOG_CONTENT" >> $GITHUB_ENV
67+ # Set output
68+ echo "::set-output name=notes::$release_notes"
6269
6370 - name : Create zip file
6471 run : |
7279 env :
7380 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7481 with :
75- tag_name : ${{ env.latest_tag }}
76- release_name : " Release ${{ env.plugin_version }}"
77- body : ${{ env.changelog }}
82+ tag_name : ${{ github.ref_name }}
83+ release_name : " ${{ env.plugin_version }}"
84+ body : ${{ steps.release_notes.outputs.notes }}
7885 draft : false
7986 prerelease : false
8087
0 commit comments