forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (79 loc) · 3.11 KB
/
Copy pathsync-upstream.yml
File metadata and controls
92 lines (79 loc) · 3.11 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
name: Sync Upstream Changes
on:
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
force:
description: 'Retry merge using the upstream-preferred conflict strategy'
required: false
type: boolean
default: false
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
UPSTREAM_REPO: ${{ vars.OPENCODE_UPSTREAM_REPO }}
UPSTREAM_BRANCH: ${{ vars.OPENCODE_UPSTREAM_BRANCH }}
TARGET_BRANCH: ${{ vars.OPENCODE_TARGET_BRANCH }}
steps:
- name: Checkout fork
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- uses: ./.github/actions/setup-bun
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Install dependencies
run: |
bun install --frozen-lockfile
- name: Merge upstream into sync branch
id: sync
run: |
sync_branch="sync/upstream-${{ github.run_id }}-${{ github.run_attempt }}"
args=(--print-branch --sync-branch "$sync_branch")
if [ "${{ github.event.inputs.force || 'false' }}" = "true" ]; then
args+=(--force)
fi
./scripts/sync-upstream.sh "${args[@]}" | tee /tmp/sync-branch.txt
echo "branch=$(tail -n 1 /tmp/sync-branch.txt)" >> "$GITHUB_OUTPUT"
- name: Check for new commits
id: changes
run: |
target_branch="${TARGET_BRANCH:-dev}"
git fetch origin "$target_branch"
if [ "$(git rev-parse HEAD)" = "$(git rev-parse "origin/$target_branch")" ]; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Run validation
if: steps.changes.outputs.has_changes == 'true'
run: bun typecheck
- name: Push sync branch
if: steps.changes.outputs.has_changes == 'true'
run: git push origin "${{ steps.sync.outputs.branch }}"
- name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true'
run: |
target_branch="${TARGET_BRANCH:-dev}"
upstream_repo="${UPSTREAM_REPO:-anomalyco/opencode}"
upstream_branch="${UPSTREAM_BRANCH:-dev}"
gh pr create \
--title "chore: sync ${upstream_repo}@${upstream_branch} into ${target_branch}" \
--body "Automated sync from \`${upstream_repo}@${upstream_branch}\` into \`${target_branch}\`.
- Source SHA: \`$(git rev-parse --short "upstream/${upstream_branch}")\`
- Target SHA before merge: \`$(git rev-parse --short "origin/${target_branch}")\`
- Sync branch: \`${{ steps.sync.outputs.branch }}\`
This PR was created by \`.github/workflows/sync-upstream.yml\`." \
--base "$target_branch" \
--head "${{ steps.sync.outputs.branch }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}