1+ name : Create Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' *.*.*' # Match semantic versioning tags
7+ # Removed branches trigger to ensure it only runs on tags
8+ # branches:
9+ # - master
10+
11+ jobs :
12+ create_release :
13+ # No need to check against branches, workflow only triggers on tags
14+ runs-on : ubuntu-latest
15+ steps :
16+ - uses : actions/checkout@v3
17+ with :
18+ fetch-depth : 0
19+
20+ - name : Find Readme File
21+ id : find_readme
22+ run : |
23+ for file in readme.txt Readme.txt README.txt README.md Readme.md readme.md; do
24+ if [ -f "$file" ]; then
25+ echo "Readme file found: $file"
26+ echo "readme_file=$file" >> $GITHUB_ENV
27+ break
28+ fi
29+ done
30+
31+ # Ensure the variable is available within the current step
32+ source $GITHUB_ENV
33+
34+ if [ -z "$readme_file" ]; then
35+ echo "::error::Readme file not found."
36+ exit 1
37+ fi
38+
39+ - name : Extract Release Notes
40+ id : release_notes
41+ run : |
42+ changelog_section_start="== Changelog =="
43+ readme_file="$readme_file"
44+
45+ # Extract the tag name from GITHUB_REF (plugin_version)
46+ if [[ "$GITHUB_REF" == refs/tags/* ]]; then
47+ plugin_version="${GITHUB_REF#refs/tags/}"
48+ echo "DEBUG: Plugin latest version found: $plugin_version."
49+ else
50+ echo "::error::This workflow must be triggered by a tag push."
51+ exit 1
52+ fi
53+
54+ in_changelog=0
55+ found_version=0
56+ release_notes=""
57+
58+ echo "DEBUG: Starting to extract release notes from $readme_file for version $plugin_version."
59+
60+ while IFS= read -r line; do
61+ echo "DEBUG: Processing line: $line"
62+
63+ # Start processing after the changelog header
64+ if [[ "$line" == "$changelog_section_start" ]]; then
65+ in_changelog=1
66+ echo "DEBUG: Found changelog section header."
67+ continue
68+ fi
69+
70+ # Skip if not in changelog section
71+ if [[ $in_changelog -eq 0 ]]; then
72+ echo "DEBUG: Skipping line (not in changelog section)."
73+ continue
74+ fi
75+
76+ # Check for the current version header
77+ if [[ "$line" == "= ${plugin_version} =" ]]; then
78+ found_version=1
79+ echo "DEBUG: Found version header for $plugin_version."
80+ continue
81+ fi
82+
83+ # Break if a new version header is found after the current version
84+ if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^= [0-9]+\.[0-9]+\.[0-9]+ =$'; then
85+ echo "DEBUG: Found a new version header. Stopping collection."
86+ break
87+ fi
88+
89+ # Collect lines starting with '*' if we are in the current version section
90+ if [[ $found_version -eq 1 ]] && echo "$line" | grep -qE '^\*'; then
91+ echo "DEBUG: Found changelog entry: $line"
92+ release_notes+="${line}\n"
93+ continue
94+ fi
95+
96+ # Log skipped lines in the current version section
97+ if [[ $found_version -eq 1 ]]; then
98+ echo "DEBUG: Skipping line (not a changelog entry): $line"
99+ fi
100+ done < "$readme_file"
101+
102+ if [[ -z "$release_notes" ]]; then
103+ echo "::error::Failed to extract release notes for version ${plugin_version}."
104+ exit 1
105+ fi
106+
107+ echo "DEBUG: Successfully extracted release notes."
108+ echo "DEBUG: Release notes content:"
109+ echo -e "$release_notes"
110+
111+ # Write the release notes with actual line breaks
112+ echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
113+ echo -e "$release_notes" >> $GITHUB_ENV
114+ echo "EOF" >> $GITHUB_ENV
115+
116+ - name : Create zip file
117+ run : |
118+ REPO_NAME=$(basename `git rev-parse --show-toplevel`)
119+ zip -r ${REPO_NAME}.zip . -x '*.git*' -x '.github/*' -x '*.distignore*' -x 'CHANGELOG.txt'
120+ echo "repo_name=${REPO_NAME}" >> $GITHUB_ENV
121+
122+ # Source to make repo_name available in subsequent steps
123+ source $GITHUB_ENV
124+
125+ - name : Create Release
126+ id : create_release
127+ uses : actions/create-release@v1
128+ env :
129+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
130+ with :
131+ tag_name : ${{ github.ref_name }}
132+ release_name : " ${{ github.ref_name }}"
133+ body : ${{ env.RELEASE_NOTES }}
134+ draft : false
135+ prerelease : false
136+
137+ - name : Upload Release Asset
138+ uses : actions/upload-release-asset@v1
139+ env :
140+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
141+ with :
142+ upload_url : ${{ steps.create_release.outputs.upload_url }}
143+ asset_path : ./${{ env.repo_name }}.zip
144+ asset_name : ${{ env.repo_name }}.zip
145+ asset_content_type : application/zip
0 commit comments