when:
  - event: manual
    branch: main
  - event: push
    branch: main
    path: '.woodpecker/unbound.yaml'

steps:
  - name: unbound
    environment:
      PROJECT_NAME: unbound
      PROJECT_PRETTY_NAME: Unbound
      FEED_REVISION: 1

      CODEBERG_GIT_USERNAME:
        from_secret: codeberg_git_username
      CODEBERG_GIT_PASSWORD:
        from_secret: codeberg_git_password
    image: codeberg.org/mark22k/ci:latest
    pull: true
    commands:
      - GIT_BRANCH="main"
      - GIT_URL="https://github.com/NLnetLabs/unbound-manual.git"
      - . ./scripts/environment.sh
      # Install python tools
      - . ./scripts/install_doc2dash.sh
      - . ./scripts/install_sphinx.sh
      - pipx inject sphinx sphinx-version-warning
      - pipx inject sphinx sphinx-tabs
      - pipx inject sphinx sphinx-copybutton
      - pipx inject sphinx sphinx-notfound-page
      - pipx inject sphinx sphinx-rtd-theme
      - pipx inject sphinx requests
      # Build Unbound docs
      - . ./scripts/download_from_git.sh
      - cd "$BASE_DIRECTORY/unbound-manual"
      - PROJECT_VERSION="unbound-$(git rev-parse --short HEAD)"
      - make html
      - doc2dash build/html
      # Build icons
      # old style
      - convert -resize 16x16 source/resources/favicon.ico[2] Unbound.docset/icon.png
      - convert -resize 32x32 source/resources/favicon.ico[1] Unbound.docset/icon@2x.png
      # new style
      # - magick source/resources/favicon.ico -resize 16x16 Unbound.docset/icon.png
      # - magick source/resources/favicon.ico -resize 32x32 Unbound.docset/icon@2x.png
      # Build tgz
      - tar czf "$BASE_DIRECTORY/Unbound.docset.tgz" Unbound.docset
      - cd "$FEED_DIRECTORY"
      - . ./scripts/create_feed.sh
      - . ./scripts/publish.sh
