Pull Data and Deploy Report #114
This file contains hidden or 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: Pull Data | |
| on: | |
| push: | |
| branches: ["main"] | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 0 * * *" # Every day at midnight UTC | |
| permissions: | |
| contents: write | |
| jobs: | |
| update-db: | |
| 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 MariaDB Connector/C dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libmariadb-dev | |
| - name: Install requirmenets | |
| run: | | |
| pip install -r ./.scripts/requirements.txt | |
| - uses: actions/checkout@v4 | |
| name: Pull data from database and push to repository | |
| - run: | | |
| python3 .scripts/pull_data.py | |
| 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 at $(date)" | |
| git push | |
| - 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 }} |