-
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.
Add workflow for triggering cdb migrations
- Loading branch information
1 parent
8aad214
commit 91832c4
Showing
1 changed file
with
80 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,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 }}" | ||
} |