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

steps:
  - name: frr
    environment:
      PROJECT_NAME: frr
      PROJECT_PRETTY_NAME: FRR
      PROJECT_VERSION: 10.2
      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="frr-$PROJECT_VERSION"
      - GIT_URL="https://github.com/FRRouting/frr.git"
      - . ./scripts/environment.sh
      # Install libyang2
      - wget "https://ci1.netdef.org/artifact/LIBYANG-LIBYANG21/shared/build-13/Debian-12-x86_64-Packages/libyang2_2.1.128-2%7Edeb12u2_amd64.deb"
      - wget "https://ci1.netdef.org/artifact/LIBYANG-LIBYANG21/shared/build-13/Debian-12-x86_64-Packages/libyang2-dev_2.1.128-2%7Edeb12u2_amd64.deb"
      - apt-get install --yes ./libyang2_2.1.128-2~deb12u2_amd64.deb ./libyang2-dev_2.1.128-2~deb12u2_amd64.deb
      # Install python tools
      - . ./scripts/install_doc2dash.sh
      # Build frr docs
      - . ./scripts/download_from_git.sh
      - cd "$BASE_DIRECTORY/frr/"
      - ./bootstrap.sh
      - ./configure
      - make html
      - doc2dash doc/user/_build/html/
      # Build icons
      # old style
      - convert -resize 16x16 doc/user/_build/html/_static/frr-icon.svg FRR.docset/icon.png
      - convert -resize 32x32 doc/user/_build/html/_static/frr-icon.svg FRR.docset/icon@2x.png
      # new style
      # - magick doc/user/_build/html/_static/frr-icon.sv-resize 16x16 FRR.docset/icon.png
      # - magick doc/user/_build/html/_static/frr-icon.sv -resize 32x32 FRR.docset/icon@2x.png
      # Build tgz
      - tar czf "$BASE_DIRECTORY/FRR.docset.tgz" FRR.docset
      - cd "$FEED_DIRECTORY"
      - . ./scripts/create_feed.sh
      - . ./scripts/publish.sh
