kind: pipeline
name: testing

workspace:
  base: /go
  path: src/git.kolaente.de/sofaraum/client

steps:
  - name: build
    image: vikunja/golang-build:latest
    pull: true
    commands:
      - make lint
      - make fmt-check
      - make ineffassign-check
      - make misspell-check
      - make build
    when:
      event: [ push, tag, pull_request ]

  - name: test
    image: vikunja/golang-build:latest
    pull: true
    commands:
      - make test
    depends_on: [ build ]
    when:
      event: [ push, tag, pull_request ]

---
kind: pipeline
name: deploy-master
depends_on:
  - testing

workspace:
  base: /go
  path: src/git.kolaente.de/sofaraum/client

trigger:
  branch:
    - master
  event:
    - push

steps:
  # Needed to get the versions right as they depend on tags
  - name: fetch-tags
    image: docker:git
    commands:
      - git fetch --tags

  - name: static
    image: techknowlogick/xgo:latest
    pull: true
    environment:
      # This path does not exist. However, when we set the gopath to /go, the build fails. Not sure why.
      # Leaving this here until we know how to resolve this properly.
      GOPATH: /srv/app
    commands:
      - export PATH=$PATH:$GOPATH/bin
      - make release

  # Push the releases to our pseudo-s3-bucket
  - name: release
    image: plugins/s3:1
    pull: true
    settings:
      bucket: sofaraum-client
      access_key:
        from_secret: aws_access_key_id
      secret_key:
        from_secret: aws_secret_access_key
      endpoint: https://storage.kolaente.de
      path_style: true
      strip_prefix: dist/binaries/
      source: dist/binaries/*
      target: /master/
    depends_on: [ static ]

---
kind: pipeline
name: deploy-version
depends_on:
  - testing

workspace:
  base: /go
  path: src/git.kolaente.de/sofaraum/client

trigger:
  event:
    - tag

steps:
  # Needed to get the versions right as they depend on tags
  - name: fetch-tags
    image: docker:git
    commands:
      - git fetch --tags

  - name: static
    image: techknowlogick/xgo:latest
    pull: true
    commands:
      - export PATH=$PATH:$GOPATH/bin
      - make release

  # Push the releases to our pseudo-s3-bucket
  - name: release
    image: plugins/s3:1
    pull: true
    settings:
      bucket: sofaraum-client
      access_key:
        from_secret: aws_access_key_id
      secret_key:
        from_secret: aws_secret_access_key
      endpoint: https://storage.kolaente.de
      path_style: true
      strip_prefix: dist/binaries/
      source: dist/binaries/*
      target: /${DRONE_TAG##v}
    depends_on: [ static ]
