Feature/new semver tagging logic (#11)
- Introduced a step to validate PR titles, ensuring they start with the correct prefixes (Release/, Feature/, Hotfix/, Bugfix/). - Enhanced versioning logic to determine version type based on PR title or merge commit message, allowing for appropriate version increments. - Improved handling of versioning for different types of changes, including major, minor, and patch updates. This update aims to enforce consistent PR title formatting and streamline version management in the CI process. Reviewed-on: #11 Co-authored-by: Juan Sebastian Montoya <juansmm@outlook.com> Co-committed-by: Juan Sebastian Montoya <juansmm@outlook.com>
This commit is contained in:
parent
379d4f6b54
commit
21402bf0b4
1 changed files with 73 additions and 2 deletions
|
|
@ -16,6 +16,21 @@ jobs:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Validate PR Title
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
run: |
|
||||||
|
PR_TITLE="${{ github.event.pull_request.title }}"
|
||||||
|
echo "PR Title: $PR_TITLE"
|
||||||
|
|
||||||
|
# Check if PR title starts with valid prefix
|
||||||
|
if [[ "$PR_TITLE" =~ ^(Release|Feature|Hotfix|Bugfix)/ ]]; then
|
||||||
|
echo "✅ PR title is valid: $PR_TITLE"
|
||||||
|
else
|
||||||
|
echo "❌ PR title must start with one of: Release/, Feature/, Hotfix/, or Bugfix/"
|
||||||
|
echo "Current title: $PR_TITLE"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Build Docker Image
|
- name: Build Docker Image
|
||||||
run: |
|
run: |
|
||||||
docker build --build-arg VERSION=test --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -t threejs-test:test .
|
docker build --build-arg VERSION=test --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") -t threejs-test:test .
|
||||||
|
|
@ -69,19 +84,75 @@ jobs:
|
||||||
MINOR=${MINOR:-0}
|
MINOR=${MINOR:-0}
|
||||||
PATCH=${PATCH:-0}
|
PATCH=${PATCH:-0}
|
||||||
|
|
||||||
# Increment patch version for each merge to main, or start at 0.1.0 if no tags exist
|
# Get PR title from event or merge commit message
|
||||||
|
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
|
||||||
|
PR_TITLE="${{ github.event.pull_request.title }}"
|
||||||
|
echo "PR Title: $PR_TITLE"
|
||||||
|
else
|
||||||
|
# For push events, check merge commit message
|
||||||
|
# Merge commits often have format: "Merge pull request #X from branch" or "PR Title (#X)"
|
||||||
|
COMMIT_MSG=$(git log -1 --pretty=format:"%s" HEAD)
|
||||||
|
echo "Commit message: $COMMIT_MSG"
|
||||||
|
|
||||||
|
# Try to extract PR title from merge commit
|
||||||
|
# Look for patterns like "Release/...", "Feature/...", etc. in the commit message
|
||||||
|
if echo "$COMMIT_MSG" | grep -qE "^(Release|Feature|Hotfix|Bugfix)/"; then
|
||||||
|
# If commit message itself starts with prefix, use it
|
||||||
|
PR_TITLE=$(echo "$COMMIT_MSG" | grep -oE "^(Release|Feature|Hotfix|Bugfix)/[^[:space:]]*" | head -1)
|
||||||
|
elif echo "$COMMIT_MSG" | grep -qE "(Release|Feature|Hotfix|Bugfix)/"; then
|
||||||
|
# Extract prefix pattern from anywhere in the message
|
||||||
|
PR_TITLE=$(echo "$COMMIT_MSG" | grep -oE "(Release|Feature|Hotfix|Bugfix)/[^[:space:]]*" | head -1)
|
||||||
|
else
|
||||||
|
# Check if it's a merge commit and try to get the original PR title
|
||||||
|
# For Forgejo, merge commits might reference the PR
|
||||||
|
PR_TITLE="$COMMIT_MSG"
|
||||||
|
echo "⚠️ Could not extract PR title prefix from commit message, using full message"
|
||||||
|
fi
|
||||||
|
echo "Extracted PR title: $PR_TITLE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Determine version type from PR title prefix
|
||||||
|
if [[ "$PR_TITLE" =~ ^Release/ ]]; then
|
||||||
|
VERSION_TYPE="release"
|
||||||
|
echo "Detected: RELEASE - incrementing major version"
|
||||||
|
elif [[ "$PR_TITLE" =~ ^Feature/ ]]; then
|
||||||
|
VERSION_TYPE="feature"
|
||||||
|
echo "Detected: FEATURE - incrementing minor version"
|
||||||
|
elif [[ "$PR_TITLE" =~ ^(Hotfix|Bugfix)/ ]]; then
|
||||||
|
VERSION_TYPE="patch"
|
||||||
|
echo "Detected: HOTFIX/BUGFIX - incrementing patch version"
|
||||||
|
else
|
||||||
|
echo "⚠️ Warning: PR title does not match expected pattern (Release/, Feature/, Hotfix/, or Bugfix/)"
|
||||||
|
echo "Defaulting to FEATURE (minor version increment)"
|
||||||
|
VERSION_TYPE="feature"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increment version based on type
|
||||||
if [[ "$LATEST_TAG" == "v0.0.0" ]]; then
|
if [[ "$LATEST_TAG" == "v0.0.0" ]]; then
|
||||||
# First version
|
# First version
|
||||||
NEW_VERSION="0.1.0"
|
NEW_VERSION="0.1.0"
|
||||||
|
elif [[ "$VERSION_TYPE" == "release" ]]; then
|
||||||
|
# Release: increment major version and reset minor/patch (0.1.5 -> 1.0.0)
|
||||||
|
MAJOR=$((MAJOR + 1))
|
||||||
|
MINOR=0
|
||||||
|
PATCH=0
|
||||||
|
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
||||||
|
elif [[ "$VERSION_TYPE" == "feature" ]]; then
|
||||||
|
# Feature: increment minor version and reset patch (0.1.5 -> 0.2.0)
|
||||||
|
MINOR=$((MINOR + 1))
|
||||||
|
PATCH=0
|
||||||
|
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
||||||
else
|
else
|
||||||
# Increment patch version for each merge to main
|
# Hotfix/Bugfix: increment patch version (0.1.5 -> 0.1.6)
|
||||||
PATCH=$((PATCH + 1))
|
PATCH=$((PATCH + 1))
|
||||||
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
|
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "version_type=$VERSION_TYPE" >> $GITHUB_OUTPUT
|
||||||
echo "Latest tag: $LATEST_TAG"
|
echo "Latest tag: $LATEST_TAG"
|
||||||
|
echo "Version type: $VERSION_TYPE"
|
||||||
echo "New version: $NEW_VERSION"
|
echo "New version: $NEW_VERSION"
|
||||||
echo "Current VERSION file: $(cat VERSION 2>/dev/null || echo 'not found')"
|
echo "Current VERSION file: $(cat VERSION 2>/dev/null || echo 'not found')"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue