# Sphinx build
steps:
  - name: build-html
    image: sphinxdoc/sphinx
    when:
      event: [ push, pull_request, tag ]
    commands:
      - cd ./docs
      - pip3 install --no-cache-dir -r requirements.txt
      - sphinx-build -b html . build -W
  - name: build-pdf
    image: sphinxdoc/sphinx-latexpdf
    when:
      event: [ push, pull_request, tag ]
    commands:
      - cd ./docs
      - pip3 install --no-cache-dir -r requirements.txt
      - sphinx-build -M latexpdf . build -W
  # Based on: https://codeberg.org/gitnex/tea4j-autodeploy/src/branch/main/.woodpecker.yml
  - name: deploy
    image: alpine/git
    when:
      event: [ push, tag ]
      branch: main
    environment:
      GIT_AUTHOR_NAME: arubot
      GIT_AUTHOR_EMAIL: arubot@noreply.codeberg.org
      GIT_COMMIT_MESSAGE: Synchronization with changes to the ARU
      GITEA_HOST: codeberg.org
      GITEA_REPOSITORY: ventureo/pages
      GITEA_BRANCH: main
      GITEA_USERNAME:
        from_secret: gitea_username
      GITEA_TOKEN:
        from_secret: gitea_token
    commands:
      - git clone https://codeberg.org/ventureo/pages
      - cp -r ./docs/build/* pages/
      - cd pages
      - git config user.name  "$${GIT_AUTHOR_NAME}"
      - git config user.email "$${GIT_AUTHOR_EMAIL}"
      - git checkout "$${GITEA_BRANCH}"
      - git add -A
      - >
        if git commit --message "$${GIT_COMMIT_MESSAGE}"; then
          git remote set-url origin "https://$${GITEA_USERNAME}:$${GITEA_TOKEN}@$${GITEA_HOST}/$${GITEA_REPOSITORY}"
          git push origin "$${GITEA_BRANCH}" -f
        fi
