|
| 1 | +name: Upstream Sync |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 06:00 UTC |
| 6 | + - cron: '0 6 * * *' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + check-upstream: |
| 11 | + name: Check for upstream changes |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: write # needed to update .last-sync-commit on main |
| 15 | + issues: write # needed to create the issue that triggers Copilot |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + ref: main |
| 22 | + |
| 23 | + - name: Get last synced commit |
| 24 | + id: last-sync |
| 25 | + run: echo "sha=$(cat .last-sync-commit | tr -d '[:space:]')" >> "$GITHUB_OUTPUT" |
| 26 | + |
| 27 | + - name: Get latest upstream commit |
| 28 | + id: upstream |
| 29 | + run: | |
| 30 | + # git ls-remote reads public repos without any auth or API calls |
| 31 | + LATEST=$(git ls-remote https://github.com/artem-ogre/CDT.git refs/heads/master | cut -f1) |
| 32 | + if [ -z "$LATEST" ]; then |
| 33 | + echo "::error::Could not resolve latest upstream commit SHA" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + echo "sha=$LATEST" >> "$GITHUB_OUTPUT" |
| 37 | + echo "Latest upstream commit: $LATEST" |
| 38 | +
|
| 39 | + - name: Create Copilot porting issue |
| 40 | + if: steps.last-sync.outputs.sha != steps.upstream.outputs.sha |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + run: | |
| 44 | + LAST="${{ steps.last-sync.outputs.sha }}" |
| 45 | + LATEST="${{ steps.upstream.outputs.sha }}" |
| 46 | + DATE=$(date -u +"%Y-%m-%d") |
| 47 | +
|
| 48 | + echo "Upstream has new commits since ${LAST:0:7} (latest: ${LATEST:0:7})" |
| 49 | +
|
| 50 | + # Shallow-clone the upstream history (metadata only) to build a commit list |
| 51 | + git clone --depth 50 --no-checkout https://github.com/artem-ogre/CDT.git /tmp/CDT-upstream |
| 52 | + COMMITS=$(git -C /tmp/CDT-upstream log \ |
| 53 | + --pretty=format:"- [%h](https://github.com/artem-ogre/CDT/commit/%H) %s" \ |
| 54 | + "${LAST}..${LATEST}" 2>/dev/null || echo "- (see compare link below)") |
| 55 | + [ -z "$COMMITS" ] && COMMITS="- (see compare link below)" |
| 56 | +
|
| 57 | + # Update .last-sync-commit on main so we don't re-open the issue next run |
| 58 | + git config user.name "github-actions[bot]" |
| 59 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 60 | + echo "$LATEST" > .last-sync-commit |
| 61 | + git add .last-sync-commit |
| 62 | + git commit -m "chore: advance upstream sync marker to ${LATEST:0:7}" |
| 63 | + git push origin main |
| 64 | +
|
| 65 | + # Ensure the auto-sync label exists |
| 66 | + gh label create "auto-sync" \ |
| 67 | + --description "Automatically generated upstream sync issue" \ |
| 68 | + --color "0075ca" 2>/dev/null || true |
| 69 | +
|
| 70 | + # Create an issue assigned to the Copilot coding agent. |
| 71 | + # Assigning to @Copilot triggers the coding agent to pick it up |
| 72 | + # and create a PR with the ported C# changes. |
| 73 | + ISSUE_BODY=$(cat <<'EOF' |
| 74 | + ## Upstream Sync Task |
| 75 | +
|
| 76 | + @Copilot please port the upstream changes listed below to C# and open a pull request. |
| 77 | +
|
| 78 | + New commits have been pushed to [artem-ogre/CDT](https://github.com/artem-ogre/CDT) since the last sync. |
| 79 | +
|
| 80 | + **Previous synced commit:** [`LAST_SHA`](https://github.com/artem-ogre/CDT/commit/LAST_FULL) |
| 81 | + **New upstream commit:** [`LATEST_SHA`](https://github.com/artem-ogre/CDT/commit/LATEST_FULL) |
| 82 | + **Full diff:** https://github.com/artem-ogre/CDT/compare/LAST_FULL...LATEST_FULL |
| 83 | +
|
| 84 | + ### Upstream commits to port |
| 85 | +
|
| 86 | + COMMIT_LIST |
| 87 | +
|
| 88 | + ### What to port |
| 89 | +
|
| 90 | + Please port all upstream C++ changes to C# and open a pull request. |
| 91 | +
|
| 92 | + Key files to check in the upstream diff: |
| 93 | + - `CDT/include/CDT.h` and `CDT/include/CDT.hpp` → port any algorithm changes to `src/CDT.Core/` |
| 94 | + - `CDT/include/Predicates.h` → port to `src/CDT.Core/Predicates.cs` |
| 95 | + - `CDT/include/KDTree.h` → port to `src/CDT.Core/KdTree.cs` |
| 96 | + - Any new types or utilities → port to `src/CDT.Core/Types.cs` or new files as appropriate |
| 97 | +
|
| 98 | + After porting: |
| 99 | + 1. Run `dotnet test` and ensure all tests pass |
| 100 | + 2. Update test inputs/expected outputs if needed |
| 101 | + EOF |
| 102 | + ) |
| 103 | + # Replace placeholders with actual values |
| 104 | + ISSUE_BODY="${ISSUE_BODY//LAST_SHA/${LAST:0:7}}" |
| 105 | + ISSUE_BODY="${ISSUE_BODY//LAST_FULL/${LAST}}" |
| 106 | + ISSUE_BODY="${ISSUE_BODY//LATEST_SHA/${LATEST:0:7}}" |
| 107 | + ISSUE_BODY="${ISSUE_BODY//LATEST_FULL/${LATEST}}" |
| 108 | + ISSUE_BODY="${ISSUE_BODY//COMMIT_LIST/$COMMITS}" |
| 109 | +
|
| 110 | + gh issue create \ |
| 111 | + --title "Port upstream CDT changes to C# (${LATEST:0:7}) — ${DATE}" \ |
| 112 | + --label "auto-sync" \ |
| 113 | + --assignee "Copilot" \ |
| 114 | + --body "$ISSUE_BODY" |
0 commit comments