kind: pipeline
name: Build
type: docker

steps:
  - name: "Quality Control"
    image: cortezaproject/corteza-server-builder:latest
    pull: always
    commands:
      - make test.unit

  - name: "Build release (tag)"
    image: cortezaproject/corteza-server-builder:latest
    environment:
      RELEASE_SFTP_KEY: { from_secret: RELEASE_SFTP_KEY }
      RELEASE_SFTP_URI: { from_secret: RELEASE_SFTP_URI }
    commands:
    - make release-clean release -j4 BUILD_OS=linux BUILDARCH=amd64 BUILD_VERSION=${DRONE_TAG}
#    - make release-clean release -j4 BUILD_OS=darwin BUILDARCH=amd64 BUILD_VERSION=${DRONE_TAG}
#    - make release-clean release -j4 BUILD_OS=windows BUILDARCH=amd64 BUILD_VERSION=${DRONE_TAG}
    - make upload
    when:
      event: [ tag ]
      ref:
      - refs/tags/20??.3.*
      - refs/tags/20??.6.*
      - refs/tags/20??.9.*
      - refs/tags/20??.12.*

  - name: "Build unstable release (develop)"
    image: cortezaproject/corteza-server-builder:latest
    environment:
      RELEASE_SFTP_KEY: { from_secret: RELEASE_SFTP_KEY }
      RELEASE_SFTP_URI: { from_secret: RELEASE_SFTP_URI }
    commands:
    - make release-clean release -j4 BUILD_OS=linux BUILDARCH=amd64 BUILD_VERSION=unstable
    - make upload
    when:
      event: [ push ]
      branch: [ develop ]

---

kind: pipeline
name: Integration
type: docker

steps:
  - name: test
    image: cortezaproject/corteza-server-builder:latest
    pull: always
    environment:
      CGO_ENABLED: 0
      GOOS: linux
      GOARCH: amd64
      CI: circleci
      AUTH_OIDC_ENABLED: 0
      AUTH_JWT_SECRET: FBjddkvwQib0d4usifnEGVr1bncuVeD7
      SYSTEM_DB_DSN: corteza:corteza-pwd@tcp(corteza-db:3306)/corteza?collation=utf8mb4_general_ci
      COMPOSE_DB_DSN: corteza:corteza-pwd@tcp(corteza-db:3306)/corteza?collation=utf8mb4_general_ci
      MESSAGING_DB_DSN: corteza:corteza-pwd@tcp(corteza-db:3306)/corteza?collation=utf8mb4_general_ci
      CORREDOR_CLIENT_CERTIFICATES_ENABLED: false
      CORREDOR_ENABLED: false
    commands:
      - wait-for-it.sh -t 60 --strict corteza-db:3306 -- echo "corteza-db is up"
      - make test.coverprofile.all

  - name: coverage
    image: plugins/codecov
    settings:
      token: 628a7104-4ec8-46ef-a3a8-50b0c2507082
      files:
       - .cover.out

services:
  - name: corteza-db
    pull: always
    image: percona:8.0
    ports:
      - 3306
    environment:
      MYSQL_ROOT_PASSWORD: bRxJ37sJ6Qu4
      MYSQL_DATABASE: corteza
      MYSQL_USER: corteza
      MYSQL_PASSWORD: corteza-pwd

trigger:
  event:
    exclude: [ pull_request ]