From 91832c4a33807dfd8ee9a53a3ab97ff77227f9f1 Mon Sep 17 00:00:00 2001 From: Jeremy McCormick Date: Mon, 25 Nov 2024 15:23:48 -0600 Subject: [PATCH] Add workflow for triggering cdb migrations --- .github/workflows/migrate_cdb.yaml | 80 ++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/migrate_cdb.yaml diff --git a/.github/workflows/migrate_cdb.yaml b/.github/workflows/migrate_cdb.yaml new file mode 100644 index 00000000..6bd8fe61 --- /dev/null +++ b/.github/workflows/migrate_cdb.yaml @@ -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 }}" + }