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@v6 - 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<> "$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"