---
version: 2.1

executors:
  # Whenever the Go version is updated here, .promu.yml should also be updated.
  golang:
    docker:
    - image: circleci/golang:1.15

jobs:
  test:
    executor: golang

    steps:
    - setup_remote_docker
    - checkout
    - run: make promu
    - run: make check_license style unused lint test build
    - store_artifacts:
        path: promu
        destination: /build/promu
    - run: rm -v promu
    - run: git diff --exit-code

  build:
    executor: golang
    working_directory: /home/circleci/.go_workspace/src/github.com/prometheus/promu

    steps:
    - setup_remote_docker:
        version: 18.09.3
    - checkout
    - run: make promu
    - run: promu crossbuild -v
    - persist_to_workspace:
        root: .
        paths:
        - .build
    - store_artifacts:
        path: .build
        destination: /build

  release_tags:
    executor: golang

    steps:
    - checkout
    - attach_workspace:
        at: .
    - run: make promu
    - run: promu crossbuild tarballs
    - run: promu checksum .tarballs
    - run: promu release .tarballs
    - store_artifacts:
        path: .tarballs
        destination: releases

workflows:
  version: 2
  promu:
    jobs:
    - test:
        filters:
          tags:
            only: /.*/
    - build:
        filters:
          tags:
            only: /.*/
    - release_tags:
        requires:
        - test
        - build
        filters:
          tags:
            only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
          branches:
            ignore: /.*/
