-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (88 loc) · 2.88 KB
/
db-changes-var2.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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"