forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (94 loc) · 3.85 KB
/
Copy pathsync-upstream.yml
File metadata and controls
103 lines (94 loc) · 3.85 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
name: Sync Upstream
# Two-branch fork model:
# dev — clean mirror of upstream/dev (fast-forward only, never holds fork commits)
# fork/local — our thin customization layer, rebased on top of dev
#
# This workflow fast-forwards dev to the latest upstream, then rebases
# fork/local on top. If the rebase hits conflicts, it stops and opens an issue
# so a human can resolve them locally — it never force-resolves silently.
on:
schedule:
- cron: "0 10 * * 1"
workflow_dispatch:
inputs:
upstream_branch:
description: "Upstream branch to mirror into dev"
required: true
default: dev
type: choice
options:
- dev
- main
- master
permissions:
contents: write
issues: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
submodules: false
# Use GITHUB_TOKEN (not SUBMODULE_PAT) so origin retains push access to opencode.
# SUBMODULE_PAT is injected separately via URL rewrite below for pvrdrxtd only.
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure git + upstream remote
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Route pvrdrxtd submodule clones through SUBMODULE_PAT without replacing the
# main origin credential (which must stay as GITHUB_TOKEN for push access).
if [ -n "${{ secrets.SUBMODULE_PAT }}" ]; then
git config --global url."https://${{ secrets.SUBMODULE_PAT }}@github.com/rustybret/pvrdrxtd".insteadOf \
"https://github.com/rustybret/pvrdrxtd"
fi
git submodule update --init --recursive 2>&1 || true
git remote add upstream https://github.com/anomalyco/opencode.git
git fetch upstream
git fetch origin
echo "UPSTREAM_BRANCH=${{ inputs.upstream_branch || 'dev' }}" >> $GITHUB_ENV
- name: Fast-forward dev to upstream (clean mirror)
run: |
BRANCH="${{ env.UPSTREAM_BRANCH }}"
echo "Mirroring upstream/${BRANCH} into dev (fast-forward only)..."
git checkout -B dev "upstream/${BRANCH}"
git push origin dev --force-with-lease
echo "dev now mirrors upstream/${BRANCH}."
- name: Rebase fork/local onto updated dev
id: rebase
run: |
git checkout -B fork/local origin/fork/local
echo "Rebasing fork/local onto dev..."
if git rebase dev 2>&1; then
echo "result=clean" >> $GITHUB_OUTPUT
else
git rebase --abort || true
echo "result=conflict" >> $GITHUB_OUTPUT
fi
- name: Push rebased fork/local
if: steps.rebase.outputs.result == 'clean'
run: |
git submodule update --init --recursive 2>&1 || true
git push origin fork/local --force-with-lease
echo "fork/local rebased onto latest upstream and pushed."
- name: Open issue on rebase conflict
if: steps.rebase.outputs.result == 'conflict'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
printf '%s\n' \
'The sync fast-forwarded dev to upstream but rebasing fork/local hit conflicts.' \
'' \
'Resolve locally:' \
' git fetch origin' \
' git checkout fork/local' \
' git rebase origin/dev' \
' # fix conflicts, then:' \
' git push origin fork/local --force-with-lease' \
> /tmp/issue-body.txt
gh issue create \
--repo "${{ github.repository }}" \
--title "Upstream sync: fork/local rebase needs manual resolution" \
--body-file /tmp/issue-body.txt