Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 54 additions & 37 deletions .github/workflows/ci-cd-versioned.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,15 @@ jobs:
TAG=""
IS_RELEASE="false"
else
# Push to main after PR merge: Detect bump from actual merge commit parents
# A merge commit has 2 parents: the target branch and the source branch
# We can check which branch the second parent belongs to
# Push to main after PR merge: Detect bump from merge commit or squash merge
BRANCH_TYPE=""

if git rev-parse HEAD^2 &>/dev/null; then
# This is a merge commit (has 2 parents)
MERGE_COMMIT_PARENT=$(git rev-parse HEAD^2)

# Check which branches contain this commit
# The source branch should contain the second parent
BRANCH_TYPE=""

# Check if commit came from alpha
if git branch -r --contains "$MERGE_COMMIT_PARENT" | grep -q "origin/alpha"; then
Expand All @@ -152,35 +150,37 @@ jobs:
# Check if commit came from bugfix/*
elif git branch -r --contains "$MERGE_COMMIT_PARENT" | grep -q "origin/bugfix/"; then
BRANCH_TYPE="bugfix"
else
# Could be from a deleted branch - try to get PR info from GitHub API
MERGE_COMMIT_MSG=$(git log -1 --pretty=%B)
PR_NUMBER=$(echo "$MERGE_COMMIT_MSG" | grep -oP '\(#\K[0-9]+(?=\))' || echo "")

if [ -n "$PR_NUMBER" ]; then
PR_INFO=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
LAST_PR_BRANCH=$(echo "$PR_INFO" | grep -oP '"ref":\s*"\K[^"]+' | head -1)

if [[ "$LAST_PR_BRANCH" == "alpha" ]]; then
BRANCH_TYPE="alpha"
elif [[ "$LAST_PR_BRANCH" == "beta" ]]; then
BRANCH_TYPE="beta"
elif [[ "$LAST_PR_BRANCH" =~ ^feature/ ]]; then
BRANCH_TYPE="feature"
elif [[ "$LAST_PR_BRANCH" =~ ^bugfix/ ]]; then
BRANCH_TYPE="bugfix"
fi
fi
fi
fi

# If not a merge commit or branch not found, check for squash merge via API
if [ -z "$BRANCH_TYPE" ]; then
MERGE_COMMIT_MSG=$(git log -1 --pretty=%B)
PR_NUMBER=$(echo "$MERGE_COMMIT_MSG" | grep -oP '\(#\K[0-9]+(?=\))' || echo "")

if [ -z "$BRANCH_TYPE" ]; then
BRANCH_TYPE="unknown"
echo "⚠️ Warning: Could not determine source branch type"
if [ -n "$PR_NUMBER" ]; then
echo "🔍 Detected PR #${PR_NUMBER}, querying GitHub API for source branch..."
PR_INFO=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER")
LAST_PR_BRANCH=$(echo "$PR_INFO" | grep -oP '"ref":\s*"\K[^"]+' | head -1)
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grep pattern '"ref":\s*"\K[^"]+' will match any "ref" field in the JSON response. The GitHub PR API returns multiple "ref" fields (for both head.ref and base.ref). Using | head -1 to get the first match is unreliable because JSON field ordering is not guaranteed. This could potentially extract the base (target) branch instead of the head (source) branch.

Consider using a more specific pattern or using jq to parse the JSON properly:

LAST_PR_BRANCH=$(echo "$PR_INFO" | jq -r '.head.ref')

Or with grep, be more specific:

LAST_PR_BRANCH=$(echo "$PR_INFO" | grep -oP '"head":[^}]*"ref":\s*"\K[^"]+')
Suggested change
LAST_PR_BRANCH=$(echo "$PR_INFO" | grep -oP '"ref":\s*"\K[^"]+' | head -1)
LAST_PR_BRANCH=$(echo "$PR_INFO" | jq -r '.head.ref')

Copilot uses AI. Check for mistakes.

if [[ "$LAST_PR_BRANCH" == "alpha" ]]; then
BRANCH_TYPE="alpha"
elif [[ "$LAST_PR_BRANCH" == "beta" ]]; then
BRANCH_TYPE="beta"
elif [[ "$LAST_PR_BRANCH" =~ ^feature/ ]]; then
BRANCH_TYPE="feature"
elif [[ "$LAST_PR_BRANCH" =~ ^bugfix/ ]]; then
BRANCH_TYPE="bugfix"
fi

echo "✅ Source branch from API: ${LAST_PR_BRANCH} -> type: ${BRANCH_TYPE}"
fi
else
# Not a merge commit, treat as direct push
fi

if [ -z "$BRANCH_TYPE" ]; then
BRANCH_TYPE="unknown"
echo "⚠️ Warning: Could not determine source branch type"
fi

case "$BRANCH_TYPE" in
Expand Down Expand Up @@ -488,16 +488,26 @@ jobs:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Check if merge commit
- name: Check if merge commit or squash merge
id: check_merge
run: |
# Check if this is a merge commit (has 2 parents)
if git rev-parse HEAD^2 &>/dev/null; then
echo "is_merge=true" >> $GITHUB_OUTPUT
echo "✅ This is a merge commit"
echo "merge_type=merge" >> $GITHUB_OUTPUT
echo "✅ This is a merge commit (2 parents)"
else
echo "is_merge=false" >> $GITHUB_OUTPUT
echo "ℹ️ This is a direct commit, skipping VERSION update"
# Check if this is a squash merge by looking for PR number
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MSG" =~ \(#[0-9]+\) ]]; then
echo "is_merge=true" >> $GITHUB_OUTPUT
echo "merge_type=squash" >> $GITHUB_OUTPUT
echo "✅ This is a squash merge (PR found in commit message)"
else
echo "is_merge=false" >> $GITHUB_OUTPUT
echo "merge_type=none" >> $GITHUB_OUTPUT
Comment on lines +497 to +508
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merge_type output variable is set but never used by any subsequent steps or jobs. If this is intended for debugging purposes only, consider removing it or documenting its purpose. If it's intended for future use, consider adding a comment explaining the planned usage.

If not needed, you can remove these lines to reduce clutter:

echo "merge_type=merge" >> $GITHUB_OUTPUT    # line 497
echo "merge_type=squash" >> $GITHUB_OUTPUT   # line 504  
echo "merge_type=none" >> $GITHUB_OUTPUT     # line 508

Copilot uses AI. Check for mistakes.
echo "ℹ️ This is a direct commit, skipping VERSION update"
fi
fi

- name: Update VERSION file
Expand Down Expand Up @@ -582,16 +592,23 @@ jobs:
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Check if merge commit
- name: Check if merge commit or squash merge
id: check_merge
run: |
# Check if this is a merge commit (has 2 parents)
if git rev-parse HEAD^2 &>/dev/null; then
echo "is_merge=true" >> $GITHUB_OUTPUT
echo "✅ This is a merge commit"
echo "✅ This is a merge commit (2 parents)"
else
echo "is_merge=false" >> $GITHUB_OUTPUT
echo "ℹ️ This is a direct commit, skipping branch sync"
# Check if this is a squash merge by looking for PR number
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$COMMIT_MSG" =~ \(#[0-9]+\) ]]; then
echo "is_merge=true" >> $GITHUB_OUTPUT
echo "✅ This is a squash merge (PR found in commit message)"
else
echo "is_merge=false" >> $GITHUB_OUTPUT
echo "ℹ️ This is a direct commit, skipping branch sync"
fi
fi

- name: Create beta branch if needed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-alpha
1.0.0-beta