|
| 1 | +# Sync Python port with upstream Vercel `packages/detect-agent` when it changes. |
| 2 | +# |
| 3 | +# Setup: |
| 4 | +# - Repository secret: CURSOR_API_KEY (https://github.com/marketplace/actions/cursor-action) |
| 5 | +# - Uses actions/cache to remember the last synced upstream commit for that path. |
| 6 | +# - First successful run bootstraps cache only (no agent); the next drift triggers the agent. |
| 7 | +# |
| 8 | +# Manual run: Actions -> "Sync Vercel detect-agent upstream" -> Run workflow |
| 9 | + |
| 10 | +name: Sync Vercel detect-agent upstream |
| 11 | + |
| 12 | +on: |
| 13 | + schedule: |
| 14 | + # Daily 14:05 UTC — adjust as you like |
| 15 | + - cron: "5 14 * * *" |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: sync-vercel-detect-agent-upstream |
| 20 | + cancel-in-progress: false |
| 21 | + |
| 22 | +jobs: |
| 23 | + sync: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + permissions: |
| 26 | + contents: write |
| 27 | + pull-requests: write |
| 28 | + env: |
| 29 | + GH_TOKEN: ${{ github.token }} |
| 30 | + GITHUB_TOKEN: ${{ github.token }} |
| 31 | + UPSTREAM_STATE_DIR: ${{ runner.temp }}/upstream-sync-state |
| 32 | + UPSTREAM_VERCEL_MIRROR: ${{ runner.temp }}/vercel.git |
| 33 | + UPSTREAM_DIFF_FILE: ${{ runner.temp }}/vercel-detect-agent.diff |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - uses: actions/cache@v4 |
| 40 | + id: vercel_mirror_cache |
| 41 | + with: |
| 42 | + path: ${{ runner.temp }}/vercel.git |
| 43 | + key: vercel-github-bare-mirror-v1-${{ runner.os }} |
| 44 | + |
| 45 | + - uses: actions/cache@v4 |
| 46 | + id: upstream_state_cache |
| 47 | + with: |
| 48 | + path: ${{ runner.temp }}/upstream-sync-state |
| 49 | + key: vercel-detect-agent-upstream-state-v1-${{ runner.os }} |
| 50 | + |
| 51 | + - name: Compute upstream drift |
| 52 | + id: drift |
| 53 | + shell: bash |
| 54 | + run: ./scripts/vercel_upstream_drift.sh |
| 55 | + |
| 56 | + - name: Configure git for pushes |
| 57 | + if: steps.drift.outputs.should_sync == 'true' |
| 58 | + run: | |
| 59 | + set -euo pipefail |
| 60 | + git config user.name "github-actions[bot]" |
| 61 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 62 | + git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" |
| 63 | +
|
| 64 | + - uses: astral-sh/setup-uv@v5 |
| 65 | + if: steps.drift.outputs.should_sync == 'true' |
| 66 | + with: |
| 67 | + enable-cache: true |
| 68 | + python-version: "3.9" |
| 69 | + |
| 70 | + - name: Install Python deps (uv) |
| 71 | + if: steps.drift.outputs.should_sync == 'true' |
| 72 | + run: uv sync --extra dev |
| 73 | + |
| 74 | + - name: Run Cursor agent (port + push + PR) |
| 75 | + id: cursor |
| 76 | + if: steps.drift.outputs.should_sync == 'true' |
| 77 | + uses: PunGrumpy/cursor-action@v1.0.0 |
| 78 | + with: |
| 79 | + api-key: ${{ secrets.CURSOR_API_KEY }} |
| 80 | + model: composer-2 |
| 81 | + working-directory: . |
| 82 | + permissions: read-write |
| 83 | + timeout: "3600" |
| 84 | + prompt: | |
| 85 | + You are syncing this repository's Python port of Vercel's `packages/detect-agent` with upstream changes. |
| 86 | +
|
| 87 | + Upstream facts: |
| 88 | + - merge_base: ${{ steps.drift.outputs.merge_base }} |
| 89 | + - last_recorded_upstream_tip: ${{ steps.drift.outputs.last_recorded }} |
| 90 | + - new_upstream_tip: ${{ steps.drift.outputs.new_sha }} |
| 91 | + - compare URL: ${{ steps.drift.outputs.compare_url }} |
| 92 | +
|
| 93 | + Read the unified diff from this absolute path. Do not `git add` or commit that path; it is CI scratch only: |
| 94 | + ${{ steps.drift.outputs.diff_path }} |
| 95 | +
|
| 96 | + Your job, in order: |
| 97 | + 1. `git fetch origin && git checkout main && git pull --ff-only origin main` |
| 98 | + 2. Create branch `sync/vercel-detect-agent-${{ steps.drift.outputs.branch_slug }}` (delete/recreate the local branch if it already exists). |
| 99 | + 3. Port upstream logic into `detect_agent/__init__.py` and `tests/` as needed. Mirror detection order and semantics from the TypeScript sources; keep typing style consistent with the existing Python file. |
| 100 | + 4. Update `README.md` / `CHANGELOG.md` here if upstream docs/changelog warrant it. |
| 101 | + 5. Run: `uv sync --extra dev && uv run pytest && uv run ruff check . && uv run ruff format --check .` |
| 102 | + 6. Commit with message like: `sync: port vercel detect-agent ${{ steps.drift.outputs.merge_base }}..${{ steps.drift.outputs.new_sha }}` (shorten SHAs in the subject if you prefer). |
| 103 | + 7. `git push -u origin HEAD` |
| 104 | + 8. Open a PR with `gh pr create` (title/body should link ${{ steps.drift.outputs.compare_url }} and mention https://github.com/vercel/vercel/tree/main/packages/detect-agent ). `GITHUB_TOKEN` is already available to `gh` in this environment. |
| 105 | +
|
| 106 | + If the diff file is empty but the SHAs differ, use the compare URL and current upstream `main` tree for that package to align the port. |
| 107 | +
|
| 108 | + - name: Record synced upstream SHA |
| 109 | + if: success() && steps.drift.outputs.should_sync == 'true' |
| 110 | + shell: bash |
| 111 | + env: |
| 112 | + NEW_SHA: ${{ steps.drift.outputs.new_sha }} |
| 113 | + run: | |
| 114 | + set -euo pipefail |
| 115 | + mkdir -p "${UPSTREAM_STATE_DIR}" |
| 116 | + printf '%s\n' "${NEW_SHA}" >"${UPSTREAM_STATE_DIR}/last_packages_detect_agent_commit.txt" |
| 117 | +
|
| 118 | + - name: Job summary |
| 119 | + if: always() |
| 120 | + shell: bash |
| 121 | + run: | |
| 122 | + set -euo pipefail |
| 123 | + { |
| 124 | + echo "## Upstream sync" |
| 125 | + echo "- should_sync: ${{ steps.drift.outputs.should_sync }}" |
| 126 | + echo "- new_sha: ${{ steps.drift.outputs.new_sha }}" |
| 127 | + echo "- compare: ${{ steps.drift.outputs.compare_url }}" |
| 128 | + } >>"${GITHUB_STEP_SUMMARY}" |
| 129 | + if [[ "${{ steps.drift.outputs.should_sync }}" == "true" ]]; then |
| 130 | + echo "- cursor exit: ${{ steps.cursor.outputs.exit-code }}" >>"${GITHUB_STEP_SUMMARY}" |
| 131 | + fi |
0 commit comments