Skip to content

Commit 7e5be7d

Browse files
committed
Refactored release-check job
1. Detects version bumps based on conventional commit messages: - feat: or feature: triggers a minor version bump - fix: triggers a patch version bump - BREAKING CHANGE: or commits with ! trigger a major version bump 2. Calculates the next semantic version (e.g., v0.1.0 → v0.2.0 for minor bump) 3. Generates organized release notes grouped by commit type: - ✨ Features - 🐛 Bug Fixes - 📚 Documentation - 🧪 Tests - ♻️ Refactoring - 🔧 Other Changes 4. Creates and pushes a new git tag 5. Creates a GitHub Release with the generated release notes The workflow automatically handles semantic versioning and only runs on pushes to the main branch after all tests, integration tests, and benchmarks pass.
1 parent 8e8e7c4 commit 7e5be7d

File tree

1 file changed

+135
-13
lines changed

1 file changed

+135
-13
lines changed

.github/workflows/ci.yml

Lines changed: 135 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ jobs:
107107
git diff --exit-code go.mod go.sum
108108
109109
test:
110-
name: Test
110+
name: Unit & Race Tests w/Coverage
111111
runs-on: ubuntu-latest
112112
needs: security
113113

@@ -137,9 +137,6 @@ jobs:
137137
flags: unittests
138138
name: codecov-umbrella
139139

140-
- name: Run benchmarks
141-
run: go test -run=^$ -bench=. -benchmem ./...
142-
143140
integration:
144141
name: Integration Tests
145142
runs-on: ubuntu-latest
@@ -233,25 +230,150 @@ jobs:
233230
docker stop omni-test-syslog || true
234231
docker rm omni-test-syslog || true
235232
233+
benchmarks:
234+
name: Benchmarks
235+
runs-on: ubuntu-latest
236+
needs: [test, integration]
237+
238+
steps:
239+
- name: Checkout code
240+
uses: actions/checkout@v4
241+
242+
- name: Set up Go
243+
uses: actions/setup-go@v5
244+
with:
245+
go-version: '1.24.4'
246+
cache: true
247+
cache-dependency-path: go.sum
248+
249+
- name: Run benchmarks
250+
run: go test -run=^$ -bench=. -benchmem ./...
251+
236252
release-check:
237253
name: Release Check
238254
runs-on: ubuntu-latest
239255
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
240-
needs: integration
256+
needs: benchmarks
241257

