Skip to content

Update release.yml (#63) #179

Update release.yml (#63)

Update release.yml (#63) #179

Workflow file for this run

name: Automated Release
on:
push:
branches: [main, next]
permissions:
contents: write
actions: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
if: |
startsWith(github.event.head_commit.message, 'feat') ||
startsWith(github.event.head_commit.message, 'Feature') ||
startsWith(github.event.head_commit.message, 'Release') ||
startsWith(github.event.head_commit.message, 'fix') ||
startsWith(github.event.head_commit.message, 'Fixes')
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Bump version and create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
# Fetch latest semver tag
LATEST_TAG=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1 || true)
LATEST_TAG=$(echo "$LATEST_TAG" | tr -d '[:space:]')
CURRENT_VERSION="${LATEST_TAG:-0.0.0}"
IFS='.' read -r MAJOR MINOR PATCH <<EOF
$CURRENT_VERSION
EOF
case "$COMMIT_MESSAGE" in
feat!*) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
Release*) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
feat:*) MINOR=$((MINOR + 1)); PATCH=0 ;;
Feature:*) MINOR=$((MINOR + 1)); PATCH=0 ;;
fix!:*) PATCH=$((PATCH + 1)) ;;
fix:*) PATCH=$((PATCH + 1)) ;;
Fixes:*) PATCH=$((PATCH + 1)) ;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
BRANCH_NAME="${GITHUB_REF_NAME}"
if [ "$BRANCH_NAME" = "main" ]; then
RELEASE_TAG="$NEW_VERSION"
RELEASE_TITLE="Release $NEW_VERSION"
IS_PRERELEASE=false
else
TEMP_TAG="next-$NEW_VERSION"
RELEASE_TAG="$NEW_VERSION" # Final tag without "next-"
RELEASE_TITLE="Release $NEW_VERSION" # Title without "next-"
IS_PRERELEASE=false # Non-prerelease for next branch
fi
echo "Bumping version to $RELEASE_TAG"
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
# Tag with "next-" for next branch, then rename
if [ "$BRANCH_NAME" = "next" ]; then
git tag -a "$TEMP_TAG" -m "$TEMP_TAG"
git push origin "$TEMP_TAG"
git tag -a "$RELEASE_TAG" -m "$RELEASE_TAG"
git push origin "$RELEASE_TAG"
git push origin --delete "$TEMP_TAG"
else
git tag -a "$RELEASE_TAG" -m "$RELEASE_TAG"
git push origin "$RELEASE_TAG"
fi
if [ -n "$LATEST_TAG" ]; then
RELEASE_NOTES=$(git log "$LATEST_TAG"..HEAD --pretty=format:"- %s")
else
RELEASE_NOTES=$(git log --pretty=format:"- %s")
fi
gh release create "$RELEASE_TAG" \
--title "$RELEASE_TITLE" \
--notes "$RELEASE_NOTES" \
--prerelease="$IS_PRERELEASE"