Skip to content

Commit

Permalink
Add workflow that checks schemas for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMcCormick committed Dec 10, 2024
1 parent 97cb3d2 commit 6a9c461
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/compare.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Compare Schemas for Changes

on:
pull_request:

jobs:
compare:
runs-on: ubuntu-latest

steps:
- name: Check out repo
uses: actions/checkout@v4
with:
path: current-ref
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"

- name: Install dependencies
working-directory: current-ref
run: |
python -m pip install --upgrade pip uv
uv pip install --system -r requirements.txt
- name: Set relative path to schema directory
run: |
echo "SCHEMA_DIR=python/lsst/sdm_schemas/schemas" >> $GITHUB_ENV
- name: Get list of changed YAML files
working-directory: current-ref
run: |
echo "Checking for changes compared with: ${{ github.event.pull_request.base.ref }}"
DIFF_OUTPUT=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}..HEAD -- ${{ env.SCHEMA_DIR }})
CHANGED_FILES=$(echo "$DIFF_OUTPUT" | grep '\.yaml$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "No schema files changed."
echo "CHANGED_FILES=" >> $GITHUB_ENV
echo "SCHEMA_FILES_CHANGED=false" >> $GITHUB_ENV
else
CHANGED_FILES=$(echo "$CHANGED_FILES" | sed "s|^${{ env.SCHEMA_DIR }}/||" | tr '\n' ' ')
echo "Changed YAML files: $CHANGED_FILES"
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
echo "SCHEMA_FILES_CHANGED=true" >> $GITHUB_ENV
fi
- name: Check out PR base ref
if: env.SCHEMA_FILES_CHANGED == 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
path: base-ref

- name: Run deepdiff comparison
if: env.SCHEMA_FILES_CHANGED == 'true'
run: |
for file in ${{ env.CHANGED_FILES }}; do
echo "Comparing $file..."
BASE_FILE=base-ref/${{ env.SCHEMA_DIR }}/$file
CURRENT_FILE=current-ref/${{ env.SCHEMA_DIR }}/$file
felis --log-level ERROR diff -c deepdiff $BASE_FILE $CURRENT_FILE
done
- name: Run alembic comparison
if: env.SCHEMA_FILES_CHANGED == 'true'
run: |
for file in ${{ env.CHANGED_FILES }}; do
echo "Comparing $file..."
BASE_FILE=base-ref/${{ env.SCHEMA_DIR }}/$file
CURRENT_FILE=current-ref/${{ env.SCHEMA_DIR }}/$file
felis --log-level ERROR diff -c alembic $BASE_FILE $CURRENT_FILE
done
- name: Run alembic comparison on deployed schemas
if: env.SCHEMA_FILES_CHANGED == 'true'
run: |
ERROR_FLAG=0
DEPLOYED_SCHEMAS=$(cat current-ref/yml/deployed-schemas.txt)
for file in ${{ env.CHANGED_FILES }}; do
if echo "$DEPLOYED_SCHEMAS" | grep -q "^$file$"; then
echo "Comparing $file..."
BASE_FILE=base-ref/${{ env.SCHEMA_DIR }}/$file
CURRENT_FILE=current-ref/${{ env.SCHEMA_DIR }}/$file
if ! felis --log-level ERROR diff -E -c alembic $BASE_FILE $CURRENT_FILE; then
echo "Error comparing $file"
ERROR_FLAG=1
fi
else
echo "Skipping $file (not in deployed-schemas.txt)"
fi
done
if [ $ERROR_FLAG -ne 0 ]; then
echo "One or more schemas was changed."
exit 1
fi

0 comments on commit 6a9c461

Please sign in to comment.