242258
steps:
243259
- name: Checkout code
244260
uses: actions/checkout@v4
261+
with:
262+
fetch-depth: 0
263+
264+
- name: Get latest tag
265+
id: latest_tag
266+
run: |
267+
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
268+
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
269+
echo "Latest tag: $latest_tag"
245270
246-
- name: Check if version changed
247-
id: version
271+
- name: Check for version bump in commit messages
272+
id: version_check
248273
run: |
249-
echo "Checking for version changes..."
250-
# Add version checking logic here
274+
# Check commit messages since last tag for version bump indicators
275+
commits_since_tag=$(git log --pretty=format:"%s" ${latest_tag}..HEAD 2>/dev/null || git log --pretty=format:"%s")
276+
277+
# Look for conventional commit patterns
278+
if echo "$commits_since_tag" | grep -qE "^(feat|feature)(\(.+\))?: "; then
279+
echo "Found feature commits - minor version bump needed"
280+
echo "bump=minor" >> $GITHUB_OUTPUT
281+
elif echo "$commits_since_tag" | grep -qE "^fix(\(.+\))?: "; then
282+
echo "Found fix commits - patch version bump needed"
283+
echo "bump=patch" >> $GITHUB_OUTPUT
284+
elif echo "$commits_since_tag" | grep -qE "BREAKING CHANGE:|^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?!: "; then
285+
echo "Found breaking changes - major version bump needed"
286+
echo "bump=major" >> $GITHUB_OUTPUT
287+
else
288+
echo "No version bump needed"
289+
echo "bump=none" >> $GITHUB_OUTPUT
290+
fi
251291
252-
- name: Create Release Notes
253-
if: steps.version.outputs.changed == 'true'
292+
- name: Calculate next version
293+
id: next_version
294+
if: steps.version_check.outputs.bump != 'none'
295+
run: |
296+
current_version="${{ steps.latest_tag.outputs.latest_tag }}"
297+
# Remove 'v' prefix
298+
version=${current_version#v}
299+
300+
# Parse semantic version
301+
IFS='.' read -r major minor patch <<< "$version"
302+
303+
# Calculate next version based on bump type
304+
if [[ "${{ steps.version_check.outputs.bump }}" == "major" ]]; then
305+
major=$((major + 1))
306+
minor=0
307+
patch=0
308+
elif [[ "${{ steps.version_check.outputs.bump }}" == "minor" ]]; then
309+
minor=$((minor + 1))
310+
patch=0
311+
elif [[ "${{ steps.version_check.outputs.bump }}" == "patch" ]]; then
312+
patch=$((patch + 1))
313+
fi
314+
315+
next_version="v${major}.${minor}.${patch}"
316+
echo "next_version=$next_version" >> $GITHUB_OUTPUT
317+
echo "Next version: $next_version"
318+
319+
- name: Generate release notes
320+
id: release_notes
321+
if: steps.version_check.outputs.bump != 'none'
254322
run: |
255-
echo "## Release Notes" > release_notes.md
323+
# Generate release notes from commits
324+
echo "## What's Changed" > release_notes.md
256325
echo "" >> release_notes.md
257-
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0)..HEAD >> release_notes.md
326+
327+
# Group commits by type
328+
git log --pretty=format:"%s|%h" ${{ steps.latest_tag.outputs.latest_tag }}..HEAD | while IFS='|' read -r msg hash; do
329+
if [[ $msg =~ ^feat(\(.+\))?: ]]; then
330+
echo "### ✨ Features" >> release_notes.md.feat
331+
echo "- $msg ($hash)" >> release_notes.md.feat
332+
elif [[ $msg =~ ^fix(\(.+\))?: ]]; then
333+
echo "### 🐛 Bug Fixes" >> release_notes.md.fix
334+
echo "- $msg ($hash)" >> release_notes.md.fix
335+
elif [[ $msg =~ ^docs(\(.+\))?: ]]; then
336+
echo "### 📚 Documentation" >> release_notes.md.docs
337+
echo "- $msg ($hash)" >> release_notes.md.docs
338+
elif [[ $msg =~ ^test(\(.+\))?: ]]; then
339+
echo "### 🧪 Tests" >> release_notes.md.test
340+
echo "- $msg ($hash)" >> release_notes.md.test
341+
elif [[ $msg =~ ^refactor(\(.+\))?: ]]; then
342+
echo "### ♻️ Refactoring" >> release_notes.md.refactor
343+
echo "- $msg ($hash)" >> release_notes.md.refactor
344+
else
345+
echo "### 🔧 Other Changes" >> release_notes.md.other
346+
echo "- $msg ($hash)" >> release_notes.md.other
347+
fi
348+
done
349+
350+
# Combine sections
351+
for type in feat fix docs test refactor other; do
352+
if [ -f release_notes.md.$type ]; then
353+
cat release_notes.md.$type | sort -u >> release_notes.md
354+
echo "" >> release_notes.md
355+
rm release_notes.md.$type
356+
fi
357+
done
358+
359+
echo "" >> release_notes.md
360+
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ steps.latest_tag.outputs.latest_tag }}...${{ steps.next_version.outputs.next_version }}" >> release_notes.md
361+
362+
- name: Create and push tag
363+
if: steps.version_check.outputs.bump != 'none'
364+
run: |
365+
git config user.name github-actions
366+
git config user.email [email protected]
367+
git tag -a ${{ steps.next_version.outputs.next_version }} -m "Release ${{ steps.next_version.outputs.next_version }}"
368+
git push origin ${{ steps.next_version.outputs.next_version }}
369+
370+
- name: Create GitHub Release
371+
if: steps.version_check.outputs.bump != 'none'
372+
uses: softprops/action-gh-release@v1
373+
with:
374+
tag_name: ${{ steps.next_version.outputs.next_version }}
375+
name: Release ${{ steps.next_version.outputs.next_version }}
376+
body_path: release_notes.md
377+
draft: false
378+
prerelease: false
379+
generate_release_notes: false

0 commit comments

Comments
 (0)