Skip to content

Commit ab746bb

Browse files
authored
feat(ci): sync upstream ci (#41)
2 parents 27ee514 + b7048b5 commit ab746bb

File tree

1 file changed

+72
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)