#!/bin/bash set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" version_from_metadata() { grep -E "^version" $SCRIPT_DIR/metadata.rb | sed -Ee "s/version '(.*)'/\1/" } run_knife_command() { docker run \ --rm \ -v $SCRIPT_DIR:/chef-repo/cookbooks/signalfx_agent \ -v $HOME/.chef:/root/.chef \ --workdir /chef-repo \ signalfx-agent-chef-dev \ knife $@ } has_existing_version() { run_knife_command supermarket show signalfx_agent --format json | \ jq -r '.versions' | \ sed -Ee 's@"https://.*([0-9]\.[0-9]\.[0-9])"$@\1@' | \ grep $(version_from_metadata) } make -C $SCRIPT_DIR dev-image if has_existing_version; then echo "Version $(version_from_metadata) already exists in the supermarket, please update metadata.rb to a new version" >&2 exit 1 fi tag=chef-v$(version_from_metadata) if ! git rev-parse $tag; then git tag -a $tag git push origin $tag fi run_knife_command supermarket share -o ./cookbooks signalfx_agent echo "Cookbook version $(version_from_metadata) successfully uploaded to Supermarket"