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

steps:
  - name: vyos
    environment:
      PROJECT_NAME: vyos
      PROJECT_PRETTY_NAME: VyOS
      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="current"
      - GIT_URL="https://github.com/vyos/vyos-documentation.git"
      - . ./scripts/environment.sh
      # Install python tools
      - . ./scripts/install_doc2dash.sh
      - . ./scripts/install_sphinx.sh
      - pipx inject sphinx sphinx-notfound-page
      - pipx inject sphinx myst-parser
      - pipx inject sphinx sphinx-design
      - pipx inject sphinx lxml
      - pipx inject sphinx sphinx-rtd-theme
      # Build VyOS docs
      - . ./scripts/download_from_git.sh
      - cd "$BASE_DIRECTORY/vyos-documentation/docs/"
      - PROJECT_VERSION="current-$(git rev-parse --short HEAD)"
      # Apply patch
      # see https://github.com/sphinx-doc/sphinx/issues/13019,
      #     https://github.com/orgs/sphinx-doc/discussions/13020,
      # and https://vyos.dev/T6777
      - sed -i 's/path = nodes\.reprunicode(path)/path = str(path)/' _ext/vyos.py
      - make html
      - doc2dash _build/html
      # Build icons
      # old style
      - convert -resize 16x16 _static/images/vyos-logo.png VyOS.docset/icon.png
      - convert -resize 32x32 _static/images/vyos-logo.png VyOS.docset/icon@2x.png
      # new style
      # - magick _static/images/vyos-logo.png -resize 16x16 VyOS.docset/icon.png
      # - magick _static/images/vyos-logo.png -resize 32x32 VyOS.docset/icon@2x.png
      # Build tgz
      - tar czf "$BASE_DIRECTORY/VyOS.docset.tgz" VyOS.docset
      - cd "$FEED_DIRECTORY"
      - . ./scripts/create_feed.sh
      - . ./scripts/publish.sh
