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

steps:
  - name: sequel
    environment:
      PROJECT_NAME: sequel
      PROJECT_PRETTY_NAME: sequel
      PROJECT_VERSION: 5.85.0
      FEED_REVISION: 1
    image: codeberg.org/mark22k/ci:latest
    pull: true
    commands:
      - GIT_BRANCH="$PROJECT_VERSION"
      - GIT_URL="https://github.com/jeremyevans/sequel.git"
      - . ./scripts/environment.sh
      # Install python tools
      - . ./scripts/install_dashing.sh
      # Build sequel docs
      - . ./scripts/download_from_git.sh
      - . ./scripts/prepare_docs_directory.sh
      - cd "$BASE_DIRECTORY/sequel/"
      - rake rdoc
      - cd rdoc
      - cp -r "site/"* "$DOCS_DIRECTORY"
      - |
          cat << EOF > "$DOCS_DIRECTORY/dashing.json"
          {
              "name": "Sequel",
              "package": "Sequel",
              "index": "index.html",
              "selectors": {
                  "h1": "Guide",
                  "h2": "Section"
              },
              "allowJS": false
          }
          EOF
      - cd "$FEED_DIRECTORY"
      - . ./scripts/build_dashing.sh
      - sqlite3 "$DOCS_DIRECTORY/sequel.docset/Contents/Resources/docSet.dsidx" "UPDATE searchIndex SET name = SUBSTR(name, 1, LENGTH(name) - 3) WHERE name LIKE '%¶ ↑';"
      # Build icons
      # old style
      - convert -resize 16x16 "$DOCS_DIRECTORY/img/logo.png" "$DOCS_DIRECTORY/sequel.docset/icon.png"
      - convert -resize 32x32 "$DOCS_DIRECTORY/img/logo.png" "$DOCS_DIRECTORY/sequel.docset/icon@2x.png"
      # new style
      # - magick _static/images/sequel-logo.png -resize 16x16 sequel.docset/icon.png
      # - magick _static/images/sequel-logo.png -resize 32x32 sequel.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
