From 95678d9e62e4a0713c9cadc71b1637ec3883d4fc Mon Sep 17 00:00:00 2001 From: amitbardos Date: Sun, 11 Oct 2026 15:41:45 +0300 Subject: [PATCH] ci(platform): sync asyncapi.json from production every week A weekly workflow (and workflow_dispatch) fetches https://app.base44.com/api/asyncapi.json, regenerates the event types, builds the docs and runs the Platform SDK tests, and opens or updates one rolling PR on bot/platform-asyncapi-sync only when asyncapi.json or the generated types changed. It closes that PR when main already matches production. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/sync-asyncapi.yml | 92 +++++++++++++++++++++ packages/platform/scripts/sync-asyncapi.mjs | 2 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/sync-asyncapi.yml diff --git a/.github/workflows/sync-asyncapi.yml b/.github/workflows/sync-asyncapi.yml new file mode 100644 index 00000000..83d57c4d --- /dev/null +++ b/.github/workflows/sync-asyncapi.yml @@ -0,0 +1,92 @@ +name: Sync Platform SDK AsyncAPI + +# Refreshes packages/platform/asyncapi.json from production and regenerates the event +# types from it. Changes go to one rolling PR; closing it without merging only skips +# that week, since the next run proposes the same changes again. + +on: + schedule: + - cron: "0 6 * * 1" # Mondays at 06:00 UTC + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +concurrency: + group: sync-asyncapi + cancel-in-progress: false + +env: + BRANCH: bot/platform-asyncapi-sync + ASYNCAPI_URL: https://app.base44.com/api/asyncapi.json + +jobs: + sync: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + ref: main + + - name: Wix gateway proxy (mandatory) + uses: ./.github/actions/wix-gateway-proxy + + - name: Use Node.js 20.x + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + with: + node-version: "20.x" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Sync asyncapi.json and regenerate the event types + run: | + npm run sync:asyncapi -w @base44/platform -- "$ASYNCAPI_URL" + npm run gen:events -w @base44/platform + + - name: Check for changes + id: changes + run: | + if git diff --quiet -- packages/platform/asyncapi.json packages/platform/src/modules/builder.events.generated.ts; then + echo "changed=false" >> "$GITHUB_OUTPUT" + echo "✅ asyncapi.json and the event types are up to date" + else + echo "changed=true" >> "$GITHUB_OUTPUT" + fi + + - name: Close a stale sync PR + if: steps.changes.outputs.changed == 'false' + env: + GH_TOKEN: ${{ github.token }} + run: | + pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number') + if [ -n "$pr" ]; then gh pr close "$pr" --delete-branch --comment "main already matches production."; fi + + - name: Build the docs and test the Platform SDK + if: steps.changes.outputs.changed == 'true' + run: | + npm run create-docs -w @base44/platform + npm test -w @base44/platform + + - name: Update the sync PR + if: steps.changes.outputs.changed == 'true' + env: + GH_TOKEN: ${{ github.token }} + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git checkout -B "$BRANCH" + git add packages/platform/asyncapi.json packages/platform/src/modules/builder.events.generated.ts + git commit -m "chore(platform): sync asyncapi.json and the event types from production" + # Rebuilt from main every run, so the branch never drifts or conflicts. + git push --force origin "$BRANCH" + + pr=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number') + body="Refreshes \`packages/platform/asyncapi.json\` from $ASYNCAPI_URL and regenerates \`builder.events.generated.ts\`. The docs build and the Platform SDK tests passed on this change. Updated automatically every week." + if [ -z "$pr" ]; then + gh pr create --head "$BRANCH" --base main --title "Sync Platform SDK events from production" --body "$body" + fi diff --git a/packages/platform/scripts/sync-asyncapi.mjs b/packages/platform/scripts/sync-asyncapi.mjs index 326010e7..8b750a31 100644 --- a/packages/platform/scripts/sync-asyncapi.mjs +++ b/packages/platform/scripts/sync-asyncapi.mjs @@ -2,7 +2,7 @@ // Replaces asyncapi.json with the document a backend serves, production by default. Production // publishes only beta and GA messages; for alpha ones point this at a dev backend, e.g. a local apper: // npm run sync:asyncapi -- http://localhost:8000/api/asyncapi.json -// or set ASYNCAPI_URL. Then run `npm run gen:events`. +// or set ASYNCAPI_URL. Then run `npm run gen:events`. The weekly sync-asyncapi workflow does both. import { writeFile } from "node:fs/promises"; const url = process.argv[2] ?? process.env.ASYNCAPI_URL ?? "https://app.base44.com/api/asyncapi.json";