Skip to content

Commit 75741cb

Browse files
authored
chore: implement automated releases
1 parent 3b8eeff commit 75741cb

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

.github/workflows/release.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Automated Release
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
release:
8+
runs-on: macos-latest
9+
steps:
10+
# Checkout the repository with full commit history
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
# Set up Swift environment
17+
- name: Setup Swift
18+
uses: swift-actions/setup-swift@v2
19+
with:
20+
swift-version: "6.1"
21+
22+
# Resolve Swift package dependencies
23+
- name: Resolve dependencies
24+
run: swift package resolve
25+
26+
# Run tests to validate the package
27+
- name: Run tests
28+
run: swift test
29+
continue-on-error: false
30+
31+
# Install GitHub CLI for release creation
32+
- name: Setup GitHub CLI
33+
run: |
34+
brew install gh
35+
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
36+
37+
# Bump version, create tag, and release
38+
- name: Bump version and create release
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
run: |
42+
#!/bin/bash
43+
set -e
44+
45+
# Get the current version from VERSION file (default to 0.0.0 if not exists)
46+
CURRENT_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0")
47+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
48+
49+
# Get the latest commit message
50+
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
51+
52+
# Determine version bump based on conventional commits
53+
if [[ $COMMIT_MESSAGE =~ ^feat!.* ]]; then
54+
# Major bump for breaking changes
55+
MAJOR=$((MAJOR + 1))
56+
MINOR=0
57+
PATCH=0
58+
elif [[ $COMMIT_MESSAGE =~ ^feat:.* ]]; then
59+
# Minor bump for features
60+
MINOR=$((MINOR + 1))
61+
PATCH=0
62+
elif [[ $COMMIT_MESSAGE =~ ^fix:.* ]]; then
63+
# Patch bump for fixes
64+
PATCH=$((PATCH + 1))
65+
else
66+
echo "No version bump needed (commit: $COMMIT_MESSAGE)"
67+
exit 0
68+
fi
69+
70+
# Form the new version
71+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
72+
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
73+
74+
# Update VERSION file
75+
echo "$NEW_VERSION" > VERSION
76+
77+
# Commit version changes
78+
git config user.name "GitHub Actions"
79+
git config user.email "actions@github.com"
80+
git add VERSION
81+
git commit -m "chore(release): bump version to $NEW_VERSION [skip ci]" || echo "No changes to commit"
82+
git push origin main
83+
84+
# Create and push tag
85+
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
86+
git push origin "v$NEW_VERSION"
87+
88+
# Generate release notes from commit message
89+
RELEASE_NOTES="Automated release for v$NEW_VERSION\n\nChanges:\n- $COMMIT_MESSAGE"
90+
91+
# Create GitHub release
92+
gh release create "v$NEW_VERSION" \
93+
--title "Release v$NEW_VERSION" \
94+
--notes "$RELEASE_NOTES" \
95+
--latest

0 commit comments

Comments
 (0)