---
kind: pipeline
name: tests:node_latest
clone:
  disable: true
steps:
  - name: checkout pr
    image: alpine/git
    commands:
      - git clone $DRONE_REMOTE_URL .
      - git checkout $DRONE_SOURCE_BRANCH
      - mv .env.ci .env
  - name: run tests
    image: node:alpine
    commands:
      - yarn
      - yarn test:ci
trigger:
  event:
    - pull_request

---
kind: pipeline
type: docker
name: build:dev

steps:
  - name: build dev
    image: plugins/docker
    depends_on: [clone]
    settings:
      username:
        from_secret: DOCKER_REGISTRY_USER
      password:
        from_secret: DOCKER_REGISTRY_PASSWORD
      repo: registry.odit.services/lfk/backend
      tags:
        - dev
      registry: registry.odit.services
  - name: run full license export
    depends_on: ["clone"]
    image: node:alpine
    commands:
      - yarn
      - yarn licenses:export
  - name: push new licenses file to repo
    depends_on: ["run full license export"]
    image: appleboy/drone-git-push
    settings:
      branch: dev
      commit: true
      commit_message: new license file version [CI SKIP]
      author_email: bot@odit.services
      remote: git@git.odit.services:lfk/backend.git
      ssh_key:
        from_secret: GITLAB_SSHKEY

trigger:
  branch:
    - dev
  event:
    - push

---
kind: pipeline
type: docker
name: build:latest

steps:
  - name: build latest
    image: plugins/docker
    depends_on: [clone]
    settings:
      username:
        from_secret: DOCKER_REGISTRY_USER
      password:
        from_secret: DOCKER_REGISTRY_PASSWORD
      repo: registry.odit.services/lfk/backend
      tags:
        - latest
      registry: registry.odit.services

trigger:
  branch:
    - main
  event:
    - push

---
kind: pipeline
type: docker
name: build:tags

steps:
  - name: build $DRONE_TAG
    image: plugins/docker
    depends_on: [clone]
    settings:
      username:
        from_secret: DOCKER_REGISTRY_USER
      password:
        from_secret: DOCKER_REGISTRY_PASSWORD
      repo: registry.odit.services/lfk/backend
      tags:
        - '${DRONE_TAG}'
      registry: registry.odit.services
  - name: trigger node lib build
    image: idcooldi/drone-webhook
    settings:
      urls: https://ci.odit.services/api/repos/lfk/lfk-client-node/builds?SOURCE_TAG=${DRONE_TAG}
      bearer:
        from_secret: BOT_DRONE_KEY
  - name: trigger js lib build
    image: idcooldi/drone-webhook
    settings:
      urls: https://ci.odit.services/api/repos/lfk/lfk-client-js/builds?SOURCE_TAG=${DRONE_TAG}
      bearer:
        from_secret: BOT_DRONE_KEY
trigger:
  event:
  - tag