Skip to content

Commit

Permalink
Merge pull request #35 from Clever/publish-yml-workflows
Browse files Browse the repository at this point in the history
support posting non-json workflow definitions
  • Loading branch information
rgarcia authored Oct 10, 2017
2 parents a97400d + 6218dc4 commit dc51930
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions circleci/workflow-publish
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,35 @@ set -e

if [ $# -ne 4 ]; then
echo "Incorrect number of arguments given. Expected 4, received $#"
echo "Usage: workflow-publish [WF_URL] [WF_USER] [WF_PASS] [WF_JSON]"
echo "Usage: workflow-publish [WF_URL] [WF_USER] [WF_PASS] [WF_FILE]"
exit 1
fi


# User supplied args
WF_URL=$1
export WF_URL=$1
if [[ -z $WF_URL ]]; then echo "Missing arg1 WF_URL" && exit 1; fi
WF_USER=$2
export WF_USER=$2
if [[ -z $WF_USER ]]; then echo "Missing arg2 WF_USER" && exit 1; fi
WF_PASS=$3
export WF_PASS=$3
if [[ -z $WF_PASS ]]; then echo "Missing arg3 WF_PASS" && exit 1; fi
WF_FILE=$4
export WF_FILE=$4
if [[ -z $WF_FILE ]]; then echo "Missing arg4 WF_FILE" && exit 1; fi

# Set automatically by CircleCI
: ${CIRCLE_PROJECT_REPONAME?"Missing required env var"}
REPO=$CIRCLE_PROJECT_REPONAME
export REPO=$CIRCLE_PROJECT_REPONAME
: ${CIRCLE_PROJECT_USERNAME?"Missing required env var"}
USER=$CIRCLE_PROJECT_USERNAME
export USER=$CIRCLE_PROJECT_USERNAME
: ${CIRCLE_BUILD_NUM?"Missing required env var"}
BUILD_NUM=$CIRCLE_BUILD_NUM
export BUILD_NUM=$CIRCLE_BUILD_NUM

json_escape () {
printf '%s' $1 | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))'
}

WF_JSON=`cat $WF_FILE | tr '\n' ' ' | tr -d '[:space:]'`
WF_DATA=`json_escape $WF_JSON`
CURL_DATA="{\"username\":\"$USER\",\"reponame\":\"$REPO\",\"buildnum\":$BUILD_NUM,\"workflow\":$WF_DATA}"
echo "Publishing to workflow-manager..."
CURL_DATA=$(python -c 'import json, os; print(json.dumps({
"username": os.getenv("USER"),
"reponame": os.getenv("REPO"),
"buildnum": int(os.getenv("BUILD_NUM")),
"workflow": open(os.getenv("WF_FILE"), "r").read(),
}))')
echo $CURL_DATA | python -m json.tool

CURL_OUTPUT="workflow-manager.out"
Expand Down

0 comments on commit dc51930

Please sign in to comment.