-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcatalog-sync
More file actions
executable file
·49 lines (43 loc) · 1.37 KB
/
catalog-sync
File metadata and controls
executable file
·49 lines (43 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Results in catalog-sync-service generating and publishing an updated
# app config for the given app.
#
# Usage:
#
# catalog-sync [CIRCLE_CI_INTEGRATIONS_URL] [USER] [PASS] [APP_NAME]
#
set -e
: ${CIRCLE_BRANCH?"Missing required env var"}
BRANCH=$CIRCLE_BRANCH
: ${CIRCLE_PROJECT_REPONAME?"Missing required env var"}
REPO=$CIRCLE_PROJECT_REPONAME
: ${GITHUB_TOKEN?"Missing required env var"}
DEFAULT_BRANCH=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/Clever/$REPO" | jq -r '.default_branch')
if [[ $BRANCH != $DEFAULT_BRANCH ]]; then
echo "Skipping sync for non-master branch"
exit 0
fi
# User supplied args
CIRCLE_CI_INTEGRATIONS_URL=$1
if [[ -z $CIRCLE_CI_INTEGRATIONS_URL ]]; then echo "Missing arg1 CIRCLE_CI_INTEGRATIONS_URL" && exit 1; fi
USER=$2
if [[ -z $USER ]]; then echo "Missing arg2 USER" && exit 1; fi
PASS=$3
if [[ -z $PASS ]]; then echo "Missing arg3 PASS" && exit 1; fi
APP_NAME=$4
if [[ -z $APP_NAME ]]; then echo "Missing arg4 APP_NAME" && exit 1; fi
echo "Posting to catalog sync service..."
SC=$(curl -u $USER:$PASS \
--retry 5 \
-w "%{http_code}" \
-H "Content-Type: application/json" \
-X POST \
$CIRCLE_CI_INTEGRATIONS_URL/serviceCatalog?app=$APP_NAME)
if [ "$SC" -eq 200 ]; then
echo "Successfully published app catalog config"
exit 0
else
echo "Failed to publish app catalog config"
exit 1
fi