Skip to content

Commit 95eaa29

Browse files
committed
Add weekly upstream sync workflow and update README with automation details
1 parent 4518f43 commit 95eaa29

3 files changed

Lines changed: 157 additions & 0 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ on:
1616
- '.github/dependabot.yml'
1717
- '.github/release.yml'
1818
- '.github/workflows/publish-maven.yml'
19+
- '.github/workflows/weekly-upstream-sync.yml'
1920
pull_request:
2021
paths-ignore:
2122
- 'README.md'
@@ -27,6 +28,7 @@ on:
2728
- '.github/dependabot.yml'
2829
- '.github/release.yml'
2930
- '.github/workflows/publish-maven.yml'
31+
- '.github/workflows/weekly-upstream-sync.yml'
3032
workflow_dispatch:
3133
merge_group:
3234

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: "Weekly Upstream Sync"
2+
3+
on:
4+
schedule:
5+
# Every Monday at 10:00 UTC (5:00 AM EST / 6:00 AM EDT)
6+
- cron: '0 10 * * 1'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
issues: write
12+
pull-requests: write
13+
14+
jobs:
15+
16+
check-and-sync:
17+
name: "Check upstream & trigger Copilot merge"
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v6
23+
24+
- name: Check for upstream changes
25+
id: check
26+
run: |
27+
LAST_MERGE=$(cat .lastmerge)
28+
echo "Last merged commit: $LAST_MERGE"
29+
30+
git clone --quiet https://github.com/github/copilot-sdk.git /tmp/upstream
31+
cd /tmp/upstream
32+
33+
UPSTREAM_HEAD=$(git rev-parse HEAD)
34+
echo "Upstream HEAD: $UPSTREAM_HEAD"
35+
36+
if [ "$LAST_MERGE" = "$UPSTREAM_HEAD" ]; then
37+
echo "No new upstream changes since last merge."
38+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
39+
else
40+
COMMIT_COUNT=$(git rev-list --count "$LAST_MERGE".."$UPSTREAM_HEAD")
41+
echo "Found $COMMIT_COUNT new upstream commits."
42+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
43+
echo "commit_count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT"
44+
echo "upstream_head=$UPSTREAM_HEAD" >> "$GITHUB_OUTPUT"
45+
echo "last_merge=$LAST_MERGE" >> "$GITHUB_OUTPUT"
46+
47+
# Generate a short summary of changes
48+
SUMMARY=$(git log --oneline "$LAST_MERGE".."$UPSTREAM_HEAD" | head -20)
49+
{
50+
echo "summary<<EOF"
51+
echo "$SUMMARY"
52+
echo "EOF"
53+
} >> "$GITHUB_OUTPUT"
54+
fi
55+
56+
- name: Close previous upstream-sync issues
57+
if: steps.check.outputs.has_changes == 'true'
58+
env:
59+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
run: |
61+
# Find all open issues with the upstream-sync label
62+
OPEN_ISSUES=$(gh issue list \
63+
--repo "${{ github.repository }}" \
64+
--label "upstream-sync" \
65+
--state open \
66+
--json number \
67+
--jq '.[].number')
68+
69+
for ISSUE_NUM in $OPEN_ISSUES; do
70+
echo "Closing superseded issue #${ISSUE_NUM}"
71+
gh issue comment "$ISSUE_NUM" \
72+
--repo "${{ github.repository }}" \
73+
--body "Superseded by a newer upstream sync issue. Closing this one."
74+
gh issue close "$ISSUE_NUM" \
75+
--repo "${{ github.repository }}" \
76+
--reason "not planned"
77+
done
78+
79+
- name: Create issue and assign to Copilot
80+
if: steps.check.outputs.has_changes == 'true'
81+
env:
82+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
run: |
84+
COMMIT_COUNT="${{ steps.check.outputs.commit_count }}"
85+
LAST_MERGE="${{ steps.check.outputs.last_merge }}"
86+
UPSTREAM_HEAD="${{ steps.check.outputs.upstream_head }}"
87+
SUMMARY="${{ steps.check.outputs.summary }}"
88+
DATE=$(date -u +"%Y-%m-%d")
89+
90+
BODY=$(cat <<'ISSUE_BODY'
91+
## Automated Upstream Sync
92+
93+
There are **COMMIT_COUNT_PLACEHOLDER** new commits in the [official Copilot SDK](https://github.com/github/copilot-sdk) since the last merge.
94+
95+
- **Last merged commit:** [`LAST_MERGE_PLACEHOLDER`](https://github.com/github/copilot-sdk/commit/LAST_MERGE_PLACEHOLDER)
96+
- **Upstream HEAD:** [`UPSTREAM_HEAD_PLACEHOLDER`](https://github.com/github/copilot-sdk/commit/UPSTREAM_HEAD_PLACEHOLDER)
97+
98+
### Recent upstream commits
99+
100+
```
101+
SUMMARY_PLACEHOLDER
102+
```
103+
104+
### Instructions
105+
106+
Follow the [agentic-merge-upstream](.github/prompts/agentic-merge-upstream.prompt.md) prompt to port these changes to the Java SDK.
107+
108+
**Key steps:**
109+
1. Run `.github/scripts/merge-upstream-start.sh` to initialize
110+
2. Run `.github/scripts/merge-upstream-diff.sh --full` to analyze changes
111+
3. Port relevant changes from the .NET SDK to Java, following existing patterns
112+
4. Run `.github/scripts/format-and-test.sh` to validate
113+
5. Run `.github/scripts/merge-upstream-finish.sh` to finalize
114+
115+
Update documentation (README.md, CHANGELOG.md, src/site/markdown/) for any user-facing changes.
116+
ISSUE_BODY
117+
)
118+
119+
# Replace placeholders
120+
BODY="${BODY//COMMIT_COUNT_PLACEHOLDER/$COMMIT_COUNT}"
121+
BODY="${BODY//LAST_MERGE_PLACEHOLDER/$LAST_MERGE}"
122+
BODY="${BODY//UPSTREAM_HEAD_PLACEHOLDER/$UPSTREAM_HEAD}"
123+
BODY="${BODY//SUMMARY_PLACEHOLDER/$SUMMARY}"
124+
125+
# Create issue and assign to Copilot coding agent
126+
gh api \
127+
--method POST \
128+
-H "Accept: application/vnd.github+json" \
129+
-H "X-GitHub-Api-Version: 2022-11-28" \
130+
/repos/${{ github.repository }}/issues \
131+
--input - <<EOF
132+
{
133+
"title": "Upstream sync: ${COMMIT_COUNT} new commits (${DATE})",
134+
"body": $(echo "$BODY" | jq -Rs .),
135+
"labels": ["upstream-sync"],
136+
"assignees": ["copilot-swe-agent[bot]"],
137+
"agent_assignment": {
138+
"target_repo": "${{ github.repository }}",
139+
"base_branch": "main",
140+
"custom_instructions": "Follow the agentic-merge-upstream prompt at .github/prompts/agentic-merge-upstream.prompt.md to port upstream changes to the Java SDK. Use the utility scripts in .github/scripts/ for initialization, diffing, formatting, and testing. Commit changes incrementally. Update .lastmerge when done."
141+
}
142+
}
143+
EOF
144+
145+
echo "✅ Issue created and assigned to Copilot coding agent."

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ public class CopilotSDK {
104104

105105
Contributions are welcome! Please see the [Contributing Guide](CONTRIBUTING.md) for details.
106106

107+
### Agentic Upstream Merge and Sync
108+
109+
This SDK tracks the official [Copilot SDK](https://github.com/github/copilot-sdk) (.NET reference implementation) and ports changes to Java. The upstream merge process is automated with AI assistance:
110+
111+
**Weekly automated sync** — A [scheduled GitHub Actions workflow](.github/workflows/weekly-upstream-sync.yml) runs every Monday at 5 AM ET. It checks for new upstream commits since the last merge (tracked in [`.lastmerge`](.lastmerge)), and if changes are found, creates an issue labeled `upstream-sync` and assigns it to the GitHub Copilot coding agent. Any previously open `upstream-sync` issues are automatically closed.
112+
113+
**Reusable prompt** — The merge workflow is defined in [`agentic-merge-upstream.prompt.md`](.github/prompts/agentic-merge-upstream.prompt.md). It can be triggered manually from:
114+
- **VS Code Copilot Chat** — type `/agentic-merge-upstream`
115+
- **GitHub Copilot CLI** — use `copilot` CLI with the same skill reference
116+
107117
### Development Setup
108118

109119
```bash

0 commit comments

Comments
 (0)