forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
164 lines (146 loc) · 5.35 KB
/
Copy pathupstream-sync.yml
File metadata and controls
164 lines (146 loc) · 5.35 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Sync Upstream
on:
schedule:
- cron: "0 6 * * *"
workflow_dispatch:
inputs:
force:
description: "Force merge even if already up-to-date"
type: boolean
default: false
jobs:
sync:
name: Sync ${{ matrix.branch }}
runs-on: ubuntu-latest
permissions:
contents: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
strategy:
fail-fast: false
matrix:
branch:
- production
- dev
steps:
- name: Checkout fork
uses: actions/checkout@v4.2.2
with:
ref: ${{ matrix.branch }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Add upstream and fetch
shell: bash
run: |
if ! git remote get-url upstream >/dev/null 2>&1; then
git remote add upstream https://github.com/anomalyco/opencode.git
fi
git fetch upstream ${{ matrix.branch }}
- name: Check if up-to-date
id: check
shell: bash
env:
FORCE_INPUT: ${{ inputs.force }}
run: |
if git merge-base --is-ancestor upstream/${{ matrix.branch }} HEAD && [[ "$FORCE_INPUT" != "true" ]]; then
echo "status=up-to-date" >> "$GITHUB_OUTPUT"
else
echo "status=pending" >> "$GITHUB_OUTPUT"
fi
- name: Attempt merge
id: merge
if: steps.check.outputs.status == 'pending'
shell: bash
run: |
upstream_hash=$(git rev-parse upstream/${{ matrix.branch }})
upstream_short=$(git rev-parse --short upstream/${{ matrix.branch }})
upstream_log=$(git log HEAD..upstream/${{ matrix.branch }} --oneline | head -20 || true)
if git merge --no-edit upstream/${{ matrix.branch }}; then
echo "status=merged" >> "$GITHUB_OUTPUT"
echo "upstream_hash=${upstream_hash}" >> "$GITHUB_OUTPUT"
echo "upstream_short=${upstream_short}" >> "$GITHUB_OUTPUT"
{
echo "upstream_log<<EOF"
echo "$upstream_log"
echo "EOF"
} >> "$GITHUB_OUTPUT"
else
conflicted=$(git diff --name-only --diff-filter=U | paste -sd ',' - || echo "")
git merge --abort
echo "status=conflict" >> "$GITHUB_OUTPUT"
echo "upstream_hash=${upstream_hash}" >> "$GITHUB_OUTPUT"
echo "upstream_short=${upstream_short}" >> "$GITHUB_OUTPUT"
echo "conflicted_files=${conflicted}" >> "$GITHUB_OUTPUT"
{
echo "upstream_log<<EOF"
echo "$upstream_log"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi
# GITHUB_TOKEN pushes do not trigger the normal push workflows. Gate here.
- name: Setup validation tools
if: steps.merge.outputs.status == 'merged'
uses: ./.github/actions/setup-bun
- name: Validate merged types and unit tests
if: steps.merge.outputs.status == 'merged'
run: |
bun turbo typecheck --concurrency=2
bun --cwd packages/app run typecheck:e2e
GITHUB_ACTIONS=false bun turbo test --concurrency=2
bun --cwd packages/client run check:generated
bun --cwd packages/opencode run test:httpapi
- name: Install browser test dependencies
if: steps.merge.outputs.status == 'merged'
working-directory: packages/app
run: bunx playwright install --with-deps chromium firefox
- name: Validate merged browser behavior
if: steps.merge.outputs.status == 'merged'
working-directory: packages/app
env:
CI: true
run: bun run test:e2e:local
- name: Push merged changes
if: steps.merge.outputs.status == 'merged'
shell: bash
run: git push origin ${{ matrix.branch }}
- name: Report conflict to job summary
if: steps.merge.outputs.status == 'conflict'
shell: bash
env:
TARGET_BRANCH: ${{ matrix.branch }}
UPSTREAM_HASH: ${{ steps.merge.outputs.upstream_hash }}
UPSTREAM_SHORT: ${{ steps.merge.outputs.upstream_short }}
CONFLICTED_FILES: ${{ steps.merge.outputs.conflicted_files }}
UPSTREAM_LOG: ${{ steps.merge.outputs.upstream_log }}
run: |
conflicted_files_nl="${CONFLICTED_FILES//,/$'\n'}"
cat >> "$GITHUB_STEP_SUMMARY" << SUMMARY_EOF
## Upstream sync conflict on ${TARGET_BRANCH} - manual merge required
**Date:** $(date -u +"%Y-%m-%d %H:%M UTC")
**Branch:** \`${TARGET_BRANCH}\`
**Upstream commit:** \`${UPSTREAM_SHORT}\` (${UPSTREAM_HASH})
### Conflicting files
\`\`\`
${conflicted_files_nl}
\`\`\`
### Incoming upstream commits
\`\`\`
${UPSTREAM_LOG}
\`\`\`
### Resolve locally
\`\`\`bash
git fetch upstream ${TARGET_BRANCH}
git checkout ${TARGET_BRANCH}
git merge upstream/${TARGET_BRANCH}
# fix conflicts, then:
git add .
git commit
git push origin ${TARGET_BRANCH}
\`\`\`
SUMMARY_EOF
exit 1