workspace:
  base: /srv/app
  path: src/git.mowie.cc/konrad/Library

clone:
  git:
    image: plugins/git
    depth: 50
    tags: true

pipeline:
  build-backend:
    image: webhippie/golang:edge
    pull: true
    group: build
    environment:
      TAGS: bindata sqlite
      GOPATH: /srv/app
    commands:
      - make clean
      - make lint
      - make fmt-check
      - make build
    when:
      event: [ push, tag, pull_request ]

  build-frontend:
    image: webhippie/nodejs:current
    pull: true
    group: build
    commands:
      - cd frontend/
      - rm siteconfig.json
      - "echo '{\"API_URL\": \"/api/v1/\"}' > siteconfig.json"
      - npm install
      - npm run build
    when:
      event: [ push, tag, pull_request ]

  test-backend:
      image: webhippie/golang:edge
      pull: true
      environment:
        GOPATH: /srv/app
      commands:
        - make test
      when:
        event: [ push, tag, pull_request ]

# Build a release when tagging
  before-static-build:
    image: karalabe/xgo-latest:latest
    pull: true
    environment:
      TAGS: bindata sqlite
      GOPATH: /srv/app
    commands:
      - make release-dirs
    when:
      event: [tag, push]

  static-build-windows:
    image: karalabe/xgo-latest:latest
    pull: true
    group: build-static
    environment:
      TAGS: bindata sqlite
      GOPATH: /srv/app
    commands:
      - make release-windows
    when:
      event: [tag, push]

  static-build-linux:
    image: karalabe/xgo-latest:latest
    pull: true
    group: build-static
    environment:
      TAGS: bindata sqlite
      GOPATH: /srv/app
    commands:
      - make release-linux
    when:
      event: [tag, push]

  static-build-darwin:
    image: karalabe/xgo-latest:latest
    pull: true
    group: build-static
    environment:
      TAGS: bindata sqlite
      GOPATH: /srv/app
    commands:
      - make release-darwin
    when:
      event: [tag, push]

#  static-build-frontend:
#    image: webhippie/nodejs:current
#    pull: true
#    group: build-static
#    commands:
#      - make release-frontend
#    when:
#      event: [push, tag ]

  after-build-static:
    image: karalabe/xgo-latest:latest
    pull: true
    environment:
      TAGS: bindata sqlite
      GOPATH: /srv/app
    commands:
      - make release-copy
      - make release-check
      - make release-os-package
      - make release-zip
    when:
      event: [tag, push]

# Push the releases to our pseudo-s3-bucket
  release:
    image: plugins/s3:1
    pull: true
    secrets: [ aws_access_key_id, aws_secret_access_key ]
    bucket: library-release
    endpoint: https://storage.kolaente.de
    path_style: true
    strip_prefix: dist/zip/
    source: dist/zip/*
    target: /${DRONE_TAG##v}
    when:
      event: [ tag ]

  release:
    image: plugins/s3:1
    pull: true
    secrets: [ aws_access_key_id, aws_secret_access_key ]
    bucket: library-release
    endpoint: https://storage.kolaente.de
    path_style: true
    strip_prefix: dist/zip/
    source: dist/zip/*
    target: /master
    when:
      event: [ push ]
      branch: [ master ]

#  release-minio:
#    image: minio/mc
#    pull: true
#    secrets: [ aws_access_key_id, aws_secret_access_key ]
#    commands:
#      - mc config host add minio https://storage.kolaente.de $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY S3v4 --insecure
#      - mc cp dist/release/* library-release/master/ -r --insecure
#    when:
#      event: [ push ]
#      branch: [ master ]

#  release-minio:
#    image: minio/mc
#    pull: true
#    secrets: [ aws_access_key_id, aws_secret_access_key ]
#    commands:
#      - mc config host add minio https://storage.kolaente.de $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY S3v4 --insecure
#      - mc cp dist/release/* library-release/${DRONE_TAG##v}/ -r --insecure
#    when:
#      event: [ tag ]