-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (69 loc) · 2.58 KB
/
migrations.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
name: Migrations
on:
pull_request:
jobs:
detect-diffs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Changes in models directories
id: model-changes
uses: tj-actions/changed-files@v45
with:
path: "core/services"
files: "./*/models/**"
- name: Model changes Output
env:
CHANGED_MODEL_FILES: ${{ steps.model-changes.outputs.all_changed_files }}
run: |
for file in "${CHANGED_MODEL_FILES}"; do
echo "$file was changed"
done
- name: Changes in migrations
id: migration-changes
uses: tj-actions/changed-files@v45
with:
path: "core/alembic/versions"
files: "*.py"
- name: Migration changes Output
run: |
CHANGED_MIGRATION_FILES="${{ steps.migration-changes.outputs.all_changed_files }}"
echo "CHANGED_MIGRATION_FILES=${CHANGED_MIGRATION_FILES}" >> $GITHUB_ENV
for file in ${CHANGED_MIGRATION_FILES}; do
echo "$file was changed"
done
- name: Validate Changes
env:
CHANGED_MODEL_FILES: ${{ steps.model-changes.outputs.all_changed_files }}
CHANGED_MIGRATION_FILES: ${{ steps.migration-changes.outputs.all_changed_files }}
run: |
if [[ -n "$CHANGED_MODEL_FILES" && -z "$CHANGED_MIGRATION_FILES" ]]; then
echo "Model Chages detected, but no corresponding migration changes. Create the corresponding migrations."
exit 1
fi
if [[ -n "$CHANGED_MIGRATION_FILES" && -z "$CHANGED_MODEL_FILES" ]]; then
echo "Migration Changes detected, but no corresponding model changes."
exit 1
fi
echo "Changes look valid."
prevent-changes:
runs-on: ubuntu-latest
needs: detect-diffs
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.base_ref }}
- name: prevent-changes-to-existing-migrations
run: |
EXISTING_MIGRATIONS=$(git ls-tree -r HEAD --name-only | grep "core/alembic/versions/.*\.py")
CHANGED_MIGRATION_FILES="${{ env.CHANGED_MIGRATION_FILES }}"
echo $CHANGED_MIGRATION_FILES
for migration in $EXISTING_MIGRATIONS; do
if echo "$CHANGED_MIGRATION_FILES" | grep "$migration"; then
echo "An already existing migration should not be edited!"
exit 1
fi
done