99
1010jobs :
1111 tag :
12- name : Deploy Plugin Tag
12+ name : Prepare Release
1313 runs-on : ubuntu-latest
14+ if : github.event_name == 'push' # Only run on push events
1415
1516 steps :
1617 - uses : actions/checkout@v3
18+ with :
19+ fetch-depth : 0 # Important: Fetch all history for tags
1720
18- - name : Debug File List
19- run : ls -R
21+ - name : Get latest commit SHA
22+ id : sha
23+ if : github.ref == 'refs/heads/master' # Only when pushing to master
24+ run : echo "::set-output name=sha::$(git rev-parse HEAD)"
2025
21- - name : Find Readme File
22- id : find_readme
26+ - name : Create Tag (if needed)
27+ id : create_tag
28+ if : github.ref == 'refs/heads/master' && !startsWith(github.event.head_commit.message, 'Merge pull request') # Only on direct pushes to master, not merge commits
2329 run : |
24- readme_file=$(find . -type f -iname "readme.*" | head -n 1)
25- if [ -n "$readme_file" ]; then
26- echo "Readme file found: $readme_file"
27- echo "readme_file=$readme_file" >> $GITHUB_ENV
28- else
29- echo "::error::Readme file not found."
30- exit 1
31- fi
30+ TAG_NAME="v$(date +%Y%m%d%H%M%S)-${{ steps.sha.outputs.sha }}"
31+ git config --global user.name 'GitHub Actions'
32+ git config --global user.email 'actions@github.com'
33+ git tag -a "$TAG_NAME" -m "Release from master ${{ steps.sha.outputs.sha }}"
34+ git push origin --tags
35+ echo "::set-output name=tag::$TAG_NAME"
3236
3337 - name : Extract Release Notes
3438 id : release_notes
39+ if : github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
3540 run : |
3641 # Define variables
3742 changelog_section_start="== Changelog =="
38- current_tag="${{ github.ref_name }}"
39- readme_file="${{ env.readme_file }}"
43+ current_tag="${{ steps.create_tag.outputs.tag || github.ref_name }}" # Use created tag or existing tag
44+ readme_file=$(find . -type f -iname "readme.*" | head -n 1)
45+
46+ if [ -z "$readme_file" ]; then
47+ echo "::error::Readme file not found."
48+ exit 1
49+ fi
50+ echo "Readme file: $readme_file"
4051
41- # Extract version from tag (strip 'refs/tags/' if it exists)
52+ # Extract version from tag
4253 version=${current_tag#refs/tags/}
4354
4455 # Initialize variables
@@ -58,19 +69,22 @@ jobs:
5869 continue
5970 fi
6071
61- # Start capturing if the line matches the current version
62- if [[ "$line" == "= $version =" ]]; then
72+ # Start capturing if the line starts with a version number (semver format)
73+ if [[ "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
6374 capturing_version=1
64- release_notes+="$line\n"
75+ # Check if the captured version matches the current tag
76+ if [[ "$line" == "$version" ]]; then
77+ release_notes+="$line\n"
78+ fi
6579 continue
6680 fi
6781
68- # Stop capturing when a new version is detected
69- if [[ $capturing_version -eq 1 && "$line" =~ ^= ]]; then
82+ # Stop capturing when a new version section is detected
83+ if [[ $capturing_version -eq 1 && "$line" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
7084 break
7185 fi
7286
73- # Add the line to the release notes if we are capturing
87+ # Add the line to the release notes if capturing the current version
7488 if [[ $capturing_version -eq 1 ]]; then
7589 release_notes+="$line\n"
7690 fi
@@ -89,17 +103,12 @@ jobs:
89103 # Set output for release notes
90104 echo "::set-output name=notes::$(printf "%b" "$release_notes")"
91105
92- - name : Debug Release Notes
93- run : |
94- echo "Debugging Release Notes:"
95- echo "${{ steps.release_notes.outputs.notes }}"
96-
97106 - name : Create GitHub Release
98107 uses : softprops/action-gh-release@v2
108+ if : github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/'))
99109 with :
100- tag_name : ${{ github.ref_name }}
110+ tag_name : ${{ steps.create_tag.outputs.tag || github.ref_name }}
101111 body : ${{ steps.release_notes.outputs.notes }}
102112 files : ${{github.workspace}}/${{ github.event.repository.name }}.zip
103-
104- env :
105- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
113+ env :
114+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments