#!/bin/bash
set -e
if [ -z "$1" ]; then
    echo "Pass the version number as the first arg. E.g.: script/release 1.2.3"
    exit 1
fi
VERSION=$1
if [ -z "$GITHUB_TOKEN" ]; then
    echo "GITHUB_TOKEN must be set for github-release"
    exit 1
fi

script/build

docker run --rm -v `pwd`:/go/src/github.com/docker/machine docker-machine ./script/generate-sums

git tag $VERSION
git push --tags
docker run --rm -e GITHUB_TOKEN docker-machine github-release release \
    --user docker \
    --repo machine \
    --tag $VERSION \
    --name $VERSION \
    --description "" \
    --pre-release
for BINARY in docker-machine_*; do
    docker run --rm -e GITHUB_TOKEN -v `pwd`:/go/src/github.com/docker/machine \
        docker-machine github-release upload \
        --user docker \
        --repo machine \
        --tag $VERSION \
        --name $BINARY \
        --file $BINARY
done
