-
Notifications
You must be signed in to change notification settings - Fork 3
178 lines (150 loc) · 6.51 KB
/
weekly-upstream-sync.yml
File metadata and controls
178 lines (150 loc) · 6.51 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: "Weekly Upstream Sync"
on:
schedule:
# Every Monday at 10:00 UTC (5:00 AM EST / 6:00 AM EDT)
- cron: '0 10 * * 1'
workflow_dispatch:
permissions:
contents: write
issues: write
pull-requests: write
env:
# Used for `gh` CLI operations to create/close/comment issues. Must be a PAT with repo permissions because the default
GH_AW_AGENT_TOKEN: ${{ secrets.GH_AW_AGENT_TOKEN }}
GH_TOKEN: ${{ secrets.GH_AW_AGENT_TOKEN }}
jobs:
check-and-sync:
name: "Check upstream & trigger Copilot merge"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Check for upstream changes
id: check
run: |
LAST_MERGE=$(cat .lastmerge)
echo "Last merged commit: $LAST_MERGE"
git clone --quiet https://github.com/github/copilot-sdk.git /tmp/upstream
cd /tmp/upstream
UPSTREAM_HEAD=$(git rev-parse HEAD)
echo "Upstream HEAD: $UPSTREAM_HEAD"
echo "last_merge=$LAST_MERGE" >> "$GITHUB_OUTPUT"
if [ "$LAST_MERGE" = "$UPSTREAM_HEAD" ]; then
echo "No new upstream changes since last merge."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
COMMIT_COUNT=$(git rev-list --count "$LAST_MERGE".."$UPSTREAM_HEAD")
echo "Found $COMMIT_COUNT new upstream commits."
echo "has_changes=true" >> "$GITHUB_OUTPUT"
echo "commit_count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT"
echo "upstream_head=$UPSTREAM_HEAD" >> "$GITHUB_OUTPUT"
# Generate a short summary of changes
SUMMARY=$(git log --oneline "$LAST_MERGE".."$UPSTREAM_HEAD" | head -20)
{
echo "summary<<EOF"
echo "$SUMMARY"
echo "EOF"
} >> "$GITHUB_OUTPUT"
fi
- name: Close previous upstream-sync issues
if: steps.check.outputs.has_changes == 'true'
run: |
# Find all open issues with the upstream-sync label
OPEN_ISSUES=$(gh issue list \
--repo "${{ github.repository }}" \
--label "upstream-sync" \
--state open \
--json number \
--jq '.[].number')
for ISSUE_NUM in $OPEN_ISSUES; do
echo "Closing superseded issue #${ISSUE_NUM}"
gh issue comment "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--body "Superseded by a newer upstream sync issue. Closing this one."
gh issue close "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--reason "not planned"
done
- name: Close stale upstream-sync issues (no changes)
if: steps.check.outputs.has_changes == 'false'
run: |
OPEN_ISSUES=$(gh issue list \
--repo "${{ github.repository }}" \
--label "upstream-sync" \
--state open \
--json number \
--jq '.[].number')
for ISSUE_NUM in $OPEN_ISSUES; do
echo "Closing stale issue #${ISSUE_NUM} — upstream is up to date"
gh issue comment "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--body "No new upstream changes detected. The Java SDK is up to date. Closing."
gh issue close "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--reason "completed"
done
- name: Create issue and assign to Copilot
id: create-issue
if: steps.check.outputs.has_changes == 'true'
run: |
COMMIT_COUNT="${{ steps.check.outputs.commit_count }}"
LAST_MERGE="${{ steps.check.outputs.last_merge }}"
UPSTREAM_HEAD="${{ steps.check.outputs.upstream_head }}"
SUMMARY="${{ steps.check.outputs.summary }}"
DATE=$(date -u +"%Y-%m-%d")
REPO="${{ github.repository }}"
BODY="## Automated Upstream Sync
There are **${COMMIT_COUNT}** new commits in the [official Copilot SDK](https://github.com/github/copilot-sdk) since the last merge.
- **Last merged commit:** [\`${LAST_MERGE}\`](https://github.com/github/copilot-sdk/commit/${LAST_MERGE})
- **Upstream HEAD:** [\`${UPSTREAM_HEAD}\`](https://github.com/github/copilot-sdk/commit/${UPSTREAM_HEAD})
### Recent upstream commits
\`\`\`
${SUMMARY}
\`\`\`
### Instructions
Follow the [agentic-merge-upstream](.github/prompts/agentic-merge-upstream.prompt.md) prompt to port these changes to the Java SDK."
# Create the issue and assign to Copilot coding agent
ISSUE_URL=$(gh issue create \
--repo "$REPO" \
--title "Upstream sync: ${COMMIT_COUNT} new commits (${DATE})" \
--body "$BODY" \
--label "upstream-sync" \
--assignee "copilot-swe-agent")
echo "issue_url=$ISSUE_URL" >> "$GITHUB_OUTPUT"
echo "✅ Issue created and assigned to Copilot coding agent: $ISSUE_URL"
- name: Summary
if: always()
run: |
HAS_CHANGES="${{ steps.check.outputs.has_changes }}"
COMMIT_COUNT="${{ steps.check.outputs.commit_count }}"
LAST_MERGE="${{ steps.check.outputs.last_merge }}"
UPSTREAM_HEAD="${{ steps.check.outputs.upstream_head }}"
ISSUE_URL="${{ steps.create-issue.outputs.issue_url }}"
{
echo "## Weekly Upstream Sync"
echo ""
if [ "$HAS_CHANGES" = "true" ]; then
echo "### ✅ New upstream changes detected"
echo ""
echo "| | |"
echo "|---|---|"
echo "| **New commits** | ${COMMIT_COUNT} |"
echo "| **Last merged** | \`${LAST_MERGE:0:12}\` |"
echo "| **Upstream HEAD** | \`${UPSTREAM_HEAD:0:12}\` |"
echo ""
echo "An issue has been created and assigned to the Copilot coding agent: "
echo " -> ${ISSUE_URL}"
echo ""
echo "### Recent upstream commits"
echo ""
echo '```'
echo "${{ steps.check.outputs.summary }}"
echo '```'
else
echo "### ⏭️ No changes"
echo ""
echo "The Java SDK is already up to date with the upstream Copilot SDK."
echo ""
echo "**Last merged commit:** \`${LAST_MERGE:0:12}\`"
fi
} >> "$GITHUB_STEP_SUMMARY"