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
2 changes: 1 addition & 1 deletion .github/workflows/helm-chart-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened]
branches: [ main, 'feature/**' ]
branches: [ main, 'feature/**', 'release/**' ]
paths:
- 'deployments/charts/**'
- '.github/workflows/helm-chart-lint.yaml'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
workflow_dispatch:
pull_request:
types: [opened, synchronize, reopened, closed]
branches: [ main, 'feature/**' ]
branches: [ main, 'feature/**', 'release/**' ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-description-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ name: PR Description Check
on:
pull_request:
types: [opened, synchronize, reopened, edited]
branches: [ main, 'feature/**' ]
branches: [ main, 'feature/**', 'release/**' ]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
Expand Down
93 changes: 56 additions & 37 deletions .github/workflows/sync-feature-branches.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,12 @@ name: Sync Feature Branches

on:
workflow_dispatch:
inputs:
branch:
description: 'Specific feature branch to sync (e.g., feature/PROJ-123-my-feature). Leave empty to sync all feature branches.'
required: false
type: string
default: ''
schedule:
# Run every Monday at 9am PT (5pm UTC)
- cron: '0 17 * * 1'
Expand All @@ -36,115 +42,128 @@ jobs:

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "OSMO CI Bot"
git config user.email "255188861+svc-osmo-ci@users.noreply.github.com"

- name: Find and sync feature branches
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ secrets.SVC_OSMO_CI_TOKEN }}
INPUT_BRANCH: ${{ inputs.branch }}
run: |
set -e

echo "🔍 Finding feature branches..."

# Get all remote feature branches
feature_branches=$(git branch -r | grep 'origin/feature/' | sed 's|origin/||' | grep -v HEAD || true)

if [ -z "$feature_branches" ]; then
echo "ℹ️ No feature branches found matching pattern 'feature/*'"
exit 0

if [ -n "$INPUT_BRANCH" ]; then
echo "🔍 Syncing specific branch: $INPUT_BRANCH"
# Validate the branch exists
if ! git ls-remote --exit-code --heads origin "$INPUT_BRANCH" > /dev/null 2>&1; then
echo "❌ Error: Branch '$INPUT_BRANCH' does not exist on remote"
exit 1
fi
feature_branches="$INPUT_BRANCH"
else
echo "🔍 Finding feature branches..."

# Get all remote feature branches
feature_branches=$(git branch -r | grep 'origin/feature/' | sed 's|origin/||' | grep -v HEAD || true)

if [ -z "$feature_branches" ]; then
echo "ℹ️ No feature branches found matching pattern 'feature/*'"
exit 0
fi
fi

echo "Found feature branches:"
echo "$feature_branches"
echo ""

# Process each feature branch
for branch in $feature_branches; do
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📋 Processing branch: $branch"

# Check if main has commits not in the feature branch
git fetch origin main
git fetch origin "$branch"

commits_behind=$(git rev-list --count origin/$branch..origin/main)

if [ "$commits_behind" -eq 0 ]; then
echo "✅ Branch $branch is already up to date with main"
continue
fi

echo "📊 Branch $branch is $commits_behind commit(s) behind main"

# Extract issue number from branch name (format: feature/PROJ-NNN-short-slug)
# If no PROJ-NNN pattern is found, use "Issue - None"
issue_number=$(echo "$branch" | grep -oE 'PROJ-[0-9]+' || echo "")
issue_number=$(echo "$branch" | grep -oE 'PROJ-[0-9]+' | grep -oE '[0-9]+' || echo "")
if [ -z "$issue_number" ]; then
issue_ref="Issue - None"
else
issue_ref="Issue #$issue_number"
fi

# Create a temporary branch for the merge
temp_branch="sync/$branch/$(date +%Y%m%d-%H%M)"

echo "🌿 Creating temporary branch: $temp_branch"
git checkout -b "$temp_branch" "origin/$branch"

# Attempt to merge main
echo "🔀 Merging main into $temp_branch..."
if git merge origin/main --no-commit --no-ff; then
echo "✅ Merge successful (no conflicts)"
git commit -m "Merge main into $branch"
else
echo "⚠️ Merge has conflicts - will create PR for manual resolution"
git add -A
git commit -m "Merge main into $branch"
fi

# Push the temporary branch
echo "⬆️ Pushing $temp_branch to remote..."
git push origin "$temp_branch"

# Create PR
echo "📝 Creating pull request..."

gh pr create \
--base "$branch" \
--head "$temp_branch" \
--title "Sync main into $branch" \
--label "external" \
--body "$(cat <<EOF
## Description

This automated PR merges the latest changes from \`main\` into \`$branch\`.

**What to do:**
Review the changes and merge this PR to keep your feature branch up to date with main. If there are merge conflicts, resolve them before merging.

**Branch Info:**
- **Target**: \`$branch\`
- **Source**: \`main\`
- **Commits behind**: $commits_behind

$issue_ref

## Checklist
- [ ] I am familiar with the [Contributing Guidelines](https://github.com/NVIDIA/OSMO/blob/main/CONTRIBUTING.md).
- [ ] New or existing tests cover these changes.
- [ ] The documentation is up to date with these changes.

---
*This PR was automatically created by the [Sync Feature Branches workflow](.github/workflows/sync-feature-branches.yaml) as part of the [Projects Process](../projects/README.md#stage-in-development).*
EOF
)"

echo "✅ Created PR to sync main into $branch"

# Switch back to main for next iteration
git checkout main

done

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✨ Sync process complete!"
Loading
Loading