feat(ci): check that existing flyway files are not modified #2
Workflow file for this run
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
name: Flyway Migration Check | |
on: | |
pull_request: | |
branches: [ main ] | |
paths: | |
- 'backend/src/main/resources/db/migration/**' | |
jobs: | |
check-migrations: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'adopt' | |
- name: Install Flyway CLI | |
run: | | |
wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/8.5.13/flyway-commandline-8.5.13-linux-x64.tar.gz | tar xvz | |
sudo ln -s `pwd`/flyway-8.5.13/flyway /usr/local/bin | |
- name: Check for modified migrations | |
run: | | |
git diff --name-only origin/main...HEAD -- backend/src/main/resources/db/migration/ > changed_files.txt | |
if [ -s changed_files.txt ]; then | |
echo "The following migration files have been modified:" | |
cat changed_files.txt | |
echo "Error: Modifying existing migrations is not allowed." | |
exit 1 | |
else | |
echo "No existing migrations have been modified." | |
fi | |
- name: Validate new migrations | |
run: flyway validate -locations=filesystem:backend/src/main/resources/db/migration | |
- name: Run Flyway info | |
run: flyway info -locations=filesystem:backend/src/main/resources/db/migration |