Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/generated-schemas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Generated Schemas

on:
pull_request:
branches: [ main ]
paths:
- 'openapi/components/schemas/**'

jobs:
no-manual-edits:
name: Check for manual edits
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Check for manual edits to generated schemas
if: >-
github.event.pull_request.user.login != 'lightspark-copybara[bot]' &&
!contains(github.event.pull_request.labels.*.name, 'edit-generated-schemas')
env:
BASE_REF: ${{ github.base_ref }}
run: |
set -euo pipefail

manifest=openapi/generated-schemas.txt
if [ ! -f "$manifest" ]; then
echo "$manifest does not exist yet; nothing to check."
exit 0
fi

: > edited.txt
git diff --name-only "origin/$BASE_REF...HEAD" > changed.txt
while IFS= read -r file; do
case "$file" in
openapi/components/schemas/*) ;;
*) continue ;;
esac
if grep -qxF "$(basename "$file")" "$manifest"; then
echo " $file" >> edited.txt
fi
done < changed.txt

if [ -s edited.txt ]; then
echo "::error::These schemas are generated. Edits to them are overwritten by the next sync."
cat edited.txt
echo "Add the 'edit-generated-schemas' label to override."
exit 1
fi

echo "No generated schemas were edited."
Loading