1+ name : Sync Fork with Upstream
2+
3+ on :
4+ pull_request :
5+ types :
6+ - opened
7+ - reopened
8+ - synchronize
9+ branches :
10+ - main
11+ schedule :
12+ - cron : ' 0 2 * * *'
13+ workflow_dispatch :
14+
15+ jobs :
16+ sync :
17+ runs-on : ubuntu-latest
18+ permissions :
19+ contents : write
20+ pull-requests : write
21+
22+ steps :
23+ - uses : actions/checkout@v5
24+ with :
25+ fetch-depth : 0
26+
27+ - name : Configure Git
28+ run : |
29+ git config user.name "github-actions[bot]"
30+ git config user.email "github-actions[bot]@users.noreply.github.com"
31+ git config merge.theirs.driver true
32+
33+ - name : Sync with upstream
34+ run : |
35+ git remote add upstream https://github.com/CloudPirates-io/helm-charts.git
36+ git fetch upstream main
37+ git fetch origin
38+
39+ BRANCH="automated-upstream-sync"
40+
41+ if git ls-remote --heads origin $BRANCH | grep $BRANCH; then
42+ echo "Updating existing branch"
43+ git checkout $BRANCH
44+ else
45+ echo "Creating new branch"
46+ git checkout -b $BRANCH
47+ fi
48+
49+ git merge upstream/main --no-edit
50+ git push origin $BRANCH --force-with-lease
51+
52+ - name : Create or update PR
53+ env :
54+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
55+ run : |
56+ BRANCH="automated-upstream-sync"
57+ COMMITS=$(git rev-list --count origin/main..origin/$BRANCH)
58+
59+ # Check if PR exists
60+ PR_NUMBER=$(gh pr list --head $BRANCH --state open --json number --jq '.[0].number')
61+
62+ if [ -n "$PR_NUMBER" ]; then
63+ echo "Updating existing PR #$PR_NUMBER"
64+ gh pr edit $PR_NUMBER --title "🔄 Sync with upstream - $COMMITS commits"
65+ gh pr comment $PR_NUMBER --body "🔄 Updated on $(date +%Y-%m-%d) with $COMMITS total commits"
66+ else
67+ echo "Creating new PR"
68+ gh pr create \
69+ --title "🔄 Sync with upstream - $COMMITS commits" \
70+ --body "Automated sync with upstream repository" \
71+ --head $BRANCH \
72+ --base main \
73+ --repo ${{ github.repository }}
74+ fi
0 commit comments