Skip to content

Side chore

Side chore #31

name: DB Change Check var2
on:
pull_request:
branches:
- main
jobs:
check-sql-schema-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout Current Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check For DB Schema Change
id: db-schema-changes
uses: tj-actions/changed-files@v45
with:
files: "app/**"
- name: Check For Migration File
id: migration-changes
uses: tj-actions/changed-files@v45
with:
files: 'migrations/**'
- name: Determine Outcome
id: determine-outcome
run: |
echo "DB_CHANGE=${{ steps.db-schema-changes.outputs.any_changed }}" >> $GITHUB_ENV
echo "MIGRATION_CHANGE=${{ steps.migration-changes.outputs.any_changed }}" >> $GITHUB_ENV
- name: Check Conditions
id: check-conditions
run: |
if [[ "${{ env.DB_CHANGE }}" == "true" && "${{ env.MIGRATION_CHANGE }}" == "true" ]]; then
echo "Conditions met. Continue to the next job."
echo "true" > continue.txt
elif [[ "${{ env.DB_CHANGE }}" == "true" || "${{ env.MIGRATION_CHANGE }}" == "true" ]]; then
echo "Only one condition is true. Failing the job."
exit 1
else
echo "Neither condition is true. Completing successfully."
echo "true" > continue.txt
fi
- name: Set Continue Output
id: set-continue-output
run: echo "continue=$(cat continue.txt)" >> $GITHUB_OUTPUT
run-alembic:
needs: check-sql-schema-changes
# if: ${{ needs.check-sql-schema-changes.outputs.continue == 'true' }}
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14-bullseye
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_HOST: localhost
POSTGRES_DRIVERNAME: postgresql
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Generate envs
id: generate-envs
run: |
DATABASE_URL="postgresql://postgres:postgres@localhost:5432"
echo "DATABASE_URL=$DATABASE_URL" >> $GITHUB_ENV
- name: Install alembic
run: |
python -m pip install --upgrade pip
pip install alembic # version?
- name: (Try) Run alembic upgrade
id: run-alembic-upgrade
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
run: |
alembic -c migrations/starter-kit/alembic.ini upgrade head"