Skip to content

Commit

Permalink
fix: add gh action + pre commit hook to detect duplicate migration files
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Feb 28, 2025
1 parent d45cbe9 commit 4ef0ccb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 49 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/go_test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Go
name: Go Tests and goose migration check
on:
push:
branches: ["main"]
branches: ["*"]
pull_request:
branches: ["main"]
jobs:
Expand All @@ -19,3 +19,14 @@ jobs:
run: |
cd backend
go test -v ./...
- name: Check duplicate migration files
run: |
DUPLICATE_MIGRATIONS=$(ls -1 migrations | grep '.*\.sql' | cut -c1-5 | sort | uniq -d)
if [ -z "$DUPLICATE_MIGRATIONS" ]; then
exit 0
else
echo "🚨 Duplicate migration files found 🚨"
echo "Migration number: $DUPLICATE_MIGRATIONS is a duplicate\n and needs to be renamed"
exit 1
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jar
/provider-middleware/providers.db
/backend/server
/provider-middleware/middleware
/provider-middleware/bin
/backend/bin
/bin/*
/tmp
/csvs/zims/*.zim
2 changes: 1 addition & 1 deletion config/kratos/kratos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ selfservice:
- hook: show_verification_ui

log:
level: trace
level: info
format: json
leak_sensitive_values: true

Expand Down
40 changes: 3 additions & 37 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ services:
- KRATOS_ADMIN_URL=http://kratos:4434
- KRATOS_PUBLIC_URL=http://kratos:4433
- MIDDLEWARE_CRON_SCHEDULE=0 22 * * *
- KETO_ADMIN_URL=http://keto:4466
- ORY_TOKEN=eyJvZmZzZXQiOiItMjUwIiwidmo8iV*@
- NATS_URL=nats:4222
- NATS_USER=unlocked
Expand Down Expand Up @@ -144,22 +143,6 @@ services:
- ./:/app
depends_on: [provider-service]

keto-migrate:
image: oryd/keto:v0.12.0-alpha.0
links:
- postgres:postgres
volumes:
- config:/home/ory
environment:
- LOG_LEVEL=debug
- DSN=postgres://keto:ChangeMe!@postgres:5432/accesscontroldb?sslmode=prefer&max_conns=20&max_idle_conns=4
command: ["migrate", "up", "-y"]
depends_on:
postgres:
condition: service_healthy
networks:
- intranet

nats:
image: nats:latest
networks:
Expand All @@ -173,24 +156,6 @@ services:
- config:/config
- nats_data:/data

keto:
image: oryd/keto:v0.11.1-alpha.0
links:
- postgres:postgres
volumes:
- type: bind
source: config
target: /home/ory
ports:
- "4466:4466"
- "4467:4467"
depends_on:
- keto-migrate
environment:
- DSN=postgres://keto:ChangeMe!@postgres:5432/accesscontroldb?sslmode=prefer&max_conns=20&max_idle_conns=4
networks:
- intranet

kratos-migrate:
image: oryd/kratos:v1.1.0
environment:
Expand All @@ -215,7 +180,7 @@ services:
- "4434:4434" # admin
environment:
- DSN=postgres://kratos:ChangeMe!@postgres:5432/kratos?sslmode=prefer&max_conns=20&max_idle_conns=4
- LOG_LEVEL=trace
- LOG_LEVEL=info
command: serve -c /etc/config/kratos/kratos.yml --dev --watch-courier
volumes:
- type: bind
Expand All @@ -236,7 +201,7 @@ services:
source: ./config/hydra
target: /etc/config/hydra
environment:
- LOG_LEVEL=debug
- LOG_LEVEL=info
- OAUTH2_EXPOSE_INTERNAL_ERRORS=1
- SERVE_PUBLIC_CORS_ENABLED=true
- SERVE_PUBLIC_CORS_ALLOWED_METHODS=POST,GET,PUT,DELETE
Expand All @@ -253,6 +218,7 @@ services:
image: oryd/hydra:v2.2.0
environment:
- DSN=postgres://hydra:ChangeMe!@postgres:5432/hydra?sslmode=prefer&max_conns=20&max_idle_conns=4
- LOG_LEVEL=info
command: migrate -c /etc/config/hydra/hydra.yml sql -e --yes
volumes:
- type: bind
Expand Down
24 changes: 15 additions & 9 deletions frontend/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
git diff --cached --name-only --diff-filter=ACMRTUXB >frontend/.husky/staged-files
echo "🔎 checking frontend........."
cd frontend
echo "🎀 running prettier 🎀 󰎙 ..."
FRONTEND_FILES=$(cat .husky/staged-files | grep '^frontend/.*\.\(css\|ts\|json\|html\|js\|tsx\)$' | sed 's/^frontend\///')

if [ -z "$FRONTEND_FILES" ]; then
echo "No files to check"
echo "No frontend files to check"
else
echo "🎀 running prettier 🎀 󰎙 ..."
npx prettier -w $FRONTEND_FILES
echo "running front-end linters 󰎙 ..."
yarn lint-staged
yarn build
git add $FRONTEND_FILES
echo "running front-end linters 󰎙 ..."
yarn lint-staged
yarn build
git add $FRONTEND_FILES
fi

echo " 🔎 checking backend ..............."
Expand All @@ -26,5 +24,13 @@ else
go fmt ./...
echo "Running Go tests  .."
go test ./...
echo "🎉 All checks passed! 🎉"

DUPLICATE_MIGRATIONS=$(ls -1 migrations | grep '.*\.sql' | cut -c1-5 | sort | uniq -d)
if [ -z "$DUPLICATE_MIGRATIONS" ]; then
echo "🎉 All checks passed! 🎉"
else
echo "🚨 Duplicate migration files found 🚨"
echo "Migration number: $DUPLICATE_MIGRATIONS is a duplicate\n and needs to be renamed"
exit 1
fi
fi

0 comments on commit 4ef0ccb

Please sign in to comment.