Skip to content

Automate migrations #28

Automate migrations

Automate migrations #28

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
with:
fetch-depth: 0
- name: Check for changes in migrations folder
id: check_changes
run: |
git fetch origin main
git fetch origin ${{ github.head_ref || github.ref_name }}
git checkout ${{ github.head_ref || github.ref_name }}
if git diff --quiet origin/main HEAD -- migrations; then
echo "no changes"
echo "CHANGES='false'" >> $GITHUB_ENV
else
echo "changes"
echo "CHANGES='true'" >> $GITHUB_ENV
fi
apply-staging:
needs: check-folder-changes
runs-on: ubuntu-latest
steps:
- name: Checkout repository
if: ${{ env.CHANGES == 'true' }}
uses: actions/checkout@v4
- name: Set up Node.js
if: ${{ env.CHANGES == 'true' }}
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
if: ${{ env.CHANGES == 'true' }}
run: npm install --force
- name: Run TypeScript script
if: ${{ env.CHANGES == 'true' }}
run: npm run migrations:apply-staging