|
| 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." |
0 commit comments