version: 2
jobs:
  build:
    docker:
      - image: edy555/arm-embedded:8.2
    steps:
      - checkout
      - run:
          name: "Pull Submodules"
          command: |
            git submodule init
            git submodule update --remote
      - run:
          name: "Build Firmware"
          command: make
      - run:
          name: "Remove obj/lst files"
          command: rm -r build/obj build/lst
      - store_artifacts:
          path: build
          destination: build
      - persist_to_workspace:
          root: .
          paths:
            - build
  publish-github-release:
    docker:
      - image: circleci/golang:1.10
    steps:
      - attach_workspace:
          at: .
      - run:
          name: "Publish Release on GitHub"
          command: |
            go get github.com/tcnksm/ghr
            zip nanovna-firmware-${CIRCLE_TAG}.zip build/*.bin build/*.hex build/*.elf
            ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${CIRCLE_TAG} nanovna-firmware-${CIRCLE_TAG}.zip
workflows:
  version: 2
  main:
    jobs:
      - build:
          filters:
            tags:
              # 1.0.0
              only: /^\d+\.\d+\.\d+$/
      - publish-github-release:
          requires:
            - build
          filters:
            branches:
              ignore: /.*/
            tags:
              # 1.0.0
              only: /^\d+\.\d+\.\d+$/