Skip to content

Commit 9cec64e

Browse files
committed
feat(ci): Test migrations in CI
1 parent 1c30e59 commit 9cec64e

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Check migrations and seed
2+
3+
# This job should run whenever a migration is updated
4+
# it should check whether the migration + seed still works as well as
5+
# check whether the pull request message mentions the migration
6+
on:
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
- reopened
12+
paths:
13+
- '**/migrations/*.php'
14+
- '**/test/Seeder/*.php'
15+
16+
jobs:
17+
migration_seed:
18+
name: Check migrations and seed
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Echo
23+
run: echo "This job should only run in if migrations or fixtures are updated"
24+
25+
- name: Checkout base branch
26+
uses: actions/checkout@v4
27+
with:
28+
ref: ${{ github.event.pull_request.base.ref }}
29+
30+
- name: Copy .env
31+
run: cp .env.dist .env
32+
33+
- name: setup docker buildx
34+
uses: docker/setup-buildx-action@v2
35+
36+
- name: build base
37+
run: docker buildx bake --file docker-compose.github.yml --file docker-compose.override.yml --file docker-compose.yml
38+
39+
- name: run base
40+
run: docker compose --file docker-compose.github.yml --file docker-compose.override.yml --file docker-compose.yml up -d --build --quiet-pull
41+
42+
- name: migrate base
43+
run: make migrate
44+
45+
- name: get migration status
46+
run: |
47+
MIGRATION_BASE_DEFAULT=$(docker compose exec -u www-data -it web ./orm migrations:current --no-interaction --object-manager doctrine.entitymanager.orm_default | sed 's/\s-.*//' | sed 's/\s//')
48+
echo "Default is at: $MIGRATION_BASE_DEFAULT"
49+
echo "MIGRATION_BASE_DEFAULT=$MIGRATION_BASE_DEFAULT" >> $GITHUB_ENV
50+
MIGRATION_BASE_REPORT=$(docker compose exec -u www-data -it web ./orm migrations:current --no-interaction --object-manager doctrine.entitymanager.orm_report | sed 's/\s-.*//' | sed 's/\s//')
51+
echo "Report is at: $MIGRATION_BASE_REPORT"
52+
echo "MIGRATION_BASE_REPORT=$MIGRATION_BASE_REPORT" >> $GITHUB_ENV
53+
54+
- name: seed base
55+
run: make seed
56+
57+
- name: cleanup base
58+
run: docker compose --file docker-compose.github.yml --file docker-compose.override.yml --file docker-compose.yml down
59+
60+
- name: Checkout head branch
61+
uses: actions/checkout@v4
62+
63+
- name: Copy .env
64+
run: cp .env.dist .env
65+
66+
- name: build head
67+
run: docker buildx bake --file docker-compose.github.yml --file docker-compose.override.yml --file docker-compose.yml
68+
69+
- name: run head
70+
run: docker compose --file docker-compose.github.yml --file docker-compose.override.yml --file docker-compose.yml up -d --build --quiet-pull
71+
72+
- name: migrate head
73+
run: make migrate
74+
75+
- name: seed head
76+
run: make seed
77+
78+
- name: revert to base migration
79+
run: |
80+
docker compose exec -u www-data -it web ./orm migrations:migrate --no-interaction --object-manager doctrine.entitymanager.orm_default $MIGRATION_BASE_DEFAULT
81+
docker compose exec -u www-data -it web ./orm migrations:migrate --no-interaction --object-manager doctrine.entitymanager.orm_report $MIGRATION_BASE_REPORT
82+
83+
- name: stop
84+
run: docker compose down

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ seed: replenish
6464
@docker compose exec -u www-data -T web ./web application:fixtures:load
6565
@docker compose exec -u www-data web ./web report:generate:full
6666
@make preparemailman
67-
@docker compose exec mailman-web bash -c '(python3 ./manage.py createsuperuser --no-input 2>/dev/null); pkill -HUP uwsgi'
67+
@docker compose exec mailman-web bash -c '(python3 ./manage.py createsuperuser --no-input 2>/dev/null || true)'
6868
@docker compose exec -u mailman mailman-core bash -c '(mailman create news@$$MAILMAN_DOMAIN; mailman create other@$$MAILMAN_DOMAIN; true) 2>/dev/null'
6969
@docker compose exec -u www-data web ./web database:mailman:fetch
7070

@@ -239,4 +239,4 @@ buildpgadmin:
239239

240240
preparemailman:
241241
@docker compose cp ./docker/mailman/settings_local.py mailman-web:/opt/mailman-web/settings_local.py
242-
@docker compose exec mailman-web bash -c "pkill -HUP uwsgi"
242+
@docker compose restart mailman-web

docker-compose.github.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
pgadmin:
3+
build:
4+
cache_from: [ type=gha ]
5+
cache_to: [ "type=gha,mode=max" ]
6+
postgresql:
7+
build:
8+
cache_from: [ type=gha ]
9+
cache_to: [ "type=gha,mode=max" ]
10+
nginx:
11+
build:
12+
cache_from: [ type=gha ]
13+
cache_to: [ "type=gha,mode=max" ]
14+
web:
15+
build:
16+
cache_from: [ type=gha ]
17+
cache_to: [ "type=gha,mode=max" ]

0 commit comments

Comments
 (0)