Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-46158: Add workflow to perform schema comparisons and check for changes to deployed schemas #277

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
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
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
4 changes: 4 additions & 0 deletions python/lsst/sdm_schemas/schemas/deployed-schemas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dp02_dc2.yaml
dp02_obscore.yaml
dp03_10yr.yaml
dp03_1yr.yaml
Loading