From 1e152ea09bf81f06ca8c77d5ee89f35590a93e0e Mon Sep 17 00:00:00 2001 From: Juan Sebastian Montoya Date: Wed, 26 Nov 2025 13:12:25 -0500 Subject: [PATCH] Feature: Add PR title validation and versioning logic to CI workflow - 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. --- .forgejo/workflows/ci.yaml | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index 811ad63..b2392b2 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -16,6 +16,21 @@ jobs: - name: Checkout 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 run: | 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} 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 # First version 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 - # Increment patch version for each merge to main + # Hotfix/Bugfix: increment patch version (0.1.5 -> 0.1.6) PATCH=$((PATCH + 1)) NEW_VERSION="$MAJOR.$MINOR.$PATCH" fi echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT + echo "version_type=$VERSION_TYPE" >> $GITHUB_OUTPUT echo "Latest tag: $LATEST_TAG" + echo "Version type: $VERSION_TYPE" echo "New version: $NEW_VERSION" echo "Current VERSION file: $(cat VERSION 2>/dev/null || echo 'not found')"