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

steps:
  - name: openssl
    environment:
      PROJECT_NAME: openssl
      PROJECT_PRETTY_NAME: openssl
      OPENSSL_VERSION: 3.3
      FEED_REVISION: 1
    image: codeberg.org/mark22k/ci:latest
    pull: true
    commands:
      - GIT_BRANCH="gh-pages"
      - GIT_URL="https://github.com/openssl/openssl-docs.git"
      - . ./scripts/environment.sh
      # Install python tools
      - . ./scripts/install_dashing.sh
      # Build openssl docs
      - . ./scripts/download_from_git.sh
      - cd "$BASE_DIRECTORY/openssl-docs/$OPENSSL_VERSION"
      - PROJECT_VERSION="$OPENSSL_VERSION-$(git rev-parse --short HEAD)"
      - rm 404.html
      - cp -r * "$DOCS_DIRECTORY"
      - |
          cat << EOF > "$DOCS_DIRECTORY/dashing.json"
          {
              "name": "openssl",
              "package": "openssl",
              "index": "index.html",
              "selectors": {
                  "h1": "Guide"
              },
              "allowJS": false
          }
          EOF
      - cd "$FEED_DIRECTORY"
      - . ./scripts/build_dashing.sh
      - sqlite3 "$DOCS_DIRECTORY/openssl.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 _static/images/openssl-logo.png openssl.docset/icon.png
      # - convert -resize 32x32 _static/images/openssl-logo.png openssl.docset/icon@2x.png
      # new style
      # - magick _static/images/openssl-logo.png -resize 16x16 openssl.docset/icon.png
      # - magick _static/images/openssl-logo.png -resize 32x32 openssl.docset/icon@2x.png
      # Build tgz
      - . ./scripts/create_docs_tarball.sh
      - . ./scripts/create_feed.sh
      - . ./scripts/publish.sh
    secrets:
      - codeberg_git_username
      - codeberg_git_password
