env:
  SUBFOLDER: Documentation

on:
  push:
    paths:
      - $SUBFOLDER/**

jobs:
  publish-docs:
    defaults:
      run:
        working-directory: ${{env.SUBFOLDER}}
    runs-on: ubuntu-latest
    permissions:
      contents: read
      deployments: write
    name: Publish to Cloudflare Pages
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - uses: actions/setup-python@v4
        with:
          python-version: 3.x

      - run: echo "CACHE_ID=$(date --utc '+%V')" >> $GITHUB_ENV

      - uses: actions/cache@v3
        with:
          key: mkdocs-material-${{ env.CACHE_ID }}
          path: .cache
          restore-keys: |
            mkdocs-material-

      - run: pip install -r requirements.txt

      - name: Build
        run: mkdocs build --site-dir public

      - name: Upload
        env:
          PROJECT_NAME: velnet-docs
          CLOUDFLARE_ACCOUNT_ID: 8077b5b1f8e2ade41874cbaa3f883069
          CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
        run: npx wrangler@3.1.1 pages deploy public --project-name="${{env.PROJECT_NAME}}" --branch="${{env.GITHUB_REF_NAME}}"
