|
| 1 | +name: Regenerate Types |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [openapi-spec-updated] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + spec_repo: |
| 9 | + description: "Repo to fetch spec from (owner/repo)" |
| 10 | + default: "osodevops/keito" |
| 11 | + spec_path: |
| 12 | + description: "Path to spec in repo" |
| 13 | + default: "docs/openapi-v2.yaml" |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + generate: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + - uses: actions/setup-node@v4 |
| 25 | + with: |
| 26 | + node-version: 22 |
| 27 | + cache: npm |
| 28 | + - run: npm ci |
| 29 | + |
| 30 | + - name: Fetch latest spec |
| 31 | + env: |
| 32 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + run: | |
| 34 | + REPO="${{ github.event.inputs.spec_repo || 'osodevops/keito' }}" |
| 35 | + SPEC_PATH="${{ github.event.inputs.spec_path || 'docs/openapi-v2.yaml' }}" |
| 36 | + gh api "repos/${REPO}/contents/${SPEC_PATH}" \ |
| 37 | + --jq '.content' | base64 -d > openapi/openapi-v2.yaml |
| 38 | +
|
| 39 | + - run: npm run generate |
| 40 | + - run: npm run typecheck |
| 41 | + - run: npm test |
| 42 | + |
| 43 | + - name: Check for changes |
| 44 | + id: diff |
| 45 | + run: | |
| 46 | + if git diff --quiet openapi/ src/generated/; then |
| 47 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 48 | + else |
| 49 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Create PR |
| 53 | + if: steps.diff.outputs.changed == 'true' |
| 54 | + uses: peter-evans/create-pull-request@v6 |
| 55 | + with: |
| 56 | + branch: chore/regenerate-types |
| 57 | + commit-message: "chore: regenerate types from updated OpenAPI spec" |
| 58 | + title: "chore: regenerate types from updated OpenAPI spec" |
| 59 | + body: | |
| 60 | + Auto-generated PR from updated OpenAPI spec. |
| 61 | +
|
| 62 | + - Fetched latest spec from upstream |
| 63 | + - Regenerated `src/generated/openapi.d.ts` |
| 64 | + - Type checking and tests pass |
| 65 | +
|
| 66 | + Review the diff and merge to trigger a release. |
0 commit comments