Skip to content

Commit 8c06053

Browse files
committed
Add Git configuration action and update release workflow for CHANGELOG management
1 parent 7d7b185 commit 8c06053

3 files changed

Lines changed: 79 additions & 40 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Configure Git for GitHub Actions'
2+
description: 'Configure Git user for automated commits'
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Configure Git
8+
run: |
9+
git config --local user.email "action@github.com"
10+
git config --local user.name "GitHub Action"
11+
shell: bash

.github/workflows/release.yml

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,49 @@
1-
name: Release
1+
name: Release and Publish
22

33
on:
4-
push:
5-
tags:
6-
- 'v*'
4+
release:
5+
types: [published]
76

87
jobs:
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
@@ -94,9 +82,4 @@ jobs:
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 }}

.github/workflows/tagging.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Update Version
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
update-version:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v5
17+
with:
18+
fetch-depth: 0
19+
ref: main
20+
21+
- name: Configure Git
22+
uses: ./.github/actions/configure-git
23+
24+
- name: Extract version from tag
25+
id: extract_version
26+
run: |
27+
TAG_NAME=${GITHUB_REF#refs/tags/}
28+
VERSION=${TAG_NAME#v}
29+
echo "version=$VERSION" >> $GITHUB_OUTPUT
30+
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
31+
32+
- name: Update version file
33+
run: |
34+
VERSION="${{ steps.extract_version.outputs.version }}"
35+
sed -i "s/VERSION = '[^']*'/VERSION = '$VERSION'/" lib/structured_params/version.rb
36+
37+
- name: Commit version update
38+
run: |
39+
git add lib/structured_params/version.rb
40+
if git diff --staged --quiet; then
41+
echo "No version changes to commit"
42+
else
43+
git commit -m "Update version to ${{ steps.extract_version.outputs.version }}"
44+
git push origin main
45+
fi

0 commit comments

Comments
 (0)