Skip to content

Commit

Permalink
Exclude migration tests from migration timestamp/ordering check (#22496)
Browse files Browse the repository at this point in the history
This fix applies to cases (e.g.
00ec402) where order of files being
added is e.g.:

1. Migration A
2. Migration B
3. Test for migration A

This also reorders workflow steps so the ones that don't require setting
up Go + compiling happen first, so if we have a migration issue it gets
reported sooner.

# Checklist for submitter

- [x] Manual QA for all new/changed functionality
  • Loading branch information
iansltx authored Sep 30, 2024
1 parent 0bd0dd8 commit 59160c2
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions .github/workflows/test-db-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,6 @@ jobs:
with:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version-file: 'go.mod'

- name: Start Infra Dependencies
# Use & to background this
run: docker compose up -d mysql_test &

- name: Wait for mysql
run: |
echo "waiting for mysql..."
until docker compose exec -T mysql_test sh -c "mysql -uroot -p\"\${MYSQL_ROOT_PASSWORD}\" -e \"SELECT 1=1\" fleet" &> /dev/null; do
echo "."
sleep 1
done
echo "mysql is ready"
- name: Verify test schema changes
run: |
make dump-test-schema
if [[ $(git diff server/datastore/mysql/schema.sql) ]]; then
echo "❌ fail: uncommited changes in schema.sql"
echo "please run `make dump-test-schema` and commit the changes"
exit 1
fi
# TODO: This doesn't cover all scenarios since other PRs might
# be merged into `main` after this check has passed.
#
Expand All @@ -84,8 +57,8 @@ jobs:
base_ref=$(git tag --list "fleet-v*" --sort=-creatordate | head -n 1)
fi
all_migrations=($(ls server/datastore/mysql/migrations/tables/20*_*.go | sort -r))
new_migrations=($(git diff --find-renames --name-only --diff-filter=A $base_ref -- server/datastore/mysql/migrations/tables/20\*_\*.go | sort -r))
all_migrations=($(ls server/datastore/mysql/migrations/tables/20*_*.go | sort -r | grep -v '_test.go'))
new_migrations=($(git diff --find-renames --name-only --diff-filter=A $base_ref -- server/datastore/mysql/migrations/tables/20\*_\*.go ':(exclude,glob)server/datastore/mysql/migrations/tables/20*_*_test.go' | sort -r))
index=0
for migration in "${new_migrations[@]}"; do
Expand All @@ -110,3 +83,31 @@ jobs:
echo "Ref: https://github.com/fleetdm/fleet/blob/main/handbook/engineering/scaling-fleet.md#foreign-keys-and-locking"
exit 1
fi
- name: Install Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version-file: 'go.mod'

- name: Start Infra Dependencies
# Use & to background this
run: docker compose up -d mysql_test &

- name: Wait for mysql
run: |
echo "waiting for mysql..."
until docker compose exec -T mysql_test sh -c "mysql -uroot -p\"\${MYSQL_ROOT_PASSWORD}\" -e \"SELECT 1=1\" fleet" &> /dev/null; do
echo "."
sleep 1
done
echo "mysql is ready"
- name: Verify test schema changes
run: |
make dump-test-schema
if [[ $(git diff server/datastore/mysql/schema.sql) ]]; then
echo "❌ fail: uncommited changes in schema.sql"
echo "please run `make dump-test-schema` and commit the changes"
exit 1
fi

0 comments on commit 59160c2

Please sign in to comment.