forked from graphprotocol/graph-node
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (121 loc) · 5.06 KB
/
sync-upstream.yml
File metadata and controls
142 lines (121 loc) · 5.06 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
130
131
132
133
134
135
136
137
138
139
140
141
142
name: Sync with upstream graphprotocol/graph-node
on:
schedule:
- cron: '0 7 * * 1' # Monday 07:00 UTC
workflow_dispatch:
permissions:
contents: write
pull-requests: write
env:
UPSTREAM_URL: https://github.com/graphprotocol/graph-node.git
UPSTREAM_BRANCH: master
REVIEWER: vladzr
jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout fork (full history)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Register 'ours' merge driver
# .gitattributes maps .github/workflows/** to merge=ours; this makes that
# driver a no-op so the fork's version wins on conflicts.
run: git config merge.ours.driver true
- name: Add upstream and fetch
run: |
git remote add upstream "$UPSTREAM_URL"
git fetch upstream "$UPSTREAM_BRANCH"
- name: Check for new commits
id: check
run: |
if git merge-base --is-ancestor "upstream/$UPSTREAM_BRANCH" HEAD; then
echo "up_to_date=true" >> "$GITHUB_OUTPUT"
echo "Already up to date with upstream/$UPSTREAM_BRANCH — nothing to do."
else
echo "up_to_date=false" >> "$GITHUB_OUTPUT"
echo "Commits to sync:"
git log --oneline "HEAD..upstream/$UPSTREAM_BRANCH" | head -50
fi
- name: Create branch and merge upstream
if: steps.check.outputs.up_to_date != 'true'
id: merge
run: |
BRANCH="sync-upstream-$(date -u +%Y%m%d)"
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
echo "pre_merge_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
# If a prior same-day run left a branch behind, replace it.
git push origin --delete "$BRANCH" 2>/dev/null || true
git checkout -b "$BRANCH"
if ! git merge --no-ff --no-edit "upstream/$UPSTREAM_BRANCH"; then
echo "::error::Merge failed — conflict outside .github/workflows/. Resolve manually."
git status
git diff --name-only --diff-filter=U
exit 1
fi
- name: Detect newly-added workflow files
if: steps.check.outputs.up_to_date != 'true'
id: new_workflows
run: |
ADDED=$(git diff --name-only --diff-filter=A \
"${{ steps.merge.outputs.pre_merge_sha }}..HEAD" -- .github/workflows/)
if [ -z "$ADDED" ]; then
echo "any=false" >> "$GITHUB_OUTPUT"
echo "No new workflow files — safe to auto-merge."
else
echo "any=true" >> "$GITHUB_OUTPUT"
{
echo "list<<NEW_WF_EOF"
echo "$ADDED"
echo "NEW_WF_EOF"
} >> "$GITHUB_OUTPUT"
echo "New workflow files from upstream — auto-merge will be skipped:"
echo "$ADDED"
fi
- name: Push branch
if: steps.check.outputs.up_to_date != 'true'
run: git push -u origin "${{ steps.merge.outputs.branch }}"
- name: Open PR
if: steps.check.outputs.up_to_date != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_WF_ANY: ${{ steps.new_workflows.outputs.any }}
NEW_WF_LIST: ${{ steps.new_workflows.outputs.list }}
BRANCH: ${{ steps.merge.outputs.branch }}
run: |
if gh pr view "$BRANCH" --json number >/dev/null 2>&1; then
echo "PR already exists for $BRANCH — leaving it alone."
exit 0
fi
if [ "$NEW_WF_ANY" = "true" ]; then
NOTICE="New upstream workflow files detected — auto-merge skipped. Review and decide whether to keep or disable each:
\`\`\`
$NEW_WF_LIST
\`\`\`"
else
NOTICE="No new workflow files from upstream — auto-merge enabled. docker-publish will be dispatched after merge."
fi
BODY="Weekly automated sync with upstream \`graphprotocol/graph-node\` \`master\`.
$NOTICE
Fork-local workflow customizations are preserved via \`.gitattributes\` (\`merge=ours\` on \`.github/workflows/**\`)."
gh pr create \
--base master \
--head "$BRANCH" \
--title "Sync with graphprotocol/graph-node master ($(date -u +%Y-%m-%d))" \
--body "$BODY" \
--reviewer "$REVIEWER"
- name: Auto-merge PR (no new workflows)
if: steps.check.outputs.up_to_date != 'true' && steps.new_workflows.outputs.any == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge "${{ steps.merge.outputs.branch }}" --merge --delete-branch
- name: Dispatch docker-publish on master
if: steps.check.outputs.up_to_date != 'true' && steps.new_workflows.outputs.any == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh workflow run docker-publish.yml --ref master