Skip to content

Commit 00ae619

Browse files
Allow a single branch to be specified for sync-feature-branches
1 parent f9ef902 commit 00ae619

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

.github/workflows/sync-feature-branches.yaml

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ name: Sync Feature Branches
1818

1919
on:
2020
workflow_dispatch:
21+
inputs:
22+
branch:
23+
description: 'Specific feature branch to sync (e.g., feature/PROJ-123-my-feature). Leave empty to sync all feature branches.'
24+
required: false
25+
type: string
26+
default: ''
2127
schedule:
2228
# Run every Monday at 9am PT (5pm UTC)
2329
- cron: '0 17 * * 1'
@@ -42,41 +48,52 @@ jobs:
4248
- name: Find and sync feature branches
4349
env:
4450
GH_TOKEN: ${{ github.token }}
51+
INPUT_BRANCH: ${{ inputs.branch }}
4552
run: |
4653
set -e
47-
48-
echo "🔍 Finding feature branches..."
49-
50-
# Get all remote feature branches
51-
feature_branches=$(git branch -r | grep 'origin/feature/' | sed 's|origin/||' | grep -v HEAD || true)
52-
53-
if [ -z "$feature_branches" ]; then
54-
echo "ℹ️ No feature branches found matching pattern 'feature/*'"
55-
exit 0
54+
55+
if [ -n "$INPUT_BRANCH" ]; then
56+
echo "🔍 Syncing specific branch: $INPUT_BRANCH"
57+
# Validate the branch exists
58+
if ! git ls-remote --exit-code --heads origin "$INPUT_BRANCH" > /dev/null 2>&1; then
59+
echo "❌ Error: Branch '$INPUT_BRANCH' does not exist on remote"
60+
exit 1
61+
fi
62+
feature_branches="$INPUT_BRANCH"
63+
else
64+
echo "🔍 Finding feature branches..."
65+
66+
# Get all remote feature branches
67+
feature_branches=$(git branch -r | grep 'origin/feature/' | sed 's|origin/||' | grep -v HEAD || true)
68+
69+
if [ -z "$feature_branches" ]; then
70+
echo "ℹ️ No feature branches found matching pattern 'feature/*'"
71+
exit 0
72+
fi
5673
fi
57-
74+
5875
echo "Found feature branches:"
5976
echo "$feature_branches"
6077
echo ""
61-
78+
6279
# Process each feature branch
6380
for branch in $feature_branches; do
6481
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
6582
echo "📋 Processing branch: $branch"
66-
83+
6784
# Check if main has commits not in the feature branch
6885
git fetch origin main
6986
git fetch origin "$branch"
70-
87+
7188
commits_behind=$(git rev-list --count origin/$branch..origin/main)
72-
89+
7390
if [ "$commits_behind" -eq 0 ]; then
7491
echo "✅ Branch $branch is already up to date with main"
7592
continue
7693
fi
77-
94+
7895
echo "📊 Branch $branch is $commits_behind commit(s) behind main"
79-
96+
8097
# Extract issue number from branch name (format: feature/PROJ-NNN-short-slug)
8198
# If no PROJ-NNN pattern is found, use "Issue - None"
8299
issue_number=$(echo "$branch" | grep -oE 'PROJ-[0-9]+' || echo "")
@@ -85,13 +102,13 @@ jobs:
85102
else
86103
issue_ref="Issue #$issue_number"
87104
fi
88-
105+
89106
# Create a temporary branch for the merge
90107
temp_branch="sync/$branch/$(date +%Y%m%d-%H%M)"
91-
108+
92109
echo "🌿 Creating temporary branch: $temp_branch"
93110
git checkout -b "$temp_branch" "origin/$branch"
94-
111+
95112
# Attempt to merge main
96113
echo "🔀 Merging main into $temp_branch..."
97114
if git merge origin/main --no-commit --no-ff; then
@@ -102,50 +119,50 @@ jobs:
102119
git add -A
103120
git commit -m "Merge main into $branch"
104121
fi
105-
122+
106123
# Push the temporary branch
107124
echo "⬆️ Pushing $temp_branch to remote..."
108125
git push origin "$temp_branch"
109-
126+
110127
# Create PR
111128
echo "📝 Creating pull request..."
112-
129+
113130
gh pr create \
114131
--base "$branch" \
115132
--head "$temp_branch" \
116133
--title "Sync main into $branch" \
117134
--body "$(cat <<EOF
118135
## Description
119-
136+
120137
This automated PR merges the latest changes from \`main\` into \`$branch\`.
121-
138+
122139
**What to do:**
123140
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.
124-
141+
125142
**Branch Info:**
126143
- **Target**: \`$branch\`
127144
- **Source**: \`main\`
128145
- **Commits behind**: $commits_behind
129-
146+
130147
$issue_ref
131-
148+
132149
## Checklist
133150
- [ ] I am familiar with the [Contributing Guidelines](https://github.com/NVIDIA/OSMO/blob/main/CONTRIBUTING.md).
134151
- [ ] New or existing tests cover these changes.
135152
- [ ] The documentation is up to date with these changes.
136-
153+
137154
---
138155
*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).*
139156
EOF
140157
)"
141-
158+
142159
echo "✅ Created PR to sync main into $branch"
143-
160+
144161
# Switch back to main for next iteration
145162
git checkout main
146-
163+
147164
done
148-
165+
149166
echo ""
150167
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
151168
echo "✨ Sync process complete!"

0 commit comments

Comments
 (0)