-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new workflow to check files in the migrations folder
- Loading branch information
1 parent
2a9a783
commit 0a9f0d7
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Validate Migration Files | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '**' # This triggers on PRs to any branch | ||
|
||
jobs: | ||
validate-migrations: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout current branch | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # Fetch all branches to get the base branch | ||
|
||
- name: Set up environment | ||
run: | | ||
# Create a directory for the migration files | ||
mkdir -p current_migrations | ||
mkdir -p base_migrations | ||
- name: Fetch base branch | ||
run: | | ||
# Use the base branch name from the pr in github | ||
BASE_BRANCH=${{ github.event.pull_request.base.ref }} | ||
echo "Base branch is: $BASE_BRANCH" | ||
# Fetch the base branch | ||
git fetch origin $BASE_BRANCH:refs/remotes/origin/$BASE_BRANCH | ||
git checkout $BASE_BRANCH | ||
cp -R db/migration/* base_migrations/ | ||
- name: Check current migration timestamps | ||
run: | | ||
# Switch back to the current branch | ||
git checkout ${{ github.head_ref }} | ||
cp -R db/migration/* current_migrations/ | ||
# Validate timestamps | ||
echo "Validating migration timestamps..." | ||
# Extract and sort timestamps | ||
current_timestamps=$(ls current_migrations | sed 's/^\([0-9]*\).*/\1/' | sort -n) | ||
base_timestamps=$(ls base_migrations | sed 's/^\([0-9]*\).*/\1/' | sort -n) | ||
# Check for duplicate timestamps first | ||
if echo "$current_timestamps" | uniq -d | grep -q .; then | ||
echo "Error: Duplicate timestamps found in the current branch migration files!" | ||
exit 1 | ||
fi | ||
# Check for timestamps in the current branch that are before the latest base branch timestamp | ||
latest_base_timestamp=$(echo "$base_timestamps" | tail -n 1) | ||
echo "Latest timestamp in base branch: $latest_base_timestamp" | ||
for timestamp in $current_timestamps; do | ||
if [ "$timestamp" -lt "$latest_base_timestamp" ]; then | ||
echo "Error: Migration timestamp $timestamp is earlier than the latest base timestamp $latest_base_timestamp!" | ||
exit 1 | ||
fi | ||
done | ||
echo "All migration timestamps are valid." |