Skip to content

Pull Data and Build Dashboard #287

Pull Data and Build Dashboard

Pull Data and Build Dashboard #287

Workflow file for this run

name: Pull Data and Build Dashboard
on:
push:
branches: ["main"]
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
permissions:
contents: write
jobs:
update-and-deploy:
runs-on: ubuntu-latest
env:
DB_HOST: ${{ secrets.DB_HOST }}
DB_USER: ${{ secrets.DB_USER }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
steps:
- name: Get GitHub action IP
id: ip
uses: haythem/public-ip@v1.3
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Setting environment variables
run: |
echo "AWS_DEFAULT_REGION=us-east-1" >> $GITHUB_ENV
- name: Add GitHub Actions IP to Security group
run: |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 3306 --cidr ${{ steps.ip.outputs.ipv4 }}/32 > /dev/null
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libmariadb-dev
pip install -r ./.scripts/requirements.txt
pip install polars plotly pandas
- name: Pull data from database
run: |
python3 .scripts/pull_data.py
- name: Commit data changes
run: |
echo "Updated at $(date)" >> updated_at.txt
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "Updated data at $(date)" || echo "No data changes"
git push || echo "No changes to push"
- name: Generate dashboard
run: |
cd .scripts
python3 modified_dashboard.py
- name: Prepare deployment directory
run: |
mkdir -p public
mv .scripts/dashboard.html public/index.html
mv .scripts/plots/ public/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
force_orphan: true
- name: Remove GitHub Actions IP from security group
if: always()
run: |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 3306 --cidr ${{ steps.ip.outputs.ipv4 }}/32
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ env.AWS_DEFAULT_REGION }}