Skip to content

Commit d74de2c

Browse files
authored
Merge pull request #29 from Clever/INFRA-2349-publish-workflows
add script: workflow-publish
2 parents ccdc6a6 + 9d4951b commit d74de2c

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ $ ./circleci/dapple-deploy [DAPPLE_URL] [DAPPLE_USER] [DAPPLE_PASS] [APP_NAME]
7171

7272
If you need to deploy multiple applications, run this command once for each.
7373

74+
#### Workflow
75+
76+
Publishes a workflow to [workflow-manager](https://github.com/clever/workflow-manager).
77+
78+
```
79+
$ ./circleci/workflow-publish [WF_URL] [WF_USER] [WF_PASS] [WF_JSON]
80+
```
81+
7482
#### Report-card
7583

7684
Runs [report-card](https://github.com/clever/report-card).

circleci/workflow-publish

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# Publishes workflows to Workflow Manager, via circle-ci-integrations.
4+
#
5+
# Usage:
6+
#
7+
# workflow-publish [WF_URL] [WF_USER] [WF_PASS] [WF_JSON]
8+
#
9+
# Required circleci provided environment variables:
10+
#
11+
# CIRCLE_PROJECT_REPONAME
12+
# CIRCLE_PROJECT_USERNAME
13+
# CIRCLE_BUILD_NUM
14+
#
15+
16+
set -e
17+
18+
if [ $# -ne 4 ]; then
19+
echo "Incorrect number of arguments given. Expected 4, received $#"
20+
echo "Usage: workflow-publish [WF_URL] [WF_USER] [WF_PASS] [WF_JSON]"
21+
exit 1
22+
fi
23+
24+
25+
# User supplied args
26+
WF_URL=$1
27+
if [[ -z $WF_URL ]]; then echo "Missing arg1 WF_URL" && exit 1; fi
28+
WF_USER=$2
29+
if [[ -z $WF_USER ]]; then echo "Missing arg2 WF_USER" && exit 1; fi
30+
WF_PASS=$3
31+
if [[ -z $WF_PASS ]]; then echo "Missing arg3 WF_PASS" && exit 1; fi
32+
WF_FILE=$4
33+
if [[ -z $WF_FILE ]]; then echo "Missing arg4 WF_FILE" && exit 1; fi
34+
35+
# Set automatically by CircleCI
36+
: ${CIRCLE_PROJECT_REPONAME?"Missing required env var"}
37+
REPO=$CIRCLE_PROJECT_REPONAME
38+
: ${CIRCLE_PROJECT_USERNAME?"Missing required env var"}
39+
USER=$CIRCLE_PROJECT_USERNAME
40+
: ${CIRCLE_BUILD_NUM?"Missing required env var"}
41+
BUILD_NUM=$CIRCLE_BUILD_NUM
42+
43+
json_escape () {
44+
printf '%s' $1 | python -c 'import json,sys; print(json.dumps(sys.stdin.read()))'
45+
}
46+
47+
WF_JSON=`cat $WF_FILE | tr '\n' ' ' | tr -d '[:space:]'`
48+
WF_DATA=`json_escape $WF_JSON`
49+
CURL_DATA="{\"username\":\"$USER\",\"reponame\":\"$REPO\",\"buildnum\":$BUILD_NUM,\"workflow\":$WF_DATA}"
50+
echo "Publishing to workflow-manager..."
51+
echo $CURL_DATA | python -m json.tool
52+
53+
exit 1
54+
55+
CURL_OUTPUT="workflow-manager.out"
56+
SC=$(curl -u $WF_USER:$WF_PASS \
57+
-w "%{http_code}" \
58+
--output $CURL_OUTPUT \
59+
-H "Content-Type: application/json" \
60+
-X POST \
61+
-d "$CURL_DATA" \
62+
$WF_URL)
63+
64+
if [ "$SC" -eq 200 ]; then
65+
echo "Successfully published workflow"
66+
rm -f $CURL_OUTPUT
67+
exit 0
68+
else
69+
echo "Failed to publish workflow"
70+
echo "------------------------------------------------"
71+
cat $CURL_OUTPUT
72+
echo ""
73+
echo "------------------------------------------------"
74+
rm -f $CURL_OUTPUT
75+
exit 1
76+
fi

0 commit comments

Comments
 (0)