|
| 1 | +name: Check generated models |
| 2 | + |
| 3 | +# Verifies the committed generated API models are still in sync with the Java |
| 4 | +# OpenAPI spec: the frontend tool API types |
| 5 | +# (frontend/editor/src/core/types/toolApiTypes.ts) and the engine tool |
| 6 | +# models (engine/src/stirling/models/tool_models.py). Regenerates both with the |
| 7 | +# single top-level `task tool-models` and fails if either committed file is |
| 8 | +# out of date. Called from build.yml when the backend Java, frontend, or engine |
| 9 | +# changes; also runs on push to main as a post-merge safety net. |
| 10 | +on: |
| 11 | + workflow_call: |
| 12 | + push: |
| 13 | + branches: [main] |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + generated-models: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + pull-requests: write |
| 24 | + env: |
| 25 | + DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }} |
| 26 | + steps: |
| 27 | + - name: Harden the runner (Audit all outbound calls) |
| 28 | + uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3 |
| 29 | + with: |
| 30 | + egress-policy: audit |
| 31 | + |
| 32 | + - name: Checkout code |
| 33 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 34 | + |
| 35 | + - name: Install uv |
| 36 | + uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0 |
| 37 | + with: |
| 38 | + enable-cache: true |
| 39 | + |
| 40 | + - name: Set up JDK 25 |
| 41 | + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 |
| 42 | + with: |
| 43 | + java-version: "25" |
| 44 | + distribution: "temurin" |
| 45 | + |
| 46 | + - name: Setup Gradle |
| 47 | + uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e # v6.1.0 |
| 48 | + with: |
| 49 | + gradle-version: 9.6.0 |
| 50 | + |
| 51 | + - name: Set up Node |
| 52 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 53 | + with: |
| 54 | + node-version: "22" |
| 55 | + cache: "npm" |
| 56 | + cache-dependency-path: frontend/package-lock.json |
| 57 | + |
| 58 | + - name: Install Task |
| 59 | + uses: go-task/setup-task@01a4adf9db2d14c1de7a560f09170b6e0df736aa # v2.1.0 |
| 60 | + |
| 61 | + # Rebuilds the OpenAPI spec from the current Java and regenerates both the |
| 62 | + # frontend types and the engine tool models from it. |
| 63 | + - name: Regenerate generated models |
| 64 | + run: task tool-models |
| 65 | + |
| 66 | + - name: Verify generated models are up to date |
| 67 | + id: models-check |
| 68 | + continue-on-error: true |
| 69 | + run: | |
| 70 | + git diff --exit-code \ |
| 71 | + frontend/editor/src/core/types/toolApiTypes.ts \ |
| 72 | + engine/src/stirling/models/tool_models.py |
| 73 | +
|
| 74 | + - name: Comment on generated models check failure |
| 75 | + # Only post a comment on PRs. github-script's PR helpers need an |
| 76 | + # issue/PR number, which doesn't exist on merge_group runs. |
| 77 | + if: steps.models-check.outcome == 'failure' && github.event_name == 'pull_request' |
| 78 | + continue-on-error: true |
| 79 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 80 | + with: |
| 81 | + script: | |
| 82 | + const marker = '<!-- generated-models-check -->'; |
| 83 | + const body = [ |
| 84 | + marker, |
| 85 | + '### Generated Models Check Failed', |
| 86 | + '', |
| 87 | + 'The generated `frontend/editor/src/core/types/toolApiTypes.ts` and/or `engine/src/stirling/models/tool_models.py` are out of date with the Java OpenAPI spec and will need to be regenerated before they can be merged in.', |
| 88 | + '', |
| 89 | + 'Run `task tool-models` to regenerate both, then commit the updated files.', |
| 90 | + ].join('\n'); |
| 91 | + const { data: comments } = await github.rest.issues.listComments({ |
| 92 | + owner: context.repo.owner, |
| 93 | + repo: context.repo.repo, |
| 94 | + issue_number: context.issue.number, |
| 95 | + }); |
| 96 | + const existing = comments.find(c => c.body.includes(marker)); |
| 97 | + if (existing) { |
| 98 | + await github.rest.issues.updateComment({ |
| 99 | + owner: context.repo.owner, |
| 100 | + repo: context.repo.repo, |
| 101 | + comment_id: existing.id, |
| 102 | + body, |
| 103 | + }); |
| 104 | + } else { |
| 105 | + await github.rest.issues.createComment({ |
| 106 | + owner: context.repo.owner, |
| 107 | + repo: context.repo.repo, |
| 108 | + issue_number: context.issue.number, |
| 109 | + body, |
| 110 | + }); |
| 111 | + } |
| 112 | +
|
| 113 | + - name: Fail if generated models check failed |
| 114 | + if: steps.models-check.outcome == 'failure' |
| 115 | + run: | |
| 116 | + echo "============================================" |
| 117 | + echo " Generated Models Check Failed" |
| 118 | + echo "============================================" |
| 119 | + echo "" |
| 120 | + echo "The generated frontend API types and/or engine tool" |
| 121 | + echo "models are out of date with the Java OpenAPI spec and" |
| 122 | + echo "will need to be regenerated before they can be merged in." |
| 123 | + echo "" |
| 124 | + echo "Run 'task tool-models' to regenerate both, then" |
| 125 | + echo "commit the updated files." |
| 126 | + echo "============================================" |
| 127 | + exit 1 |
| 128 | +
|
| 129 | + - name: Remove generated models check comment on success |
| 130 | + if: steps.models-check.outcome == 'success' && github.event_name == 'pull_request' |
| 131 | + continue-on-error: true |
| 132 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 133 | + with: |
| 134 | + script: | |
| 135 | + const marker = '<!-- generated-models-check -->'; |
| 136 | + const { data: comments } = await github.rest.issues.listComments({ |
| 137 | + owner: context.repo.owner, |
| 138 | + repo: context.repo.repo, |
| 139 | + issue_number: context.issue.number, |
| 140 | + }); |
| 141 | + const existing = comments.find(c => c.body.includes(marker)); |
| 142 | + if (existing) { |
| 143 | + await github.rest.issues.deleteComment({ |
| 144 | + owner: context.repo.owner, |
| 145 | + repo: context.repo.repo, |
| 146 | + comment_id: existing.id, |
| 147 | + }); |
| 148 | + } |
0 commit comments