version: 2.1
references:
  base_container: &base_container
    docker:
      - image: filebrowser/builder:v1.1.0
jobs:
  lint:
    <<: *base_container
    steps:
      - checkout
      - run: make lint
  test:
    <<: *base_container
    steps:
      - checkout
      - run:
          name: "Test"
          command: make test
  build:
    <<: *base_container
    steps:
      - checkout
      - run:
          name: "Build"
          command: make build
      - run:
          name: "Cleanup"
          command: |
            rm -rf frontend/node_modules
            rm -rf bin/
      - persist_to_workspace:
          root: .
          paths:
            - '*'
  release:
    <<: *base_container
    steps:
      - attach_workspace:
          at: '~/project'
      - setup_remote_docker
      - run: echo $DOCKER_PASSWORD | docker login --username $DOCKER_USERNAME --password-stdin
      - run: curl -sL https://git.io/goreleaser | bash
      - run: docker logout
workflows:
  version: 2
  build-workflow:
    jobs:
      - lint:
          filters:
            tags:
              only: /.*/
      - test:
          filters:
            tags:
              only: /.*/
      - build:
          filters:
            tags:
              only: /.*/
      - release:
          context: deploy
          requires:
            - build
            - test
            - lint
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/