SDK for go and typescript #2
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: SDK | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'api/**' | |
| - 'sdk/**' | |
| - 'Makefile' | |
| - '.github/workflows/sdk.yml' | |
| pull_request: | |
| branches: [main] | |
| paths: | |
| - 'api/**' | |
| - 'sdk/**' | |
| - 'Makefile' | |
| - '.github/workflows/sdk.yml' | |
| - 'frontend/src/api/**' | |
| - 'frontend/package.json' | |
| jobs: | |
| contract-and-generate: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Validate OpenAPI YAML | |
| run: | | |
| python3 - <<'PY' | |
| import pathlib, sys | |
| try: | |
| import yaml | |
| except ImportError: | |
| import subprocess | |
| subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'pyyaml', '-q']) | |
| import yaml | |
| data = yaml.safe_load(pathlib.Path('api/openapi.yaml').read_text()) | |
| assert data.get('openapi', '').startswith('3.'), data.get('openapi') | |
| assert 'paths' in data and data['paths'] | |
| ops = [] | |
| for path, item in data['paths'].items(): | |
| for method, op in item.items(): | |
| if isinstance(op, dict) and 'operationId' in op: | |
| ops.append(op['operationId']) | |
| assert 'getMe' in ops and 'createToken' in ops, ops[:10] | |
| print(f'ok: {len(data["paths"])} paths, {len(ops)} operations') | |
| PY | |
| - name: Setup Go (route coverage) | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: backend/go.mod | |
| - name: OpenAPI route coverage | |
| working-directory: backend | |
| run: go test ./internal/openapi/ -count=1 | |
| - name: Generate SDKs | |
| run: make sdk-generate | |
| - name: Fail on generated drift | |
| run: | | |
| git add -N api/openapi.yaml sdk/go/openapi sdk/typescript/src/generated || true | |
| if ! git diff --exit-code -- api/openapi.yaml sdk/go/openapi sdk/typescript/src/generated; then | |
| echo "SDK drift detected; run 'make sdk-generate' and commit" | |
| exit 1 | |
| fi | |
| go-sdk: | |
| runs-on: ubuntu-latest | |
| needs: [contract-and-generate] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: sdk/go/go.mod | |
| - name: Test Go SDK | |
| run: make sdk-go-test | |
| typescript-sdk: | |
| runs-on: ubuntu-latest | |
| needs: [contract-and-generate] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 26 | |
| cache: npm | |
| cache-dependency-path: sdk/typescript/package-lock.json | |
| - name: Build and test TypeScript SDK | |
| run: | | |
| cd sdk/typescript | |
| npm ci | |
| npm test | |
| npm run build |