version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.4.1
    branches:
      only:
        - master
    steps:
      - checkout
      - run:
          name: Call GitHub Releases API
          command: |
            cd /home/circleci/project
            TAG=$(git tag -l | grep -E '^2\.[0-9]{6}' | sort -gr | head -n1 | sed -E 's/\.[0-9]{3}$//')
            if [ ! -z "$TAG" ]; then
              for url in $(echo $RELEASE_INJECTION | sed "s/,/ /g"); do
                curl -sL -X POST -H "Content-Type: application/json" \
                  -u "$ACCESS_TOKEN" \
                  --data "{\"tag_name\": \"$TAG\", \
                           \"target_commitish\": \"master\", \
                           \"name\": \"Netdisco $TAG\"}" \
                  $url
              done
            fi
