Skip to content

Commit

Permalink
Add workflow for triggering cdb migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMcCormick committed Nov 25, 2024
1 parent 8aad214 commit 91832c4
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/migrate_cdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Trigger ConsDB Database Migrations

on:
pull_request:
types: [closed]

jobs:
migrate-cdb:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true # Only trigger on merged PRs

steps:

- name: Checkout PR repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
path: pr

- name: Checkout main repo
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
path: main

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

- name: Install dependencies
working-directory: ${{ github.workspace }}/pr
run: |
set -e
python -m pip install --upgrade pip uv
uv pip install --system -r requirements.txt
shell: bash

- name: Compare PR to main
working-directory: ${{ github.workspace }}/pr
run: |
CHANGED_FILES=()
for SCHEMA_FILE in python/lsst/sdm_schemas/schemas/cdb_*.yaml; do
MAIN_FILE=../main/python/lsst/sdm_schemas/schemas/$(basename $SCHEMA_FILE)
if [ -f "$MAIN_FILE" ]; then
echo "Comparing $MAIN_FILE to $SCHEMA_FILE"
DIFF_RESULTS=$(felis diff --comparator alembic $MAIN_FILE $SCHEMA_FILE)
if [ $? -ne 0 ]; then
echo "Error running felis diff on $SCHEMA_FILE"
exit 1
fi
echo "$DIFF_RESULTS"
if [ -n "$DIFF_RESULTS" ]; then
echo "Schema file $SCHEMA_FILE has changed"
CHANGED_FILES+=($SCHEMA_FILE)
fi
else
echo "Schema file $SCHEMA_FILE is new"
CHANGED_FILES+=($SCHEMA_FILE)
fi
done
if [ ${#CHANGED_FILES[@]} -eq 0 ]; then
echo "No cdb schema files changed"
exit 0
else
echo "Changed cdb schema files: ${CHANGED_FILES[@]}"
fi
- name: Trigger migration workflow in consdb repository
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.REPO_DISPATCH_TOKEN }}
repository: JeremyMcCormick/consdb-dm-47507
event-type: migration
client-payload: |
{
"branch_name": "${{ github.event.pull_request.head.ref }}",
"commit_sha": "${{ github.event.pull_request.merge_commit_sha }}"
}

0 comments on commit 91832c4

Please sign in to comment.