|
| 1 | +name: Validate SDKs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +concurrency: |
| 8 | + group: sdk-validation-${{ github.event.pull_request.number }} |
| 9 | + cancel-in-progress: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + detect-changes: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + spec-changed: ${{ steps.filter.outputs.spec }} |
| 16 | + matrix: ${{ steps.set-matrix.outputs.matrix }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 19 | + |
| 20 | + - uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 |
| 21 | + id: filter |
| 22 | + with: |
| 23 | + filters: | |
| 24 | + spec: |
| 25 | + - 'spec/**' |
| 26 | +
|
| 27 | + - name: Load SDK matrix |
| 28 | + id: set-matrix |
| 29 | + run: echo "matrix=$(jq -c . .github/sdk-matrix.json)" >> "$GITHUB_OUTPUT" |
| 30 | + |
| 31 | + sdk_build: |
| 32 | + needs: detect-changes |
| 33 | + if: needs.detect-changes.outputs.spec-changed == 'true' |
| 34 | + runs-on: ubuntu-latest |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + include: ${{ fromJson(needs.detect-changes.outputs.matrix) }} |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Generate GitHub App token |
| 42 | + id: app-token |
| 43 | + uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2.2.2 |
| 44 | + with: |
| 45 | + app-id: ${{ secrets.SDK_BOT_APP_ID }} |
| 46 | + private-key: ${{ secrets.SDK_BOT_PRIVATE_KEY }} |
| 47 | + |
| 48 | + - name: Checkout openapi-spec |
| 49 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 50 | + with: |
| 51 | + path: openapi-spec |
| 52 | + |
| 53 | + - name: Checkout oagen-emitters |
| 54 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 55 | + with: |
| 56 | + repository: workos/oagen-emitters |
| 57 | + token: ${{ steps.app-token.outputs.token }} |
| 58 | + path: oagen-emitters |
| 59 | + |
| 60 | + - name: Checkout live SDK |
| 61 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 62 | + with: |
| 63 | + repository: ${{ matrix.sdk_repo }} |
| 64 | + token: ${{ steps.app-token.outputs.token }} |
| 65 | + path: ${{ matrix.sdk_checkout_path }} |
| 66 | + |
| 67 | + - name: Setup Node |
| 68 | + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
| 69 | + with: |
| 70 | + node-version: '24' |
| 71 | + cache: 'npm' |
| 72 | + cache-dependency-path: oagen-emitters/package-lock.json |
| 73 | + |
| 74 | + - name: Install dependencies |
| 75 | + working-directory: oagen-emitters |
| 76 | + run: npm ci |
| 77 | + |
| 78 | + - name: Extract baseline |
| 79 | + working-directory: oagen-emitters |
| 80 | + run: npm run sdk:extract:${{ matrix.language }} |
| 81 | + |
| 82 | + - name: Generate |
| 83 | + working-directory: oagen-emitters |
| 84 | + run: npm run sdk:generate:${{ matrix.language }} |
| 85 | + |
| 86 | + - name: Verify |
| 87 | + working-directory: oagen-emitters |
| 88 | + run: npm run sdk:verify:${{ matrix.language }} |
| 89 | + |
| 90 | + - name: Comment on failure |
| 91 | + if: failure() |
| 92 | + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 |
| 93 | + with: |
| 94 | + github-token: ${{ steps.app-token.outputs.token }} |
| 95 | + script: | |
| 96 | + const body = [ |
| 97 | + `## SDK build failed for \`${{ matrix.language }}\``, |
| 98 | + '', |
| 99 | + 'The spec changes in this PR caused the **${{ matrix.language }}** SDK build to fail.', |
| 100 | + '', |
| 101 | + `**[View workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})**`, |
| 102 | + '', |
| 103 | + 'This check must pass before the PR can be merged.' |
| 104 | + ].join('\n'); |
| 105 | +
|
| 106 | + await github.rest.issues.createComment({ |
| 107 | + owner: context.repo.owner, |
| 108 | + repo: context.repo.repo, |
| 109 | + issue_number: context.issue.number, |
| 110 | + body |
| 111 | + }); |
| 112 | +
|
| 113 | + - name: Upload diagnostics |
| 114 | + if: always() |
| 115 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 116 | + with: |
| 117 | + name: oagen-diagnostics-${{ matrix.language }} |
| 118 | + path: | |
| 119 | + oagen-emitters/sdk/ |
| 120 | + oagen-emitters/sdk-*-surface.json |
| 121 | + oagen-emitters/smoke-*.json |
| 122 | + retention-days: 14 |
| 123 | + |
| 124 | + sdk-validation: |
| 125 | + runs-on: ubuntu-latest |
| 126 | + needs: [detect-changes, sdk_build] |
| 127 | + if: always() |
| 128 | + steps: |
| 129 | + - name: Check result |
| 130 | + run: | |
| 131 | + if [[ "${{ needs.detect-changes.outputs.spec-changed }}" != "true" ]]; then |
| 132 | + echo "No spec changes, skipping SDK validation" |
| 133 | + exit 0 |
| 134 | + fi |
| 135 | + if [[ "${{ needs.sdk_build.result }}" != "success" ]]; then |
| 136 | + echo "SDK build failed" |
| 137 | + exit 1 |
| 138 | + fi |
0 commit comments