1- name : Release
1+ name : Release and Publish
22
33on :
4- push :
5- tags :
6- - ' v*'
4+ release :
5+ types : [published]
76
87jobs :
9- update-version -and-release :
8+ update-changelog -and-publish :
109 runs-on : ubuntu-latest
1110 permissions :
1211 contents : write
13- id-token : write
12+ id-token : write # IMPORTANT: this permission is mandatory for trusted publishing
1413
1514 steps :
1615 - name : Checkout code
1716 uses : actions/checkout@v5
1817 with :
1918 fetch-depth : 0
20- token : ${{ secrets.GITHUB_TOKEN }}
19+ ref : main
2120
22- - name : Extract version from tag
21+ - name : Configure Git
22+ uses : ./.github/actions/configure-git
23+
24+ - name : Extract version from release
2325 id : extract_version
2426 run : |
25- TAG_NAME=${GITHUB_REF#refs/tags/ }
27+ TAG_NAME=${{ github.event.release.tag_name } }
2628 VERSION=${TAG_NAME#v}
2729 echo "version=$VERSION" >> $GITHUB_OUTPUT
2830 echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
2931
30- - name : Update version file
31- run : |
32- VERSION="${{ steps.extract_version.outputs.version }}"
33- sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb
34-
35- - name : Extract release notes from GitHub release
36- id : release_notes
37- run : |
38- RELEASE_NOTES=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
39- "https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.extract_version.outputs.tag_name }}" \
40- | jq -r '.body // ""')
41-
42- # Escape newlines and quotes for use in sed
43- RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed 's/$/\\n/' | tr -d '\n' | sed 's/\\n$//' | sed 's/"/\\"/g')
44- echo "release_notes=$RELEASE_NOTES" >> $GITHUB_OUTPUT
45-
4632 - name : Update CHANGELOG
4733 run : |
4834 VERSION="${{ steps.extract_version.outputs.version }}"
4935 CURRENT_DATE=$(date +%Y-%m-%d)
50- RELEASE_NOTES="${{ steps.release_notes.outputs.release_notes }}"
36+ RELEASE_NOTES="${{ github.event.release.body }}"
5137
5238 # Create temporary changelog entry
5339 echo "## [$VERSION] - $CURRENT_DATE" > temp_changelog.md
5440 echo "" >> temp_changelog.md
41+
42+ # Add release notes from GitHub release
5543 if [ -n "$RELEASE_NOTES" ]; then
56- echo -e "$RELEASE_NOTES" >> temp_changelog.md
44+ echo "$RELEASE_NOTES" >> temp_changelog.md
5745 else
58- echo "- Release $VERSION " >> temp_changelog.md
46+ echo "- Release ${{ steps.extract_version.outputs.tag_name }} " >> temp_changelog.md
5947 fi
6048 echo "" >> temp_changelog.md
6149
@@ -68,17 +56,17 @@ jobs:
6856 echo "# Changelog" > CHANGELOG.md
6957 echo "" >> CHANGELOG.md
7058 cat temp_changelog.md >> CHANGELOG.md
71- rm temp_changelog.md
59+
60+ # Clean up temporary file
61+ rm -f temp_changelog.md
7262
73- - name : Commit version and CHANGELOG updates
63+ - name : Commit CHANGELOG update
7464 run : |
75- git config --local user.email "action@github.com"
76- git config --local user.name "GitHub Action"
77- git add lib/structured_params/version.rb CHANGELOG.md
65+ git add CHANGELOG.md
7866 if git diff --staged --quiet; then
79- echo "No changes to commit"
67+ echo "No CHANGELOG changes to commit"
8068 else
81- git commit -m "Release ${{ steps.extract_version.outputs.tag_name }}: Update version and CHANGELOG "
69+ git commit -m "Update CHANGELOG for ${{ steps.extract_version.outputs.tag_name }}"
8270 git push origin main
8371 fi
8472
9482
9583 - name : Publish to RubyGems
9684 run : |
97- mkdir -p ~/.gem
98- echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}" > ~/.gem/credentials
99- chmod 0600 ~/.gem/credentials
10085 gem push structured_params-*.gem
101- env :
102- RUBYGEMS_API_KEY : ${{ secrets.RUBYGEMS_API_KEY }}
0 commit comments