#clone:
#  git:
#    image: woodpeckerci/plugin-git
#    settings:
#      recursive: true
#      submodule_update_remote: true

variables:
  - &install_pnpm "corepack enable pnpm"

steps:
  prepare_repo:
    image: alpine:3
    commands:
      - apk add git
      - git submodule init
      - git submodule update
    when:
      - event: pull_request

  prettier_markdown_check:
    image: tmknom/prettier:3.2.5
    commands:
      - prettier -c . "!dist" "!lemmy-docs" "!lemmy-translations" "!joinlemmy-translations" "!lemmy-js-client" "!lemmy-stats-crawler" "!src/shared/instance_stats.ts" "!src/shared/donation_stats.ts" "!pnpm-lock.yaml"
    when:
      - event: pull_request

  install:
    image: node:alpine
    commands:
      - *install_pnpm
      - pnpm i
    when:
      - event: pull_request

  lint:
    image: node:alpine
    commands:
      - *install_pnpm
      - pnpm lint
    when:
      - event: pull_request

  build_dev:
    image: node:alpine
    commands:
      - *install_pnpm
      - pnpm prebuild:dev
      - pnpm build:dev
    when:
      - event: pull_request

  nightly_instance_crawl:
    image: node:alpine
    commands:
      # libpq and openssl can probably be removed after lemmy dep is upgraded to 0.16.4+
      - apk add cargo pkgconfig openssl openssl-dev libpq libpq-dev
      - *install_pnpm
      - pnpm crawl
    when:
      - event: cron

  nightly_build_and_push_to_docker_hub:
    image: woodpeckerci/plugin-docker-buildx
    settings:
      dockerfile: Dockerfile
      repo: dessalines/joinlemmy-site
      tag: latest
      username:
        from_secret: docker_username
      password:
        from_secret: docker_password
    when:
      - event: cron

  release_instance_crawl:
    image: node:alpine
    commands:
      # libpq and openssl can probably be removed after lemmy dep is upgraded to 0.16.4+
      - apk add cargo pkgconfig openssl openssl-dev libpq libpq-dev
      - *install_pnpm
      - pnpm crawl
    when:
      - event: tag

  release_build_and_push_to_docker_hub:
    image: woodpeckerci/plugin-docker-buildx
    settings:
      dockerfile: Dockerfile
      repo: dessalines/joinlemmy-site
      tag: latest
      username:
        from_secret: docker_username
      password:
        from_secret: docker_password
    when:
      - event: tag

  notify_on_failure:
    image: alpine:3
    commands:
      - apk add curl
      - "curl -d'joinlemmy-site build failed: ${DRONE_BUILD_LINK}' ntfy.sh/lemmy_drone_ci"
    when:
      - event: pull_request
        status: failure

  notify_on_tag_deploy:
    image: alpine:3
    commands:
      - apk add curl
      - "curl -d'joinlemmy-site:${DRONE_TAG} deployed' ntfy.sh/lemmy_drone_ci"
    when:
      - event: tag