---
kind: pipeline
type: docker
name: testing

steps:
- name: build
  image: docker:dind
  environment:
    COMPOSE_PROJECT_NAME: ${DRONE_REPO_OWNER,,}-${DRONE_REPO_NAME,,}-${DRONE_COMMIT_BRANCH//\//-}
    NUXT_APP_BASE_URL: /${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/${DRONE_COMMIT_BRANCH}/
    SERVICE_3000_CHECK_HTTP: /${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/${DRONE_COMMIT_BRANCH}/
    SERVICE_3000_TAGS: urlprefix-testing.asycn.io/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/${DRONE_COMMIT_BRANCH}/*
  commands:
  - docker build --target static --output /drone/src/.output/public -f docker/Dockerfile .
  - docker compose -f docker/docker-compose.yml -f docker/docker-compose.labels.yml up --build -d
  volumes:
  - name: dockersock
    path: /var/run/docker.sock

- name: publish
  image: hypervtechnics/drone-sftp
  settings:
    username:
      from_secret: ssh_username
    password:
      from_secret: ssh_password
    host: open.us.org
    port: 22
    target: /dav/www/
    source: ./.output/public/
    overwrite: true
    verbose: true
  when:
    branch:
    - main
    event:
    - push

- name: notify
  image: appleboy/drone-telegram
  when:
    status:
    - success
    - failure
  settings:
    token:
      from_secret: telegram_token
    to:
      from_secret: telegram_chat_id_atr
    format: markdown
    message: >
      {{#success build.status}}
      ✅ `{{commit.email}}` a mis à jour la branche `{{commit.branch}}` sur le repo `{{repo.name}}`:
      ```
      {{commit.message}}
      ```
      🌐 https://testing.asycn.io/${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}/{{commit.branch}}/
      {{else}}
      ❌ Le build #{{build.number}} du repo `{{repo.name}}` est un gros fail...
      📝 Commit de {{commit.email}} sur la branche `{{commit.branch}}`:
      ```
      {{commit.message}}
      ```
      🌐 {{ build.link }}
      {{/success}}

volumes:
- name: dockersock
  host:
    path: /var/run/docker.sock
