From ae4ce5423cc00cc7872918b6abd883d202985271 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Thu, 26 Mar 2026 15:27:46 +0100 Subject: [PATCH 1/2] feat: add cross-repo cloud preview dispatch on PRs Triggers ephemeral CF Worker preview deploys in the cloud repo when PRs are opened/updated. Cleans up (deletes D1, KV, worker) on PR close. Each PR gets its own isolated D1 database with fresh migrations. Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/cloud-preview.yml | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/cloud-preview.yml diff --git a/.github/workflows/cloud-preview.yml b/.github/workflows/cloud-preview.yml new file mode 100644 index 00000000..86c06383 --- /dev/null +++ b/.github/workflows/cloud-preview.yml @@ -0,0 +1,53 @@ +name: Cloud Preview + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + +jobs: + dispatch-deploy: + name: Trigger Cloud Preview + if: github.event.action != 'closed' + runs-on: ubuntu-latest + steps: + - name: Dispatch preview deploy + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.CLOUD_DISPATCH_TOKEN }} + script: | + await github.rest.actions.createWorkflowDispatch({ + owner: 'AgentWorkforce', + repo: 'cloud', + workflow_id: 'preview-relayfile.yml', + ref: 'main', + inputs: { + pr_number: String(context.payload.pull_request.number), + head_sha: context.payload.pull_request.head.sha, + sdk_ref: context.payload.pull_request.head.ref, + source_repo: context.payload.repository.full_name, + action: 'deploy', + }, + }); + + dispatch-cleanup: + name: Cleanup Cloud Preview + if: github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - name: Dispatch preview cleanup + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.CLOUD_DISPATCH_TOKEN }} + script: | + await github.rest.actions.createWorkflowDispatch({ + owner: 'AgentWorkforce', + repo: 'cloud', + workflow_id: 'preview-relayfile.yml', + ref: 'main', + inputs: { + pr_number: String(context.payload.pull_request.number), + head_sha: context.payload.pull_request.head.sha, + source_repo: context.payload.repository.full_name, + action: 'cleanup', + }, + }); From 05fc0eb6e5ae39ab2855a5f24f0b5b5d9bc9d6d6 Mon Sep 17 00:00:00 2001 From: Khaliq Date: Thu, 26 Mar 2026 15:41:44 +0100 Subject: [PATCH 2/2] fix: use GitHub App token instead of static PAT for cross-repo dispatch Co-Authored-By: Claude Opus 4.6 (1M context) --- .github/workflows/cloud-preview.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cloud-preview.yml b/.github/workflows/cloud-preview.yml index 86c06383..5b43c26b 100644 --- a/.github/workflows/cloud-preview.yml +++ b/.github/workflows/cloud-preview.yml @@ -10,10 +10,17 @@ jobs: if: github.event.action != 'closed' runs-on: ubuntu-latest steps: + - name: Generate GitHub App Token + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.GH_APP_PUSHER_ID }} + private_key: ${{ secrets.GH_APP_PUSHER_PRIVATE_KEY }} + - name: Dispatch preview deploy uses: actions/github-script@v7 with: - github-token: ${{ secrets.CLOUD_DISPATCH_TOKEN }} + github-token: ${{ steps.generate_token.outputs.token }} script: | await github.rest.actions.createWorkflowDispatch({ owner: 'AgentWorkforce', @@ -34,10 +41,17 @@ jobs: if: github.event.action == 'closed' runs-on: ubuntu-latest steps: + - name: Generate GitHub App Token + id: generate_token + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.GH_APP_PUSHER_ID }} + private_key: ${{ secrets.GH_APP_PUSHER_PRIVATE_KEY }} + - name: Dispatch preview cleanup uses: actions/github-script@v7 with: - github-token: ${{ secrets.CLOUD_DISPATCH_TOKEN }} + github-token: ${{ steps.generate_token.outputs.token }} script: | await github.rest.actions.createWorkflowDispatch({ owner: 'AgentWorkforce',