Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ jobs:
# - typecheck next (package pretypecheck emits SDK .d.ts; core resolves from src/)
# - lint after typecheck (type-aware eslint reuses those declarations)
# - build last (full emit; SDK JS built once via the root graph, still always-on as a ship gate)
migration-order:
name: Migration Order
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Check out repository code
uses: actions/checkout@v7
with:
fetch-depth: 0

- name: Refresh main branch reference
run: git fetch --no-tags origin main

- name: Check migration ordering
run: bash scripts/check-migration-order.sh

typecheck-and-build:
name: Format, Typecheck, Lint and Build
runs-on: ubuntu-latest
Expand Down Expand Up @@ -268,6 +285,7 @@ jobs:
if: always()
needs:
- detect-changes
- migration-order
- typecheck-and-build
- package-checks
- chart-checks
Expand All @@ -278,14 +296,16 @@ jobs:
- name: Decide whether the needed jobs succeeded or failed
env:
DETECT_CHANGES: ${{ needs.detect-changes.result }}
MIGRATION_ORDER: ${{ needs.migration-order.result }}
TYPECHECK_AND_BUILD: ${{ needs.typecheck-and-build.result }}
PACKAGE_CHECKS: ${{ needs.package-checks.result }}
CHART_CHECKS: ${{ needs.chart-checks.result }}
STORE_TESTS: ${{ needs.store-tests.result }}
run: |
ok() { [ "$1" = success ] || [ "$1" = skipped ]; }
echo "detect-changes=$DETECT_CHANGES typecheck-and-build=$TYPECHECK_AND_BUILD package-checks=$PACKAGE_CHECKS chart-checks=$CHART_CHECKS store-tests=$STORE_TESTS"
echo "detect-changes=$DETECT_CHANGES migration-order=$MIGRATION_ORDER typecheck-and-build=$TYPECHECK_AND_BUILD package-checks=$PACKAGE_CHECKS chart-checks=$CHART_CHECKS store-tests=$STORE_TESTS"
[ "$DETECT_CHANGES" = success ] || exit 1
[ "$MIGRATION_ORDER" = success ] || exit 1
[ "$TYPECHECK_AND_BUILD" = success ] || exit 1
ok "$PACKAGE_CHECKS" || exit 1
ok "$CHART_CHECKS" || exit 1
Expand Down
49 changes: 49 additions & 0 deletions scripts/check-migration-order.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -euo pipefail

main_ref="${MIGRATION_BASE_REF:-origin/main}"
migration_dirs=(
"packages/trueforge/src/db/postgres/migrations"
"packages/trueforge/src/db/sqlite/migrations"
)

latest_main_migration="$(
git ls-tree -r --name-only "$main_ref" -- "${migration_dirs[@]}" \
| awk -F/ '{ print $NF }' \
| sort \
| tail -n 1
)"

added_migrations="$(
git diff --name-only --diff-filter=A "$main_ref...HEAD" -- "${migration_dirs[@]}" \
| awk -F/ '{ print $NF }' \
| sort
)"

if [ -z "$added_migrations" ]; then
echo "No new migrations added relative to $main_ref"
exit 0
fi

invalid_migrations="$(
while IFS= read -r migration; do
[ -n "$migration" ] || continue
if [[ "$migration" < "$latest_main_migration" || "$migration" == "$latest_main_migration" ]]; then
echo "$migration"
fi
done <<< "$added_migrations"
)"

if [ -z "$invalid_migrations" ]; then
echo "All added migrations sort after $main_ref ($latest_main_migration)"
exit 0
fi

echo "Latest migration on $main_ref: $latest_main_migration" >&2
echo "Added migrations must sort strictly after it:" >&2
while IFS= read -r migration; do
[ -n "$migration" ] || continue
echo "- $migration" >&2
done <<< "$invalid_migrations"
exit 1