-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from lsst/tickets/DM-46158
DM-46158: Add workflow to perform schema comparisons and check for changes to deployed schemas
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |