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

steps:
  - name: i2pd
    environment:
      PROJECT_NAME: i2pd
      PROJECT_PRETTY_NAME: i2pd
      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="master"
      - GIT_URL="https://github.com/PurpleI2P/i2pd_docs_en.git"
      - . ./scripts/environment.sh
      # Install python tools
      - . ./scripts/install_dashing.sh
      - . ./scripts/install_mkdocs.sh
      # Build i2pd docs
      - . ./scripts/download_from_git.sh
      - . ./scripts/prepare_docs_directory.sh
      - cd "$BASE_DIRECTORY/i2pd_docs_en/"
      - PROJECT_VERSION="master-$(git rev-parse --short HEAD)"
      - mkdocs build
      - rm site/404.html
      - cp -r "site/"* "$DOCS_DIRECTORY"
      - |
          cat << EOF > "$DOCS_DIRECTORY/dashing.json"
          {
              "name": "i2pd",
              "package": "i2pd",
              "index": "index.html",
              "selectors": {
                  "h1": "Guide",
                  "h2": "Section"
              },
              "allowJS": false
          }
          EOF
      - cd "$FEED_DIRECTORY"
      - . ./scripts/build_dashing.sh
      - sqlite3 "$DOCS_DIRECTORY/i2pd.docset/Contents/Resources/docSet.dsidx" "UPDATE searchIndex SET name = SUBSTR(name, 1, LENGTH(name) - 1) WHERE name LIKE '%¶';"
      # Build icons
      # old style
      - convert -resize 16x16 "$DOCS_DIRECTORY/img/logo.png" "$DOCS_DIRECTORY/i2pd.docset/icon.png"
      - convert -resize 32x32 "$DOCS_DIRECTORY/img/logo.png" "$DOCS_DIRECTORY/i2pd.docset/icon@2x.png"
      # new style
      # - magick _static/images/i2pd-logo.png -resize 16x16 i2pd.docset/icon.png
      # - magick _static/images/i2pd-logo.png -resize 32x32 i2pd.docset/icon@2x.png
      # Build tgz
      - . ./scripts/create_docs_tarball.sh
      - . ./scripts/create_feed.sh
      - . ./scripts/publish.sh
