name: Update Exchange Rates

on:
  schedule:
    - cron: "23 7 * * 4"
  workflow_dispatch:

jobs:
  generate-currency-rates:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install requests

      - name: Run generate_currency_rates.py
        run: |
          python scripts/generate_exchange_rates.py -o static/currency_rates.json
        env:
          EXCHANGE_RATE_API_KEY: ${{ secrets.EXCHANGE_RATE_API_KEY }}

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v7
        with:
          commit-message: "feat: update currency rates"
          branch: feat/update-currency-rates
          signoff: true
          title: "feat: update currency rates"
          body: "This PR updates the currency rates."
          base: main
