Skip to content

Add NotFoundResponse to AppBFFAPI #16

Add NotFoundResponse to AppBFFAPI

Add NotFoundResponse to AppBFFAPI #16

Workflow file for this run

name: Create PR on Schema Change
on:
push:
branches:
- main
paths:
- "src/**"
- "main.tsp"
- "tspconfig.yaml"
workflow_dispatch:
jobs:
compile:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: jdx/mise-action@v3
- name: Install
run: task install
- name: Compile
run: task compile
- uses: actions/upload-artifact@v4
with:
name: schemas
path: tsp-output/schema/
create-pr:
needs: compile
runs-on: ubuntu-latest
strategy:
matrix:
include:
- repo: dotto-flutter
type: app
schema: openapi.AppBFFService.yaml
- repo: dotto-admin-web
type: app
schema: openapi.AdminBFFService.yaml
- repo: app-bff-api
type: bff
schema: openapi.AppBFFService.yaml
- repo: admin-bff-api
type: bff
schema: openapi.AdminBFFService.yaml
- repo: academic-api
type: backend
schema: openapi.AcademicService.yaml
- repo: announcement-api
type: backend
schema: openapi.AnnouncementService.yaml
- repo: funch-api
type: backend
schema: openapi.FunchService.yaml
- repo: user-api
type: backend
schema: openapi.UserService.yaml
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.DOTTO_API_SCHEMA_UPDATER_APP_ID }}
private-key: ${{ secrets.DOTTO_API_SCHEMA_UPDATER_APP_PRIVATE_KEY }}
owner: fun-dotto
repositories: ${{ matrix.repo }}
- uses: actions/download-artifact@v4
with:
name: schemas
path: schemas
- name: Check if branch and PR exist
id: check-existing
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
# Check if branch exists
exit_code=0
git ls-remote --exit-code --heads https://x-access-token:${GH_TOKEN}@github.com/fun-dotto/${{ matrix.repo }}.git update-openapi-schema || exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "branch_exists=true" >> $GITHUB_OUTPUT
else
echo "branch_exists=false" >> $GITHUB_OUTPUT
fi
# Check if PR exists
pr_count=$(gh pr list --repo fun-dotto/${{ matrix.repo }} --head update-openapi-schema --base main --state open --json number --jq 'length')
if [ "$pr_count" -gt 0 ]; then
echo "pr_exists=true" >> $GITHUB_OUTPUT
else
echo "pr_exists=false" >> $GITHUB_OUTPUT
fi
- uses: actions/checkout@v6
with:
repository: fun-dotto/${{ matrix.repo }}
token: ${{ steps.app-token.outputs.token }}
path: target-repo
ref: ${{ steps.check-existing.outputs.branch_exists == 'true' && steps.check-existing.outputs.pr_exists == 'true' && 'update-openapi-schema' || '' }}
- name: Copy schemas
run: |
if [ -z "${{ matrix.schema }}" ]; then
echo "Error: matrix.schema is required"
exit 1
fi
mkdir -p target-repo/openapi
cp schemas/${{ matrix.schema }} target-repo/openapi/openapi.yaml
if [ "${{ matrix.type }}" = "bff" ]; then
mkdir -p target-repo/openapi/external/academic_api
mkdir -p target-repo/openapi/external/announcement_api
mkdir -p target-repo/openapi/external/funch_api
mkdir -p target-repo/openapi/external/user_api
cp schemas/openapi.AcademicService.yaml target-repo/openapi/external/academic_api/openapi.yaml
cp schemas/openapi.AnnouncementService.yaml target-repo/openapi/external/announcement_api/openapi.yaml
cp schemas/openapi.FunchService.yaml target-repo/openapi/external/funch_api/openapi.yaml
cp schemas/openapi.UserService.yaml target-repo/openapi/external/user_api/openapi.yaml
fi
- name: Push to existing branch
if: steps.check-existing.outputs.branch_exists == 'true' && steps.check-existing.outputs.pr_exists == 'true'
working-directory: target-repo
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "Update OpenAPI schema from dotto-typespec"
git push
fi
- uses: peter-evans/create-pull-request@v7
if: steps.check-existing.outputs.branch_exists != 'true' || steps.check-existing.outputs.pr_exists != 'true'
with:
token: ${{ steps.app-token.outputs.token }}
path: target-repo
branch: update-openapi-schema
draft: true
title: "Update OpenAPI schema"
body: |
This PR updates the OpenAPI schema from [dotto-typespec](https://github.com/fun-dotto/dotto-typespec).
Triggered by: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
commit-message: "Update OpenAPI schema from dotto-typespec"