Skip to content

Commit 899c713

Browse files
committed
Auto-bump version after release
1 parent b8788e0 commit 899c713

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

.github/workflows/test-release.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,70 @@ jobs:
7070
body: ${{ steps.changelog.outputs.notes }}
7171
env:
7272
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Calculate next version
75+
if: steps.tagcheck.outputs.should_release == 'true'
76+
id: nextversion
77+
run: |
78+
CURRENT="${{ steps.getversion.outputs.version }}"
79+
# Split version into parts (assumes X.Y.Z format)
80+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
81+
# Bump patch version
82+
NEXT_PATCH=$((PATCH + 1))
83+
NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}"
84+
echo "next=$NEXT_VERSION" >> $GITHUB_OUTPUT
85+
echo "Next version will be: $NEXT_VERSION"
86+
87+
- name: Update setup.py version
88+
if: steps.tagcheck.outputs.should_release == 'true'
89+
run: |
90+
sed -i 's/version="${{ steps.getversion.outputs.version }}"/version="${{ steps.nextversion.outputs.next }}"/' setup.py
91+
92+
- name: Update README.md version
93+
if: steps.tagcheck.outputs.should_release == 'true'
94+
run: |
95+
sed -i 's/rev: v${{ steps.getversion.outputs.version }}/rev: v${{ steps.nextversion.outputs.next }}/g' README.md
96+
97+
- name: Update CHANGELOG.md
98+
if: steps.tagcheck.outputs.should_release == 'true'
99+
run: |
100+
CURRENT="${{ steps.getversion.outputs.version }}"
101+
NEXT="${{ steps.nextversion.outputs.next }}"
102+
TODAY=$(date +%Y-%m-%d)
103+
104+
# Create temp file with new changelog section
105+
cat > /tmp/changelog_update.txt << 'ENDOFCHANGELOG'
106+
## [Unreleased]
107+
108+
Nothing yet.
109+
110+
## [NEXT_VERSION] - TODAY_PLACEHOLDER
111+
ENDOFCHANGELOG
112+
113+
# Replace placeholders
114+
sed -i "s/NEXT_VERSION/$NEXT/g" /tmp/changelog_update.txt
115+
sed -i "s/TODAY_PLACEHOLDER/$TODAY/g" /tmp/changelog_update.txt
116+
117+
# Insert new section after the first "## [Unreleased]" line
118+
sed -i "/## \[Unreleased\]/r /tmp/changelog_update.txt" CHANGELOG.md
119+
# Remove the old "## [Unreleased]" and "Nothing yet." lines
120+
sed -i '1,/Nothing yet\./ { /## \[Unreleased\]/d; /Nothing yet\./d }' CHANGELOG.md
121+
122+
# Update version comparison links at bottom
123+
# Update [Unreleased] link
124+
sed -i "s|\[Unreleased\]:.*|[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v$NEXT...HEAD|" CHANGELOG.md
125+
# Add new version link after [Unreleased]
126+
sed -i "/\[Unreleased\]:/a [$NEXT]: https://github.com/homebysix/pre-commit-macadmin/compare/v$CURRENT...v$NEXT" CHANGELOG.md
127+
128+
- name: Commit version bump
129+
if: steps.tagcheck.outputs.should_release == 'true'
130+
run: |
131+
git config user.name "github-actions[bot]"
132+
git config user.email "github-actions[bot]@users.noreply.github.com"
133+
git add setup.py README.md CHANGELOG.md
134+
git commit -m "Bump version to ${{ steps.nextversion.outputs.next }}"
135+
136+
- name: Push changes
137+
if: steps.tagcheck.outputs.should_release == 'true'
138+
run: |
139+
git push origin ${{ github.ref_name }}

0 commit comments

Comments
 (0)