Skip to content

Commit 73ffca4

Browse files
authored
Merge pull request #4 from Mirantis/sync_workflow
🌱workflows: add upstream sync workflow
2 parents d278b9b + 5496d63 commit 73ffca4

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Template for any upstream repository - update the upstream URL as needed
2+
#
3+
# Key Features:
4+
# - Syncs main branch daily with upstream (force sync, never fails)
5+
# - Protects hotfix/* branches from being overwritten
6+
# - Includes error handling and status reporting
7+
# - Can be triggered manually if needed
8+
9+
name: Mirror Sync with Upstream
10+
on:
11+
schedule:
12+
- cron: '0 6 * * *' # Daily at 6 AM UTC
13+
workflow_dispatch: # Allow manual trigger
14+
15+
jobs:
16+
sync:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout mirror repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0 # Full history needed for mirror operations
23+
token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Configure Git
26+
run: |
27+
git config user.name "github-actions[bot]"
28+
git config user.email "github-actions[bot]@users.noreply.github.com"
29+
30+
- name: Add upstream remote
31+
run: |
32+
# Add upstream remote (kubernetes-sigs repository)
33+
git remote add upstream https://github.com/kubernetes-sigs/cluster-api-provider-openstack.git
34+
35+
# Fetch upstream with error handling
36+
if ! git fetch upstream; then
37+
echo "::error::Failed to fetch from upstream repository"
38+
exit 1
39+
fi
40+
41+
echo "Successfully fetched from upstream"
42+
43+
- name: Force sync main branch with upstream
44+
run: |
45+
# Switch to main branch
46+
if ! git checkout main; then
47+
echo "::error::Failed to checkout main branch"
48+
exit 1
49+
fi
50+
51+
# Check if main is behind upstream
52+
BEHIND_COUNT=$(git rev-list --count main..upstream/main)
53+
echo "Main branch is $BEHIND_COUNT commits behind upstream"
54+
55+
# Reset main to exactly match upstream/main
56+
if ! git reset --hard upstream/main; then
57+
echo "::error::Failed to reset main branch to upstream/main"
58+
exit 1
59+
fi
60+
61+
# Force push to mirror
62+
if ! git push origin main --force; then
63+
echo "::error::Failed to push main branch to mirror"
64+
exit 1
65+
fi
66+
67+
echo "Successfully synced main branch with upstream"
68+
69+
- name: Clean up stale upstream tracking branches
70+
run: |
71+
# Clean up remote-tracking branches for upstream
72+
# This does NOT delete actual branches, just stale remote refs
73+
git remote prune upstream
74+
echo "Cleaned up stale upstream tracking branches"
75+
echo "Note: Only main branch is synced - hotfix/* branches are preserved"
76+
77+
- name: Report sync status
78+
run: |
79+
echo "Mirror sync completed successfully"
80+
echo "Main branch now matches upstream/main exactly"
81+
echo ""
82+
echo "Latest commits on main:"
83+
git log --oneline -5
84+
echo ""
85+
echo "Hotfix branches (preserved):"
86+
git branch | grep 'hotfix/' || echo " No hotfix branches found"
87+
echo ""
88+
echo "Mirror repository is ready for development"
89+
90+
- name: Notify on failure
91+
if: failure()
92+
run: |
93+
echo "::error::🚨 Mirror sync failed! Manual intervention required."
94+
echo "::error::Repository: mirantis/cluster-api-provider-openstack"
95+
echo "::error::Check logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"

0 commit comments

Comments
 (0)