name: build-and-deploy-website
run-name: build and deploy website
on:
  workflow_dispatch:
  schedule:
    # At 01:30 on Saturday:
    - cron: '30 1 * * 6'
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checking out repository code
        uses: actions/checkout@v3
        with:
          token: ${{ secrets.HOW_BAD_IS_MY_BATCH_ACCESS_TOKEN }}
      - name: Configuring git
        run: |
          git config --global user.email "Knoll_Frank@web.de"
          git config --global user.name "FK"
      - name: Installing dependencies
        uses: conda-incubator/setup-miniconda@v2
        with:
          activate-environment: howbadismybatch-venv
          environment-file: environment.yml
      - name: Installing Google Chrome
        shell: bash -el {0}
        run: |
          wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
          sudo dpkg -i google-chrome-stable_current_amd64.deb
          sudo apt install google-chrome-stable
          pip install selenium webdriver-manager
          pip install pycountry
          pip install python-decouple
      - name: Installing ipython kernel
        shell: bash -el {0}
        run: |
          ipython kernel install --user --name=howbadismybatch-venv-kernel
      - name: Executing HowBadIsMyBatch.ipynb
        shell: bash -el {0}
        run: |
          cd src
          jupyter nbconvert --to script HowBadIsMyBatch.ipynb
          python ./HowBadIsMyBatch.py          
          # jupyter nbconvert --ExecutePreprocessor.kernel_name="howbadismybatch-venv-kernel" --to notebook --allow-errors --execute HowBadIsMyBatch.ipynb
          # jupyter nbconvert --to html HowBadIsMyBatch.nbconvert.ipynb
          git add -A
          git commit -m "updating data for batch codes"
      - name: Executing Intensivstationen.ipynb
        shell: bash -el {0}
        run: |
          cd src/intensivstationen
          DATAWRAPPER_API_TOKEN=${{ secrets.DATAWRAPPER_API_TOKEN }} jupyter nbconvert --ExecutePreprocessor.kernel_name="howbadismybatch-venv-kernel" --to notebook --allow-errors --execute Intensivstationen.ipynb
          jupyter nbconvert --to html Intensivstationen.nbconvert.ipynb
          git add -A
          git commit -m "updating data for Intensivstationen"
      - name: Pushing changes to GitHub Pages
        shell: bash -el {0}
        run: |
          git push
