name: docs
concurrency:
  group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }}
  cancel-in-progress: true
on:
  push:
    branches:
      - "master"
  pull_request:
    branches:
      - '*' # all branches, including forks

jobs:
  build_docs:
    runs-on: ubuntu-latest
    steps:
      ## Install Braindecode
      - name: Checking Out Repository
        uses: actions/checkout@v4
      # Install python with caching pip dependencies
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
          cache: 'pip' # caching pip dependencies
      # Cache MNE Data
      - name: Create/Restore MNE Data Cache
        id: cache-mne_data
        uses: actions/cache@v4
        with:
          path: ~/mne_data
          key: ${{ runner.os }}-mne-data-v1-${{ github.run_id }}
          restore-keys: |
            ${{ runner.os }}-mne-data-v1-
      # Update pip
      - name: Update pip
        run: pip install --upgrade pip
      # Install with MOABB and docs dependencies
      - name: Install with doc dependencies
        run: pip install -e .[moabb,docs,bids]
      # Show Braindecode Version
      - run: python -c "import braindecode; print(braindecode.__version__)"
      - name: Create Docs
        run: |
          cd docs
          make html
      - name: Upload HTML Docs as Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: HTML-Docs
          path: ./docs/_build/

      - name: Deploy to Github Pages if on Master
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
          external_repository: braindecode/braindecode.github.io
          destination_dir: dev
          publish_branch: master
          publish_dir: ./docs/_build/html
          cname: braindecode.org
