-
Notifications
You must be signed in to change notification settings - Fork 2
88 lines (74 loc) · 2.52 KB
/
upstream-sync.yml
File metadata and controls
88 lines (74 loc) · 2.52 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
name: Upstream Sync
on:
schedule:
- cron: "0 9 * * 1"
workflow_dispatch:
jobs:
sync:
name: Check upstream submodule
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Check for upstream updates
id: check
run: |
cd zeroclaw
git fetch origin main
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/main)
echo "local=$LOCAL" >> "$GITHUB_OUTPUT"
echo "remote=$REMOTE" >> "$GITHUB_OUTPUT"
if [ "$LOCAL" = "$REMOTE" ]; then
echo "up_to_date=true" >> "$GITHUB_OUTPUT"
echo "Submodule is up to date"
else
echo "up_to_date=false" >> "$GITHUB_OUTPUT"
SHORT=$(echo "$REMOTE" | cut -c1-7)
echo "short_hash=$SHORT" >> "$GITHUB_OUTPUT"
COMMITS=$(git log --oneline "$LOCAL".."$REMOTE")
echo "New commits:"
echo "$COMMITS"
{
echo "commits<<EOF"
echo "$COMMITS"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi
- name: Create sync branch and PR
if: steps.check.outputs.up_to_date == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="chore/upstream-sync-${{ steps.check.outputs.short_hash }}"
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
echo "Branch $BRANCH already exists, skipping"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
cd zeroclaw
git checkout origin/main
cd ..
git add zeroclaw
git commit -m "chore(upstream): update zeroclaw submodule to ${{ steps.check.outputs.short_hash }}"
git push origin "$BRANCH"
BODY="## Upstream ZeroClaw Update
Updated zeroclaw submodule to \`${{ steps.check.outputs.short_hash }}\`.
### New upstream commits
\`\`\`
${{ steps.check.outputs.commits }}
\`\`\`
> Auto-generated by the upstream-sync workflow."
gh pr create \
--title "chore(upstream): update zeroclaw to ${{ steps.check.outputs.short_hash }}" \
--body "$BODY" \
--label "dependencies,upstream-sync" \
--base main \
--head "$BRANCH"