docs: improve readability #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Automated Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
runs-on: macos-latest | |
steps: | |
# Checkout the repository with full commit history | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Set up Swift environment | |
- name: Setup Swift | |
uses: swift-actions/setup-swift@v2 | |
with: | |
swift-version: "6.1" | |
# Resolve Swift package dependencies | |
- name: Resolve dependencies | |
run: swift package resolve | |
# Run tests to validate the package | |
- name: Run tests | |
run: swift test | |
continue-on-error: false | |
# Install GitHub CLI for release creation | |
- name: Setup GitHub CLI | |
run: | | |
brew install gh | |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token | |
# Bump version, create tag, and release | |
- name: Bump version and create release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
#!/bin/bash | |
set -e | |
# Get the current version from VERSION file (default to 0.0.0 if not exists) | |
CURRENT_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0") | |
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" | |
# Get the latest commit message | |
COMMIT_MESSAGE=$(git log -1 --pretty=%B) | |
# Determine version bump based on conventional commits | |
if [[ $COMMIT_MESSAGE =~ ^feat!.* ]]; then | |
# Major bump for breaking changes | |
MAJOR=$((MAJOR + 1)) | |
MINOR=0 | |
PATCH=0 | |
elif [[ $COMMIT_MESSAGE =~ ^feat:.* ]]; then | |
# Minor bump for features | |
MINOR=$((MINOR + 1)) | |
PATCH=0 | |
elif [[ $COMMIT_MESSAGE =~ ^fix:.* ]]; then | |
# Patch bump for fixes | |
PATCH=$((PATCH + 1)) | |
else | |
echo "No version bump needed (commit: $COMMIT_MESSAGE)" | |
exit 0 | |
fi | |
# Form the new version | |
NEW_VERSION="$MAJOR.$MINOR.$PATCH" | |
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION" | |
# Update VERSION file | |
echo "$NEW_VERSION" > VERSION | |
# Commit version changes | |
git config user.name "GitHub Actions" | |
git config user.email "actions@github.com" | |
git add VERSION | |
git commit -m "chore(release): bump version to $NEW_VERSION [skip ci]" || echo "No changes to commit" | |
git push origin main | |
# Create and push tag | |
git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION" | |
git push origin "v$NEW_VERSION" | |
# Generate release notes from commit message | |
RELEASE_NOTES="Automated release for v$NEW_VERSION\n\nChanges:\n- $COMMIT_MESSAGE" | |
# Create GitHub release | |
gh release create "v$NEW_VERSION" \ | |
--title "Release v$NEW_VERSION" \ | |
--notes "$RELEASE_NOTES" \ | |
--latest |