Skip to content

Commit

Permalink
Add workflow for comparing schemas for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMcCormick committed Nov 7, 2024
1 parent a502ee5 commit 8e1b554
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/compare.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Compare Schemas for Changes

on:
push:
branches:
- main
tags:
- "*"
pull_request:

jobs:
compare:
runs-on: ubuntu-latest

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

- name: Fetch origin main
run: cd $GITHUB_WORKSPACE/current-ref && git fetch origin main

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip uv
uv pip install --system -r $GITHUB_WORKSPACE/current-ref/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
run: |
cd $GITHUB_WORKSPACE/current-ref
CHANGED_FILES=$(git diff --name-only origin/main..HEAD -- ${{ env.SCHEMA_DIR }} | sed "s|^${{ env.SCHEMA_DIR }}/||")
echo "Changed YAML files: $CHANGED_FILES"
echo "CHANGED_FILES=$CHANGED_FILES" >> $GITHUB_ENV
- name: Check out main branch
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
path: main-branch

- name: Run felis diff on the schema files
run: |
cd $GITHUB_WORKSPACE
for file in ${{ env.CHANGED_FILES }}; do
echo "Schema diff for $file:"
MAIN_FILE=main-branch/${{ env.SCHEMA_DIR }}/$file
CURRENT_FILE=current-ref/${{ env.SCHEMA_DIR }}/$file
felis diff $MAIN_FILE $CURRENT_FILE
done
- name: Run felis diff of schema file against database
run: |
cd $GITHUB_WORKSPACE
for file in ${{ env.CHANGED_FILES }}; do
echo "Database diff for $file:"
MAIN_FILE=main-branch/${{ env.SCHEMA_DIR }}/$file
DB_URL=sqlite:///$(basename ${MAIN_FILE%.yaml}).db
felis create $MAIN_FILE --engine-url $DB_URL
CURRENT_FILE=current-ref/${{ env.SCHEMA_DIR }}/$file
echo "Comparing $DB_URL to $CURRENT_FILE"
felis diff --engine-url $DB_URL $CURRENT_FILE
done

0 comments on commit 8e1b554

Please sign in to comment.