-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (72 loc) · 2.81 KB
/
main.yml
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
name: DB Change Checks
on:
push
jobs:
check-sql-schema-changes:
runs-on: ubuntu-latest
steps:
- name: 1. Checkout Current Branch
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: 2. Check For Changes
id: changed-db-files
uses: tj-actions/changed-files@v44
with:
files: |
- "app/"
- name: 2a. Output Changed Files
run: |
echo "Changed files bool: ${{ steps.check-sql-schema-changes.outputs.any_changed == 'true' }}"
echo "Changed files: ${{ steps.changed-db-files.outputs.changed_files }}"
- name: 3. Set up Python
id: setup-python
uses: actions/setup-python@v5
if: steps.check-sql-schema-changes.outputs.any_changed == 'true'
with:
python-version: '3.11'
- name: 4. Generate envs
id: generate-envs
if: steps.check-sql-schema-changes.outputs.any_changed == 'true'
run: |
TIMESTAMP=$(date +'%Y%m%d%H%M')
BRANCH_NAME="my-branch-$TIMESTAMP"
DATABASE_URL="abcd"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
echo "DATABASE_URL=$DATABASE_URL" >> $GITHUB_ENV
- name: 5. Install alembic
if: steps.check-sql-schema-changes.outputs.any_changed == 'true'
run: |
python -m pip install --upgrade pip
pip install -r app/requirements.txt
- name: 6. Run alembic script autogeneration
if: steps.check-sql-schema-changes.outputs.any_changed == 'true'
id: run-alembic-script-autogen
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
run: |
alembic -c alembic.ini revision --autogenerate -m "test script {{ env.BRANCH_NAME }}"
- name: 7. Checkout new branch
if: steps.check-sql-schema-changes.outputs.any_changed == 'true'
id: checkout-new-branch
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git checkout -b ${{ env.BRANCH_NAME }}
git push origin ${{ env.BRANCH_NAME }}
- name: 8. Add-alembic-script-to-new-branch
if: steps.check-sql-schema-changes.outputs.any_changed == 'true'
run: |
git add .
git commit -m "Add new Alembic migration"
git push origin HEAD:${{ github.ref }}
- name: 9. Create PR
if: steps.check-sql-schema-changes.outputs.any_changed == 'true'
id: create-pull-request
uses: peter-evans/create-pull-request@v5
with:
branch: ${{ env.BRANCH_NAME }}
base: main
title: "BotPR: {{ env.BRANCH_NAME }}"
author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"