Repository navigation
Chore/harshil/sessions agents #1714
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate SDK | |
| # Regenerates the OpenAPI document and the SDK, and commits both to the branch. | |
| # Fork PRs cannot receive that commit; main regenerates after merge. | |
| on: | |
| # Manual regen on main if the post-merge push job missed or failed. | |
| workflow_dispatch: | |
| push: | |
| branches: [main] | |
| # Only sources the document is built from; tests and metadata cannot change it. | |
| paths: | |
| - 'packages/trueforge/src/**' | |
| - 'packages/trueforge/scripts/**' | |
| - 'packages/trueforge-core/src/**' | |
| - '.github/fern/**' | |
| - '.github/workflows/generate-sdk.yaml' | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| paths: | |
| - 'packages/trueforge/src/**' | |
| - 'packages/trueforge/scripts/**' | |
| - 'packages/trueforge-core/src/**' | |
| - '.github/fern/**' | |
| - '.github/workflows/generate-sdk.yaml' | |
| concurrency: | |
| group: generate-sdk-${{ github.head_ref || github.ref_name }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| generate: | |
| name: Generate OpenAPI and TypeScript SDK | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| # A pull_request path filter matches the whole PR, not just the new commit, | |
| # so this job's own commits would otherwise retrigger it indefinitely. | |
| # github-actions[bot]: legacy GITHUB_TOKEN pushes (if any still land). | |
| # trueforge-dev-bot[bot]: App-token pushes from this workflow (slug of the Generate SDK App). | |
| if: > | |
| github.actor != 'github-actions[bot]' && | |
| github.actor != 'trueforge-dev-bot[bot]' | |
| steps: | |
| - name: Create GitHub App token | |
| id: app-token | |
| if: > | |
| github.event_name == 'push' || | |
| github.event_name == 'workflow_dispatch' || | |
| github.event.pull_request.head.repo.full_name == github.repository | |
| uses: actions/create-github-app-token@v3 | |
| with: | |
| client-id: ${{ secrets.TRUEFORGE_GENERATE_SDK_APP_ID }} | |
| private-key: ${{ secrets.TRUEFORGE_GENERATE_SDK_APP_PRIVATE_KEY }} | |
| # Writable checkout: App token minted only for same-repo / push / dispatch. | |
| - name: Check out branch | |
| if: steps.app-token.outcome == 'success' | |
| uses: actions/checkout@v7 | |
| with: | |
| repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} | |
| ref: ${{ github.head_ref || github.ref_name }} | |
| # Full history, so the gate below can diff against the base commit. | |
| fetch-depth: 0 | |
| token: ${{ steps.app-token.outputs.token || github.token }} | |
| # Forks skip the writable checkout above; without this the job has no code. | |
| # Use base-repo pull refs (head.sha) — cloning the fork with GITHUB_TOKEN 403s. | |
| - name: Check out pull request head | |
| if: github.event_name == 'pull_request' && steps.app-token.outcome != 'success' | |
| uses: actions/checkout@v7 | |
| with: | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v7 | |
| with: | |
| node-version: '24' | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| # The spec script imports @truefoundry/trueforge-core from its build output. | |
| - name: Build trueforge-core | |
| run: pnpm --filter @truefoundry/trueforge-core build | |
| - name: Write OpenAPI document | |
| run: pnpm --filter @truefoundry/trueforge openapi:write | |
| # Generation and its Docker pull are the slow part, so skip everything below | |
| # when neither the document nor the generator config moved. | |
| - name: Decide whether the SDK needs regenerating | |
| id: decide | |
| env: | |
| BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.before }} | |
| run: | | |
| set -euo pipefail | |
| reason="" | |
| if [ -n "$(git status --porcelain -- .github/fern/openapi/openapi.json docs/openapi.json)" ]; then | |
| reason="the OpenAPI document changed" | |
| elif ! git rev-parse --verify --quiet "${BASE_SHA}^{commit}" >/dev/null; then | |
| # A branch's first push reports an all-zero base commit. | |
| reason="there is no base commit to compare against" | |
| elif ! git diff --quiet "$BASE_SHA" HEAD -- .github/fern/generators.yml .github/fern/fern.config.json; then | |
| reason="the generator config changed" | |
| fi | |
| if [ -n "$reason" ]; then | |
| echo "Regenerating: $reason." | |
| echo "needed=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Skipping: the OpenAPI document and generator config are unchanged." | |
| echo "needed=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| # Same entrypoint as local `pnpm sdk:generate` (re-runs openapi:write; idempotent). | |
| # App-token success = we can push; forks skip Fern so a flake cannot block the PR. | |
| - name: Generate OpenAPI document and TypeScript SDK | |
| if: steps.decide.outputs.needed == 'true' && steps.app-token.outcome == 'success' | |
| run: pnpm sdk:generate | |
| # App-token success = writable head; forks cannot receive this commit. | |
| - name: Commit generated output | |
| if: steps.decide.outputs.needed == 'true' && steps.app-token.outcome == 'success' | |
| # Passed as env, never interpolated into the script, so it cannot inject shell. | |
| env: | |
| BRANCH: ${{ github.head_ref || github.ref_name }} | |
| APP_SLUG: ${{ steps.app-token.outputs.app-slug }} | |
| run: | | |
| set -euo pipefail | |
| # --porcelain, not `git diff`, so new files count too. | |
| # docs/openapi.json is a second copy of the same document (Mintlify); keep it | |
| # in the same commit as .github/fern/openapi or the docs site drifts. | |
| if [ -z "$(git status --porcelain -- .github/fern/openapi docs/openapi.json packages/trueforge-sdk pnpm-lock.yaml)" ]; then | |
| echo "OpenAPI document and SDK are already up to date." | |
| exit 0 | |
| fi | |
| git config user.name "${APP_SLUG}[bot]" | |
| git config user.email "${APP_SLUG}[bot]@users.noreply.github.com" | |
| # Bot-authored sdk diffs need a changeset; the PR author never touches this commit. | |
| # Skip packages/trueforge-sdk/.fern — Fern metadata only, not a consumer-facing change. | |
| # changeset:sdk-regen is a no-op if the sdk is already named in a pending file. | |
| if [ -n "$(git status --porcelain -- packages/trueforge-sdk ':!packages/trueforge-sdk/.fern')" ]; then | |
| pnpm changeset:sdk-regen | |
| fi | |
| git add .github/fern/openapi docs/openapi.json packages/trueforge-sdk pnpm-lock.yaml .changeset | |
| git commit -m "Regenerate OpenAPI document and TypeScript SDK" | |
| git push origin "HEAD:refs/heads/$BRANCH" | |
| - name: Report skipped commit on fork | |
| if: steps.decide.outputs.needed == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository | |
| run: | | |
| set -euo pipefail | |
| { | |
| echo "### Fork pull request" | |
| echo | |
| echo "OpenAPI/SDK commits are skipped on forks (GitHub Apps cannot push to the head repo)." | |
| echo "Do not hand-edit \`packages/trueforge-sdk\` or the OpenAPI documents." | |
| echo "After merge, **Generate SDK** on \`main\` regenerates both (or run it manually from Actions)." | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| echo "::notice::Fork PR: OpenAPI/SDK will be regenerated on main after merge. Do not hand-edit generated files." |