Skip to content

Commit 28a200f

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

File tree

1 file changed

+74
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)