version: 2
jobs:
  linting:
    docker:
      - image: circleci/golang:1.10
    working_directory: /go/src/github.com/filebrowser/filebrowser
    steps:
      - checkout
      - run:
          name: Install Dependencies
          command: |
            curl -sL -o $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
            chmod +x $GOPATH/bin/dep
            dep ensure -v
            go get github.com/alecthomas/gometalinter
            gometalinter --install
      - run:
          name: Run linting
          command: |
            gometalinter --exclude="rice-box.go" \
              --deadline=300s \
              -D goconst \
              -D gocyclo \
              -D vetshadow \
              -D errcheck \
              -D golint \
              -D gas \
              -D gosec
  build:
    docker:
      - image: circleci/golang:1.10
    working_directory: /go/src/github.com/filebrowser/filebrowser
    steps:
      - checkout
      - run:
          name: Install Dependencies
          command: |
            curl -sL -o $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
            chmod +x $GOPATH/bin/dep
            dep ensure -v
      - run:
          name: Building
          command: go build github.com/filebrowser/filebrowser/cmd/filebrowser
  deploy:
    docker:
      - image: circleci/golang:1.10
    working_directory: /go/src/github.com/filebrowser/filebrowser
    steps:
      - checkout
      - run:
          name: Install Dependencies
          command: |
            curl -sL -o $GOPATH/bin/dep https://github.com/golang/dep/releases/download/v0.4.1/dep-linux-amd64
            chmod +x $GOPATH/bin/dep
            dep ensure -v
      - run:
          name: Deploy
          command: curl -sL https://git.io/goreleaser | bash

workflows:
  version: 2
  lint-build-deploy:
    jobs:
      - linting:
          filters:
              tags:
                only: /.*/
              branches:
                only: /.*/
      - build:
          filters:
              tags:
                only: /.*/
              branches:
                only: /.*/
      - deploy:
          requires:
            - linting
            - build
          filters:
            tags:
              only: /v[0-9]+(\.[0-9]+)*(-.*)*/
            branches:
              ignore: /.*/