# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
  test:
    docker:
      # specify the version
      - image: liamg/golang-opengl
    working_directory: /go/src/github.com/liamg/aminal
    steps:
      - checkout
      - run: make test
  build-linux:
    docker:
      - image: liamg/golang-opengl
    working_directory: /go/src/github.com/liamg/aminal
    requires:
      - build
    steps:
      - checkout
      - run: make build-linux
      - persist_to_workspace:
          root: bin
          paths:
            - linux
  package-debian:
    docker:
      - image: liamg/golang-opengl
    working_directory: /go/src/github.com/liamg/aminal
    requires:
      - build
    steps:
      - checkout
      - run: make package-debian
      - persist_to_workspace:
          root: bin
          paths:
            - debian
  build-darwin:
    docker:
      - image: karalabe/xgo-latest:latest
    working_directory: /go/src/github.com/liamg/aminal
    steps:
      - checkout
      - run: make build-darwin
      - run: cp /build/bin/darwin/* bin/darwin/
      - persist_to_workspace:
          root: bin
          paths:
            - darwin
  release:
    docker:
      - image: circleci/golang:latest
    steps:
      - run: mkdir -p artifacts
      - attach_workspace:
          at: artifacts
      - run:
          name: "Publish Release on GitHub"
          command: |
            mkdir -p release
            cp artifacts/linux/* release/
            cp artifacts/darwin/* release/
            cp artifacts/debian/* release/
            go get github.com/tcnksm/ghr
            ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -n "Aminal ${CIRCLE_TAG}" -b "Aminal ${CIRCLE_TAG}" -delete ${CIRCLE_TAG} release/
workflows:
  version: 2
  build:
    jobs:
      - test:
          filters:
            tags:
              only: /^v.*/
      - build-darwin:
          requires:
            - test
          filters:
            tags:
              only: /^v.*/
      - build-linux:
          requires:
            - test
          filters:
            tags:
              only: /^v.*/
      - package-debian:
          requires:
            - test
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
      - release:
          requires:
            - build-linux
            - build-darwin
            - package-debian
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/