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

steps:
  - name: fastd
    environment:
      PROJECT_NAME: fastd
      PROJECT_PRETTY_NAME: fastd
      PROJECT_VERSION: 23
      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="v$PROJECT_VERSION"
      - GIT_URL="https://github.com/neocturne/fastd.git"
      - . ./scripts/environment.sh
      - . ./scripts/install_sphinx.sh
      - . ./scripts/install_doc2dash.sh
      - pipx inject sphinx sphinx-rtd-theme
      # Build fastd docs
      - . ./scripts/download_from_git.sh
      - cd "$BASE_DIRECTORY/fastd/doc/"
      - make html
      - doc2dash build/html
      - tar czf "$BASE_DIRECTORY/fastd.docset.tgz" fastd.docset
      - |
          cat <<EOF > "$BASE_DIRECTORY/fastd.xml"
          <entry>
            <name>fastd</name>
            <version>v$PROJECT_VERSION</version>
            <url>https://mark22k.codeberg.page/zeal-docs/@fastd/fastd.docset.tgz</url>
          </entry>
          EOF
      - cd "$FEED_DIRECTORY"
      - . ./scripts/create_feed.sh
      - . ./scripts/publish.sh
