Skip to content

Bump to 1.23.2

Bump to 1.23.2 #3

Workflow file for this run

---
name: Test Release
on:
push:
branches:
- release-dev
paths:
- "setup.py"
- ".github/workflows/test-release.yml"
jobs:
test-release:
name: Create GitHub Release
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Read version from setup.py
id: getversion
run: |
echo "version=$(python ./setup.py --version)" >> $GITHUB_OUTPUT
echo "Version detected: $(python ./setup.py --version)"
- name: Fetch tags
run: git fetch --tags origin
- name: Check if tag already exists
id: tagcheck
run: |
if git rev-parse "v${{ steps.getversion.outputs.version }}" >/dev/null 2>&1; then
echo "Tag v${{ steps.getversion.outputs.version }} already exists"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "Tag v${{ steps.getversion.outputs.version }} does not exist - will proceed with release"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
- name: Extract changelog for version
if: steps.tagcheck.outputs.should_release == 'true'
id: changelog
run: |
VERSION="${{ steps.getversion.outputs.version }}"
# Extract content between ## [VERSION] and the next ## [
CHANGELOG=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d' | tail -n +2)
if [ -z "$CHANGELOG" ]; then
echo "No changelog entry found for version $VERSION"
CHANGELOG="No changelog entry found. Please update CHANGELOG.md."
fi
# Use EOF delimiter for multi-line output
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
if: steps.tagcheck.outputs.should_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.getversion.outputs.version }}
name: Release v${{ steps.getversion.outputs.version }} (Test)
draft: false
prerelease: true
body: ${{ steps.changelog.outputs.notes }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Calculate next version
if: steps.tagcheck.outputs.should_release == 'true'
id: nextversion
run: |
CURRENT="${{ steps.getversion.outputs.version }}"
# Split version into parts (assumes X.Y.Z format)
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
# Bump patch version
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}"
echo "next=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "Next version will be: $NEXT_VERSION"
- name: Update setup.py version
if: steps.tagcheck.outputs.should_release == 'true'
run: |
sed -i 's/version="${{ steps.getversion.outputs.version }}"/version="${{ steps.nextversion.outputs.next }}"/' setup.py
- name: Update README.md version
if: steps.tagcheck.outputs.should_release == 'true'
run: |
sed -i 's/rev: v${{ steps.getversion.outputs.version }}/rev: v${{ steps.nextversion.outputs.next }}/g' README.md
- name: Update CHANGELOG.md
if: steps.tagcheck.outputs.should_release == 'true'
run: |
CURRENT="${{ steps.getversion.outputs.version }}"
NEXT="${{ steps.nextversion.outputs.next }}"
TODAY=$(date +%Y-%m-%d)
# Create temp file with new changelog section
cat > /tmp/changelog_update.txt << 'ENDOFCHANGELOG'
## [Unreleased]
Nothing yet.
## [NEXT_VERSION] - TODAY_PLACEHOLDER
ENDOFCHANGELOG
# Replace placeholders
sed -i "s/NEXT_VERSION/$NEXT/g" /tmp/changelog_update.txt
sed -i "s/TODAY_PLACEHOLDER/$TODAY/g" /tmp/changelog_update.txt
# Insert new section after the first "## [Unreleased]" line
sed -i "/## \[Unreleased\]/r /tmp/changelog_update.txt" CHANGELOG.md
# Remove the old "## [Unreleased]" and "Nothing yet." lines
sed -i '1,/Nothing yet\./ { /## \[Unreleased\]/d; /Nothing yet\./d }' CHANGELOG.md
# Update version comparison links at bottom
# Update [Unreleased] link
sed -i "s|\[Unreleased\]:.*|[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v$NEXT...HEAD|" CHANGELOG.md
# Add new version link after [Unreleased]
sed -i "/\[Unreleased\]:/a [$NEXT]: https://github.com/homebysix/pre-commit-macadmin/compare/v$CURRENT...v$NEXT" CHANGELOG.md
- name: Commit version bump
if: steps.tagcheck.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add setup.py README.md CHANGELOG.md
git commit -m "Bump to ${{ steps.nextversion.outputs.next }} [skip ci]"
- name: Push changes
if: steps.tagcheck.outputs.should_release == 'true'
run: |
git push origin ${{ github.ref_name }}