From aad712e408c608912ad411f377c3314fa40c9b37 Mon Sep 17 00:00:00 2001 From: Marc Littlemore Date: Mon, 7 Jul 2025 09:26:33 +0100 Subject: [PATCH] chore: Add GitHub workflow to sync public API docs (no-changelog) (#15985) --- .github/workflows/sync-public-api-docs.yml | 97 ++++++++++++++++++++++ packages/cli/package.json | 3 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/sync-public-api-docs.yml diff --git a/.github/workflows/sync-public-api-docs.yml b/.github/workflows/sync-public-api-docs.yml new file mode 100644 index 0000000000..07c3ea660e --- /dev/null +++ b/.github/workflows/sync-public-api-docs.yml @@ -0,0 +1,97 @@ +name: Sync Public API Schema to Docs Repo + +on: + # Triggers for the master branch if relevant Public API files have changed + push: + branches: + - master + paths: + # Trigger if: + # - any of the public API files change + - 'packages/cli/src/public-api/*.{css,yaml,yml}' + # - the build script or dependencies change + - 'packages/cli/package.json' + # - any main dependencies change + - 'pnpm-lock.yaml' + + # Allow manual trigger + workflow_dispatch: + +jobs: + sync-public-api: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout Main n8n Repository + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Setup Environment and Build Project + uses: ./.github/actions/setup-and-build + + - name: Build Public API Schema + run: pnpm run build:data + + - name: Verify OpenAPI schema exists + id: verify_file + run: | + if [[ -f "packages/cli/dist/public-api/v1/openapi.yml" ]]; then + echo "OpenAPI file found: packages/cli/dist/public-api/v1/openapi.yml" + echo "file_exists=true" >> $GITHUB_OUTPUT + else + echo "ERROR: OpenAPI file not found at packages/cli/dist/public-api/v1/openapi.yml after build." + echo "file_exists=false" >> $GITHUB_OUTPUT + fi + + - name: Generate GitHub App Token + if: steps.verify_file.outputs.file_exists == 'true' + id: generate_token + uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 + with: + app-id: ${{ secrets.N8N_ASSISTANT_APP_ID }} + private-key: ${{ secrets.N8N_ASSISTANT_PRIVATE_KEY }} + + - name: Checkout Docs Repository + if: steps.verify_file.outputs.file_exists == 'true' + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + repository: n8n-io/n8n-docs + token: ${{ steps.generate_token.outputs.token }} + path: public-docs + + - name: Copy OpenAPI file to Docs Repo + if: steps.verify_file.outputs.file_exists == 'true' + run: | + # Destination path within the 'public-docs' checkout directory + DOCS_TARGET_PATH="public-docs/docs/api/v1/openapi.yml" + + echo "Copying 'packages/cli/dist/public-api/v1/openapi.yml' to '${DOCS_TARGET_PATH}'" + cp packages/cli/dist/public-api/v1/openapi.yml "${DOCS_TARGET_PATH}" + + - name: Create PR in Docs Repo + if: steps.verify_file.outputs.file_exists == 'true' + + # Pin v7.0.8 + uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e + with: + token: ${{ steps.generate_token.outputs.token }} + + path: public-docs + commit-message: 'feat(public-api): Update Public API schema' + committer: GitHub + author: ${{ github.actor }} <${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com> + signoff: false + + # Create a unique branch and delete after we're done + branch: 'chore/openapi-sync-${{ github.run_id }}-${{ github.run_attempt }}' + delete-branch: true + + title: 'chore: Update Public API schema' + body: | + Automated update of the Public API OpenAPI YAML schema. + + This PR was generated by a GitHub Action in the [${{ github.repository }} repository](https://github.com/${{ github.repository }}). + Source commit: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) + + Please review the changes and merge if appropriate. diff --git a/packages/cli/package.json b/packages/cli/package.json index abd4ef01bf..b42f4dd9d1 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -7,7 +7,8 @@ "scripts": { "clean": "rimraf dist .turbo", "typecheck": "tsc --noEmit", - "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && node scripts/build.mjs", + "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && pnpm run build:data", + "build:data": "node scripts/build.mjs", "buildAndDev": "pnpm run build && pnpm run dev", "dev": "concurrently -k -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold\" \"npm run watch\" \"nodemon\"", "dev:worker": "concurrently -k -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold\" \"npm run watch\" \"nodemon worker\"",