@@ -25,60 +25,50 @@ jobs:
2525 # Get the merged branch name from the merge commit
2626 COMMIT_MSG=$(git log -1 --pretty=%B)
2727 echo "Commit message: $COMMIT_MSG"
28-
29- # Try to extract branch name from merge commit message
30- # Supports various formats:
31- # - "Merge branch '0.0.2_Dev'"
32- # - "Merge branch '0.0.2_Dev' into main"
33- # - "Merge pull request #123 from user/0.0.2_Dev"
34- BRANCH_NAME=$(echo "$COMMIT_MSG" | sed -n "s/.*[Mm]erge.*branch '\([^']*\)'.*/\1/p" | head -n 1)
35-
28+
29+ # Extract branch name from merge commit message (e.g., "Merge branch '0.0.2_Dev'")
30+ BRANCH_NAME=$(echo "$COMMIT_MSG" | sed -n "s/.*Merge.*branch '\([^']*\)'.*/\1/p")
31+
3632 if [ -z "$BRANCH_NAME" ]; then
37- # Try alternative format with double quotes
38- BRANCH_NAME=$(echo "$COMMIT_MSG" | sed -n "s/.*[Mm]erge .*branch \"\([^\"]*\)\".*/\1/p" | head -n 1 )
33+ # Try alternative merge message format
34+ BRANCH_NAME=$(echo "$COMMIT_MSG" | sed -n "s/.*Merge .*branch \"\([^\"]*\)\".*/\1/p")
3935 fi
40-
36+
4137 if [ -z "$BRANCH_NAME" ]; then
42- # Try GitHub pull request merge format: "Merge pull request #123 from user/branch"
43- BRANCH_NAME=$(echo "$COMMIT_MSG" | sed -n "s/.*[Mm]erge pull request.*from [^/]*\/\([^ ]*\).*/\1/p" | head -n 1)
44- fi
45-
46- if [ -z "$BRANCH_NAME" ]; then
47- # No merge commit found, try to extract version directly from commit message
38+ # No merge commit found, try to get version from commit message directly
4839 echo "::warning::No merge commit detected, trying to extract version from commit message"
4940 VERSION=$(echo "$COMMIT_MSG" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+(_[A-Za-z0-9]+)?' | head -n 1)
5041 else
5142 echo "Merged branch: $BRANCH_NAME"
5243 # Extract version from branch name (format: X.Y.Z_Dev or X.Y.Z)
53- # Supports branch names like: "0.0.2_Dev", "feature/1.2.3", "release-1.0.0_RC1"
5444 VERSION=$(echo "$BRANCH_NAME" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+(_[A-Za-z0-9]+)?' | head -n 1)
5545 fi
56-
46+
5747 if [ -z "$VERSION" ]; then
5848 echo "::error::No version found in commit message or branch name"
59- echo "::error::Commit message: $COMMIT_MSG"
60- echo "::error::Branch name: $BRANCH_NAME"
6149 exit 1
6250 fi
63-
64- echo "VERSION=$VERSION" >> $GITHUB_ENV
65- echo "Extracted version: $VERSION"
51+
52+ # Remove _Dev suffix for the release version
53+ RELEASE_VERSION=$(echo "$VERSION" | sed 's/_Dev$//')
54+
55+ echo "VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
56+ echo "Extracted version: $RELEASE_VERSION"
6657
6758 - name : Update CHANGELOG.md
6859 run : |
6960 # Get repository URL
7061 REPO_URL="https://github.com/${{ github.repository }}"
71- VERSION="${{ env.VERSION }}"
72-
62+
7363 # Get the previous release tag (exclude current version if it exists)
7464 PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+' | grep -v "^$VERSION$" | head -n 1 || true)
75-
65+
7666 # Replace [Unreleased] with [VERSION] - DATE
7767 sed -i "s/^## \[Unreleased\]/## [$VERSION] - $(date +'%Y-%m-%d')/" CHANGELOG.md
78-
68+
7969 # Add new Unreleased section at the top
8070 sed -i '/^# CHANGELOG/a\\n## [Unreleased]' CHANGELOG.md
81-
71+
8272 # Update or add version comparison links at the bottom of the file
8373 if grep -q "^\[Unreleased\]:" CHANGELOG.md; then
8474 # Update existing Unreleased link
8878 echo "" >> CHANGELOG.md
8979 echo "[Unreleased]: $REPO_URL/compare/$VERSION...HEAD" >> CHANGELOG.md
9080 fi
91-
81+
9282 # Add link for the new version
9383 if [ -n "$PREVIOUS_TAG" ]; then
9484 # Add comparison link between versions
@@ -100,67 +90,82 @@ jobs:
10090
10191 - name : Update CMakeLists.txt
10292 run : |
103- VERSION="${{ env.VERSION }}"
104- # Update version in CMakeLists.txt (searches for any VERSION variable)
105- sed -i -E "s/set\([A-Z_]*VERSION[A-Z_]* [^)]*\)/set(\0 $VERSION)/g" CMakeLists.txt || true
106- sed -i -E "s/set\([A-Z_]*LIB_VERSION[A-Z_]* [^)]*\)/set(\0 $VERSION)/g" CMakeLists.txt || true
93+ # Split version into major, minor, and build
94+ IFS='.' read -r MAJOR MINOR BUILD <<< "$VERSION"
95+
96+ # Extract repository name and convert to uppercase with underscores
97+ REPO_NAME=$(echo "${{ github.repository }}" | cut -d'/' -f2 | tr '[:lower:]' '[:upper:]' | tr '-' '_')
98+
99+ # Check if version variables exist, if not add them before register_component()
100+ if ! grep -q "set(${REPO_NAME}_LIB_MAJOR" CMakeLists.txt; then
101+ # Add version variables before register_component()
102+ sed -i "/register_component()/i # Library version\nset(${REPO_NAME}_LIB_MAJOR $MAJOR)\nset(${REPO_NAME}_LIB_MINOR $MINOR)\nset(${REPO_NAME}_LIB_BUILD $BUILD)\n" CMakeLists.txt
103+ else
104+ # Update existing version variables
105+ sed -i -E "s/set\(${REPO_NAME}_LIB_MAJOR [0-9]+\)/set(${REPO_NAME}_LIB_MAJOR $MAJOR)/" CMakeLists.txt
106+ sed -i -E "s/set\(${REPO_NAME}_LIB_MINOR [0-9]+\)/set(${REPO_NAME}_LIB_MINOR $MINOR)/" CMakeLists.txt
107+ sed -i -E "s/set\(${REPO_NAME}_LIB_BUILD [0-9]+\)/set(${REPO_NAME}_LIB_BUILD $BUILD)/" CMakeLists.txt
108+ fi
109+
110+ echo "Updated CMakeLists.txt with version $MAJOR.$MINOR.$BUILD for $REPO_NAME"
107111
108112 - name : Update idf_component.yml
109113 run : |
110- VERSION="${{ env.VERSION }}"
111114 # Update version in idf_component.yml
112115 sed -i "s/^version: .*/version: \"$VERSION\"/" idf_component.yml
113116
114117 - name : Commit and push changes
115- uses : stefanzweifel/git-auto-commit-action@v5
116- with :
117- commit_message : " Release: Update to version ${{ env.VERSION }}"
118- branch : ${{ github.ref_name }}
119-
120- - name : Generate release notes with diff
121118 run : |
122- VERSION="${{ env.VERSION }}"
123- # Get the previous release tag (without v prefix)
124- PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+' | head -n 1 || true)
125-
126- echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
119+ git config user.name "github-actions[bot]"
120+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
121+ git add CHANGELOG.md CMakeLists.txt idf_component.yml
122+ if git diff --cached --quiet; then
123+ echo "No changes to commit"
124+ else
125+ git commit -m "Release: Update to version $VERSION"
126+ git push origin ${{ github.ref_name }}
127+ fi
127128
128- if [ -n "$PREVIOUS_TAG" ]; then
129- echo "## Changes" >> $GITHUB_ENV
130- echo "" >> $GITHUB_ENV
131- git log $PREVIOUS_TAG..HEAD --pretty=format:"- %s (%h)" >> $GITHUB_ENV || true
132- echo "" >> $GITHUB_ENV
133- echo "" >> $GITHUB_ENV
134- echo "See [CHANGELOG.md](CHANGELOG.md) for full details." >> $GITHUB_ENV
129+ - name : Create and push tag
130+ run : |
131+ if git rev-parse "$VERSION" >/dev/null 2>&1; then
132+ echo "Tag $VERSION already exists, skipping tag creation"
135133 else
136- echo "## Release $VERSION" >> $GITHUB_ENV
137- echo "" >> $GITHUB_ENV
138- echo "See [CHANGELOG.md](CHANGELOG.md) for details." >> $GITHUB_ENV
134+ git tag -a " $VERSION" -m "Release $VERSION"
135+ git push origin "$VERSION"
136+ echo "Tag $VERSION created and pushed"
139137 fi
140138
141- echo "EOF" >> $GITHUB_ENV
139+ - name : Wait for tag to be available
140+ run : |
141+ echo "Waiting for tag to be fully available..."
142+ sleep 5
143+ git fetch --tags
144+ git tag -l "$VERSION"
142145
143- - name : Create and push tag
146+ - name : Generate release notes
144147 run : |
145- git config user.name "github-actions[bot]"
146- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
147- git tag -a "${{ env.VERSION }}" -m "Release ${{ env.VERSION }}"
148- git push origin "${{ env.VERSION }}"
148+ # Extract the section for the current version from CHANGELOG.md
149+ awk -v version="$VERSION" '
150+ /^## \['"$VERSION"'\]/ { found=1; next }
151+ /^## \[/ { if(found) exit }
152+ found { print }
153+ ' CHANGELOG.md > RELEASE_NOTES.md
154+
155+ # Check if we extracted anything
156+ if [ ! -s RELEASE_NOTES.md ]; then
157+ echo "## Release $VERSION" > RELEASE_NOTES.md
158+ echo "" >> RELEASE_NOTES.md
159+ echo "See [CHANGELOG.md](CHANGELOG.md) for details." >> RELEASE_NOTES.md
160+ fi
149161
150- - name : Create GitHub Release
151- uses : softprops/action-gh-release@v2
152- with :
153- tag_name : ${{ env.VERSION }}
154- name : Release ${{ env.VERSION }}
155- body : ${{ env.RELEASE_NOTES }}
156- generate_release_notes : true
162+ - name : Create Release
157163 env :
158- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
159-
160- - name : Upload component to ESP Component Registry
161- uses : espressif/upload-components-ci-action@v1
162- with :
163- name : ${{ github.event.repository.name }}
164- version : ${{ env.VERSION }}
165- namespace : ${{ github.repository_owner }}
166- api_token : ${{ secrets.IDF_COMPONENT_REGISTRY_TOKEN }}
164+ GITHUB_TOKEN : ${{ github.token }}
165+ VERSION : ${{ env.VERSION }}
166+ run : |
167+ # Create release using GitHub CLI
168+ gh release create "$VERSION" \
169+ --title "Release $VERSION" \
170+ --notes-file RELEASE_NOTES.md \
171+ --target main
0 commit comments