Skip to content

Commit b0f5786

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

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
PR_NUMBER=$(gh pr list \
60+
--repo ${{ github.repository }} \
61+
--head "$BRANCH" \
62+
--base main \
63+
--state open \
64+
--json number \
65+
--jq '.[0].number')
66+
67+
if [ -n "$PR_NUMBER" ]; then
68+
echo "Updating existing PR #$PR_NUMBER"
69+
gh pr edit $PR_NUMBER --repo ${{ github.repository }} --title "🔄 Sync with upstream - $COMMITS commits"
70+
gh pr comment $PR_NUMBER --repo ${{ github.repository }} --body "🔄 Updated on $(date +%Y-%m-%d) with $COMMITS total commits"
71+
else
72+
echo "Creating new PR"
73+
gh pr create \
74+
--title "🔄 Sync with upstream - $COMMITS commits" \
75+
--body "Automated sync with upstream repository" \
76+
--head $BRANCH \
77+
--base main \
78+
--repo ${{ github.repository }}
79+
fi

0 commit comments

Comments
 (0)