Skip to content

Automate migrations #11

Automate migrations

Automate migrations #11

name: Apply staging migrations on PR when there are changes in the migrations folder
on:
pull_request:
types: [opened, synchronize]
jobs:
check-folder-changes:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Fetch latest changes
run: git fetch origin main
- name: Check for changes in migrations folder
id: check_changes
run: |
if git show-ref --verify --quiet refs/remotes/origin/main; then
if git merge-base --is-ancestor origin/main HEAD; then
if git diff --name-only origin/main...HEAD | grep -q '^migrations/'; then
echo "changes=true" >> $GITHUB_ENV
else
echo "changes=false" >> $GITHUB_ENV
fi
else
echo "changes=false" >> $GITHUB_ENV
fi
else
echo "changes=false" >> $GITHUB_ENV
fi
apply-staging:
needs: check-folder-changes
if: needs.check-folder-changes.outputs.changes == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm install
- name: Run TypeScript script
run: npm run migrations:apply-staging