---
kind: pipeline
type: docker
name: build:dev
clone:
  disable: true

steps:
  - name: clone
    image: alpine/git
    commands:
      - git clone $DRONE_REMOTE_URL .
      - git checkout dev
  - 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/document-server
      tags:
        - dev
      registry: registry.odit.services
  - name: run changelog export
    depends_on: ["clone"]
    image: node:latest
    commands:
      - npx auto-changelog --commit-limit false -p -u --hide-credit
  - name: push new changelog to repo
    depends_on: ["run changelog export"]
    image: appleboy/drone-git-push
    settings:
      branch: dev
      commit: true
      commit_message: 🧾New changelog file version [CI SKIP] [skip ci]
      author_email: bot@odit.services
      remote: git@git.odit.services:lfk/document-server.git
      ssh_key:
        from_secret: GITLAB_SSHKEY
  - name: run full license export
    depends_on: ["clone"]
    image: node:14.15.1-alpine3.12
    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] [skip ci]
      author_email: bot@odit.services
      remote: git@git.odit.services:lfk/document-server.git
      skip_verify: true
      ssh_key:
        from_secret: GITLAB_SSHKEY

trigger:
  branch:
    - dev
  event:
    - push

---
kind: pipeline
type: docker
name: build:latest
clone:
  disable: true

steps:
  - name: clone
    image: alpine/git
    commands:
      - git clone $DRONE_REMOTE_URL .
      - git checkout dev
      - git merge main
      - git checkout main
  - name: build latest
    depends_on: ["clone"]
    image: plugins/docker
    settings:
      username:
        from_secret: DOCKER_REGISTRY_USER
      password:
        from_secret: DOCKER_REGISTRY_PASSWORD
      repo: registry.odit.services/lfk/document-server
      tags:
        - latest
      registry: registry.odit.services
  - name: push merge to repo
    depends_on: ["clone"]
    image: appleboy/drone-git-push
    settings:
      branch: dev
      commit: false
      remote: git@git.odit.services:lfk/document-server.git
      ssh_key:
        from_secret: GITLAB_SSHKEY

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/document-server
      tags:
        - '${DRONE_TAG}'
      registry: registry.odit.services
trigger:
  event:
  - tag