Skip to content

Commit da1f952

Browse files
authored
Merge pull request #110 from homebysix/release-automation
Add release automation workflow
2 parents 5ee621c + 0019402 commit da1f952

5 files changed

Lines changed: 158 additions & 8 deletions

File tree

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ name: "CodeQL"
77

88
on:
99
push:
10-
branches: [master]
10+
branches: [main]
1111
pull_request:
1212
# The branches below must be a subset of the branches above
13-
branches: [master]
13+
branches: [main]
1414
schedule:
1515
- cron: '0 21 * * 3'
1616

.github/workflows/release.yml

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
name: Release
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- "setup.py"
10+
- ".github/workflows/release.yml"
11+
12+
jobs:
13+
release:
14+
name: Create GitHub Release
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout source code
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: '3.11'
25+
26+
- name: Read version from setup.py
27+
id: getversion
28+
run: |
29+
echo "version=$(python ./setup.py --version)" >> $GITHUB_OUTPUT
30+
echo "Version detected: $(python ./setup.py --version)"
31+
32+
- name: Fetch tags
33+
run: git fetch --tags origin
34+
35+
- name: Check if tag already exists
36+
id: tagcheck
37+
run: |
38+
if git rev-parse "v${{ steps.getversion.outputs.version }}" >/dev/null 2>&1; then
39+
echo "Tag v${{ steps.getversion.outputs.version }} already exists"
40+
echo "should_release=false" >> $GITHUB_OUTPUT
41+
else
42+
echo "Tag v${{ steps.getversion.outputs.version }} does not exist - will proceed with release"
43+
echo "should_release=true" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Extract changelog for version
47+
if: steps.tagcheck.outputs.should_release == 'true'
48+
id: changelog
49+
run: |
50+
VERSION="${{ steps.getversion.outputs.version }}"
51+
# Extract content between ## [VERSION] and the next ## [
52+
CHANGELOG=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d' | tail -n +2)
53+
if [ -z "$CHANGELOG" ]; then
54+
echo "No changelog entry found for version $VERSION"
55+
CHANGELOG="No changelog entry found. Please update CHANGELOG.md."
56+
fi
57+
# Use EOF delimiter for multi-line output
58+
echo "notes<<EOF" >> $GITHUB_OUTPUT
59+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
60+
echo "EOF" >> $GITHUB_OUTPUT
61+
62+
- name: Create GitHub Release
63+
if: steps.tagcheck.outputs.should_release == 'true'
64+
uses: softprops/action-gh-release@v2
65+
with:
66+
tag_name: v${{ steps.getversion.outputs.version }}
67+
name: Release v${{ steps.getversion.outputs.version }}
68+
draft: false
69+
prerelease: false
70+
body: ${{ steps.changelog.outputs.notes }}
71+
env:
72+
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 to ${{ steps.nextversion.outputs.next }} [skip ci]"
135+
136+
- name: Push changes
137+
if: steps.tagcheck.outputs.should_release == 'true'
138+
run: |
139+
git push origin main

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ All notable changes to this project will be documented in this file. This projec
1414

1515
Nothing yet.
1616

17+
## [1.24.0] - 2026-04-12
18+
19+
### Added
20+
21+
- Automated GitHub Actions workflow for creating releases and bumping versions.
22+
23+
### Changed
24+
25+
- Updated CodeQL workflow to run on `main` branch instead of `master`.
26+
1727
## [1.23.0] - 2026-03-19
1828

1929
### Added
@@ -458,7 +468,8 @@ Nothing yet.
458468

459469
- Initial release
460470

461-
[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.23.0...HEAD
471+
[Unreleased]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.24.0...HEAD
472+
[1.24.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.23.0...v1.24.0
462473
[1.23.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.22.0...v1.23.0
463474
[1.22.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.21.0...v1.22.0
464475
[1.21.0]: https://github.com/homebysix/pre-commit-macadmin/compare/v1.20.0...v1.21.0

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ For any hook in this repo you wish to use, add the following to your pre-commit
1515

1616
```yaml
1717
- repo: https://github.com/homebysix/pre-commit-macadmin
18-
rev: v1.23.0
18+
rev: v1.24.0
1919
hooks:
2020
- id: check-plists
2121
# - id: ...
@@ -147,7 +147,7 @@ When combining arguments that take lists (for example: `--required-keys`, `--cat
147147

148148
```yaml
149149
- repo: https://github.com/homebysix/pre-commit-macadmin
150-
rev: v1.23.0
150+
rev: v1.24.0
151151
hooks:
152152
- id: check-munki-pkgsinfo
153153
args: ['--catalogs', 'testing', 'stable', '--']
@@ -157,7 +157,7 @@ But if you also use the `--categories` argument, you would move the trailing `--
157157

158158
```yaml
159159
- repo: https://github.com/homebysix/pre-commit-macadmin
160-
rev: v1.23.0
160+
rev: v1.24.0
161161
hooks:
162162
- id: check-munki-pkgsinfo
163163
args: ['--catalogs', 'testing', 'stable', '--categories', 'Design', 'Engineering', 'Web Browsers', '--']
@@ -169,7 +169,7 @@ If it looks better to your eye, feel free to use a multi-line list for long argu
169169

170170
```yaml
171171
- repo: https://github.com/homebysix/pre-commit-macadmin
172-
rev: v1.23.0
172+
rev: v1.24.0
173173
hooks:
174174
- id: check-munki-pkgsinfo
175175
args: [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
name="pre-commit-macadmin",
77
description="Pre-commit hooks for Mac admins, client engineers, and IT consultants.",
88
url="https://github.com/homebysix/pre-commit-macadmin",
9-
version="1.23.0",
9+
version="1.24.0",
1010
author="Elliot Jordan",
1111
author_email="elliot@elliotjordan.com",
1212
packages=["pre_commit_macadmin_hooks"],

0 commit comments

Comments
 (0)