98 lines
3.3 KiB
YAML
98 lines
3.3 KiB
YAML
name: SDK Codegen Drift
|
|
|
|
# Re-runs the @hivegrid/api-client-ts generation pipeline on PRs that touch the
|
|
# upstream OpenAPI surface or the SDK package, then verifies the
|
|
# committed src/generated/ tree is in sync with openapi.json.
|
|
#
|
|
# Docs: docs/sdks/typescript.md
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- "apps/api/src/openapi.ts"
|
|
- "apps/api/src/openapi.test.ts"
|
|
- "packages/api-client-ts/**"
|
|
- "packages/api-types/**"
|
|
- ".gitea/workflows/sdk-codegen.yml"
|
|
|
|
env:
|
|
HIVEGRID_GITEA_HOST_IP: ${{ vars.HIVEGRID_GITEA_HOST_IP }}
|
|
|
|
jobs:
|
|
drift-check:
|
|
name: Verify SDK codegen is in sync with OpenAPI spec
|
|
runs-on: toolctrl-ci
|
|
timeout-minutes: 15
|
|
steps:
|
|
- name: Resolve internal Gitea host
|
|
run: |
|
|
if [ -n "${HIVEGRID_GITEA_HOST_IP:-}" ]; then
|
|
if ! HIVEGRID_GITEA_HOST_IP="$HIVEGRID_GITEA_HOST_IP" node -e 'process.exit(require("node:net").isIP(process.env.HIVEGRID_GITEA_HOST_IP || "") ? 0 : 1)'; then
|
|
echo "HIVEGRID_GITEA_HOST_IP must be a single IPv4 or IPv6 token"
|
|
exit 1
|
|
fi
|
|
printf '%s git.tool-ctrl.de\n' "$HIVEGRID_GITEA_HOST_IP" >> /etc/hosts
|
|
fi
|
|
|
|
- name: Checkout PR head
|
|
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
|
|
|
- name: Set up Node.js
|
|
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
|
|
with:
|
|
node-version-file: .nvmrc
|
|
|
|
- name: Persist Node.js toolchain
|
|
run: bash scripts/ci/persist-node-toolchain.sh
|
|
|
|
- name: Enable Corepack
|
|
run: corepack enable --install-directory /usr/local/bin
|
|
|
|
- name: Prepare pnpm 11.12.0
|
|
run: corepack prepare pnpm@11.12.0 --activate
|
|
|
|
- name: Configure pnpm store
|
|
run: pnpm config set store-dir .pnpm-store
|
|
|
|
- name: Cache pnpm store
|
|
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
|
|
with:
|
|
path: .pnpm-store
|
|
key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile --prefer-offline
|
|
|
|
- name: Regenerate OpenAPI capture
|
|
run: pnpm --filter @hivegrid/api-client-ts generate-spec
|
|
|
|
- name: Regenerate typed client (Hey-API)
|
|
run: pnpm --filter @hivegrid/api-client-ts generate
|
|
|
|
- name: Fail if generated code drifts from committed state
|
|
run: |
|
|
if ! git diff --exit-code --stat \
|
|
packages/api-client-ts/openapi.json \
|
|
packages/api-client-ts/src/generated; then
|
|
echo ""
|
|
echo "SDK codegen drift detected. Run:"
|
|
echo ""
|
|
echo " pnpm --filter @hivegrid/api-client-ts generate:all"
|
|
echo ""
|
|
echo "then commit packages/api-client-ts/openapi.json and packages/api-client-ts/src/generated/."
|
|
exit 1
|
|
fi
|
|
echo "SDK codegen is in sync with the upstream OpenAPI spec."
|
|
|
|
- name: Typecheck SDK packages
|
|
run: |
|
|
pnpm --filter @hivegrid/api-client-ts typecheck
|
|
pnpm --filter @hivegrid/api-types typecheck
|
|
|
|
- name: Run SDK tests
|
|
run: |
|
|
pnpm --filter @hivegrid/api-client-ts test
|
|
pnpm --filter @hivegrid/api-types test
|