forked from paperclipai/paperclip
-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (109 loc) · 4.05 KB
/
Copy pathsync-upstream.yml
File metadata and controls
129 lines (109 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Sync Upstream
on:
schedule:
- cron: "0 */3 * * *"
workflow_dispatch:
concurrency:
group: sync-upstream
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Add upstream remote
run: git remote add upstream https://github.com/paperclipai/paperclip.git
- name: Fetch upstream
run: git fetch upstream master
- name: Check for new commits
id: check
run: |
behind=$(git rev-list --count HEAD..upstream/master)
echo "behind=$behind" >> "$GITHUB_OUTPUT"
if [ "$behind" -eq 0 ]; then
echo "Already up to date with upstream."
else
echo "Fork is $behind commit(s) behind upstream."
fi
- name: Rebase onto upstream
if: steps.check.outputs.behind != '0'
id: rebase
run: |
BRANCH="sync/upstream"
git config user.name "upstream-sync-bot"
git config user.email "upstream-sync-bot@users.noreply.github.com"
git checkout -B "$BRANCH"
if git rebase upstream/master; then
echo "conflict=false" >> "$GITHUB_OUTPUT"
else
git rebase --abort
echo "conflict=true" >> "$GITHUB_OUTPUT"
echo "::warning::Rebase has conflicts — manual resolution required."
fi
- name: Push sync branch
if: steps.check.outputs.behind != '0' && steps.rebase.outputs.conflict == 'false'
run: git push --force origin sync/upstream
- name: Create or update pull request
if: steps.check.outputs.behind != '0'
id: pr
env:
GH_TOKEN: ${{ github.token }}
run: |
BRANCH="sync/upstream"
behind=${{ steps.check.outputs.behind }}
conflict=${{ steps.rebase.outputs.conflict }}
existing=$(gh pr list --head "$BRANCH" --json number --jq '.[0].number')
if [ "$conflict" = "true" ]; then
title="sync: upstream has $behind new commit(s) (conflicts)"
body="$(cat <<'EOF'
## Upstream Sync
The upstream repository [paperclipai/paperclip](https://github.com/paperclipai/paperclip) has **new commits** that could not be rebased automatically due to merge conflicts.
**Manual resolution required.** Please pull the `sync/upstream` branch locally and resolve conflicts:
```bash
git fetch origin sync/upstream
git checkout sync/upstream
git rebase upstream/master
# resolve conflicts
git push --force origin sync/upstream
```
EOF
)"
else
title="sync: rebase $behind commit(s) from upstream"
body="$(cat <<'EOF'
## Upstream Sync
Automated rebase of new commits from [paperclipai/paperclip](https://github.com/paperclipai/paperclip). No conflicts detected — safe to merge.
EOF
)"
fi
if [ -z "$existing" ]; then
if [ "$conflict" = "true" ]; then
echo "Skipping PR creation — conflicts need resolution before branch can be pushed."
exit 0
fi
gh pr create \
--head "$BRANCH" \
--title "$title" \
--body "$body"
else
gh pr edit "$existing" --title "$title" --body "$body"
echo "Updated existing PR #$existing."
fi
- name: Auto-merge if clean
if: steps.check.outputs.behind != '0' && steps.rebase.outputs.conflict == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
pr_url="$(gh pr list --head sync/upstream --json url --jq '.[0].url')"
if [ -z "$pr_url" ]; then
echo "PR not found, skipping auto-merge."
exit 0
fi
gh pr merge --auto --rebase --delete-branch "$pr_url"