Skip to content

Commit 78994d2

Browse files
author
Frederic Spiers
committed
feat(ci): sync upstream ci
1 parent 27ee514 commit 78994d2

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
actions: write
22+
23+
steps:
24+
- uses: actions/checkout@v5
25+
with:
26+
fetch-depth: 0
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Configure Git
30+
run: |
31+
git config user.name "github-actions[bot]"
32+
git config user.email "github-actions[bot]@users.noreply.github.com"
33+
git config merge.theirs.driver true
34+
35+
- name: Sync with upstream
36+
run: |
37+
git remote add upstream https://github.com/CloudPirates-io/helm-charts.git
38+
git fetch upstream main
39+
git fetch origin
40+
41+
BRANCH="automated-upstream-sync"
42+
43+
if git ls-remote --heads origin $BRANCH | grep $BRANCH; then
44+
echo "Updating existing branch"
45+
git checkout $BRANCH
46+
else
47+
echo "Creating new branch"
48+
git checkout -b $BRANCH
49+
fi
50+
51+
git merge upstream/main --no-edit
52+
git push origin $BRANCH --force-with-lease
53+
54+
- name: Create or update PR
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
run: |
58+
BRANCH="automated-upstream-sync"
59+
COMMITS=$(git rev-list --count origin/main..origin/$BRANCH)
60+
61+
# Check if PR exists
62+
PR_NUMBER=$(gh pr list --head $BRANCH --state open --json number --jq '.[0].number')
63+
64+
if [ -n "$PR_NUMBER" ]; then
65+
echo "Updating existing PR #$PR_NUMBER"
66+
gh pr edit $PR_NUMBER --title "🔄 Sync with upstream - $COMMITS commits"
67+
gh pr comment $PR_NUMBER --body "🔄 Updated on $(date +%Y-%m-%d) with $COMMITS total commits"
68+
else
69+
echo "Creating new PR"
70+
gh pr create \
71+
--title "🔄 Sync with upstream - $COMMITS commits" \
72+
--body "Automated sync with upstream repository" \
73+
--head $BRANCH \
74+
--base main
75+
fi

0 commit comments

Comments
 (0)