Skip to content

Update Population Data #1

Update Population Data

Update Population Data #1

name: Update Population Data
on:
workflow_dispatch:
schedule:
# every month at 00:00 UTC
- cron: '0 0 1 * *'
jobs:
update-population-data:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout MHCT db docker repo
uses: actions/checkout@v4
with:
repository: m-h-c-t/mhct-db-docker
path: mhct-db-docker
ref: main
- name: Build MHCT db docker image
run: |
cd mhct-db-docker
docker build -t mhct-db-docker .
- name: Run MHCT db docker container
run: |
docker run -d --name mhct-db -p 3306:3306 mhct-db-docker
# Wait for database to be ready with retry loop
echo "Waiting for database to be ready..."
for i in {1..30}; do
if docker exec mhct-db mysqladmin ping -h localhost -psecret --silent; then
echo "Database is ready!"
break
fi
echo "Attempt $i: Database not ready yet, waiting..."
sleep 2
done
# Final check to ensure database is ready
if ! docker exec mhct-db mysqladmin ping -h localhost -psecret --silent; then
echo "Database failed to become ready after 60 seconds"
exit 1
fi
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Update population data
run: npm run pop
- name: Commit and push if there are changes
run: |
if [ -z "$(git status --porcelain data/pop-csv)" ]; then
echo "No changes in population data."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add data/pop-csv/*
git commit -m "Automated population data update" || exit 0
git push
- name: Cleanup Docker container
if: always()
run: |
docker stop mhct-db || true
docker rm mhct-db || true