From 9079d53bc83aa7996de1f42e6d24191f8926878e Mon Sep 17 00:00:00 2001 From: Howard Askew <19271569+howaskew@users.noreply.github.com> Date: Wed, 21 Oct 2026 13:16:53 +0100 Subject: [PATCH] ci: Let other repositories test generated models before merging Allow the Update Data Model workflow to be called from other repositories with a models-lib or data-models ref. When called this way it generates the TypeScript models, builds and tests them, and does not create a pull request. models-lib pull requests can then check that the generated TypeScript compiles and passes the example tests. Replaces #7, which predates the GitHub App token change: it used an expression in a reusable workflow `uses:` (not allowed), and checked out the calling repository instead of models-ts when called from elsewhere. This version runs the tests in the same job, so no nested workflow or artifact is needed. Also: - name the models-ts repository in its checkout - run the models-ts tests (tsc and mocha) before creating a pull request - Node 18.17.1, actions/checkout v4, actions/setup-node v4 - peter-evans/create-pull-request v7 (v4 fails after updating an existing pull request: "Cannot read properties of undefined") Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/create-data-model-pr.yaml | 58 ++++++++++++++++----- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/.github/workflows/create-data-model-pr.yaml b/.github/workflows/create-data-model-pr.yaml index 680ee4d..3df06ae 100644 --- a/.github/workflows/create-data-model-pr.yaml +++ b/.github/workflows/create-data-model-pr.yaml @@ -4,50 +4,79 @@ on: workflow_dispatch: repository_dispatch: types: [data-models-update] + # Lets other repositories (e.g. models-lib pull requests) test the TypeScript models generated + # from a specific models-lib or data-models ref. In that case no pull request is created. + workflow_call: + inputs: + models-lib_ref: + required: false + type: string + data-models_ref: + required: false + type: string + +permissions: + contents: read jobs: generate: runs-on: ubuntu-latest steps: + # The repository is named explicitly, as this workflow can be called from another repository - name: Checkout models-ts - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: + repository: openactive/models-ts ref: main path: models-ts - name: Checkout models-lib - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: repository: openactive/models-lib + ref: ${{ inputs.models-lib_ref }} path: models-lib - - name: Setup Node.js 14.x - uses: actions/setup-node@v1 + - name: Setup Node.js 18.17.1 + uses: actions/setup-node@v4 with: - node-version: 14.x - + node-version: 18.17.1 + - name: Install models-lib run: npm install working-directory: ./models-lib/ - + - name: Update models-lib with latest data-models + if: ${{ !inputs.data-models_ref }} run: npm update @openactive/data-models working-directory: ./models-lib/ + - name: Install data-models ${{ inputs.data-models_ref }} + if: ${{ inputs.data-models_ref }} + env: + DATA_MODELS_REF: ${{ inputs.data-models_ref }} + run: npm install "github:openactive/data-models#$DATA_MODELS_REF" + working-directory: ./models-lib/ + - name: Run TypeScript models generator run: npm start -- generate TypeScript --destination ../models-ts/src/ working-directory: ./models-lib/ - + - name: Install models-ts run: npm install working-directory: ./models-ts/ - + - name: Build models-ts types run: npm run build working-directory: ./models-ts/ + - name: Test models-ts + run: npm test + working-directory: ./models-ts/ + - name: Generate GitHub App Token + if: ${{ !inputs.models-lib_ref && !inputs.data-models_ref }} uses: actions/create-github-app-token@v1 id: generate-token with: @@ -55,8 +84,9 @@ jobs: private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} - name: Create Pull Request + if: ${{ !inputs.models-lib_ref && !inputs.data-models_ref }} id: cpr - uses: peter-evans/create-pull-request@v4 + uses: peter-evans/create-pull-request@v7 with: path: ./models-ts/ token: ${{ steps.generate-token.outputs.token }} @@ -74,6 +104,10 @@ jobs: draft: false - name: Check outputs + if: ${{ !inputs.models-lib_ref && !inputs.data-models_ref }} + env: + PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }} + PR_URL: ${{ steps.cpr.outputs.pull-request-url }} run: | - echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" - echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" + echo "Pull Request Number - $PR_NUMBER" + echo "Pull Request URL - $PR_URL"