forked from AnyBucket-Lab/circleci-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·53 lines (43 loc) · 1.86 KB
/
deploy.sh
File metadata and controls
executable file
·53 lines (43 loc) · 1.86 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
50
51
52
53
#!/bin/bash
set -ex
# Only deploy for private repository builds.
if [[ $CIRCLE_PROJECT_REPONAME != 'frontend-private' ]]; then
exit 0
fi
# Git Configuration
export GIT_SSH="$PWD/script/git-ssh-wrap.sh"
# Distribute built public files and publish the sha1 of this branch.
tar -cz resources/public/ | aws s3 cp - s3://$DEPLOY_S3_BUCKET/dist/$CIRCLE_SHA1.tgz
echo $CIRCLE_SHA1 | aws s3 cp - s3://$DEPLOY_S3_BUCKET/branch/$CIRCLE_BRANCH
# Keep open source master branch up to date.
export KEYPATH="$HOME/.ssh/id_frontend"
[email protected]:circleci/frontend
if [[ $CIRCLE_BRANCH = master ]]; then
git push $public_repo
fi
# Trigger a build on circleci/circle with latest assets
# Check for matching branch name on backend or create one from production branch.
export KEYPATH="$HOME/.ssh/id_frontend-private"
[email protected]:circleci/circle
heads_file=$(mktemp)
git ls-remote --heads $backend_repo > $heads_file
# backend_branch may be overridden by the next block
backend_branch=$CIRCLE_BRANCH
backend_sha=""
if ! grep -e "refs/heads/${CIRCLE_BRANCH}$" $heads_file ; then
backend_branch="zfe%2F$CIRCLE_BRANCH"
backend_sha=$(grep -e "refs/heads/production" $heads_file | awk '{print $1}')
else
backend_sha=$(grep -e "refs/heads/${CIRCLE_BRANCH}$" $heads_file | awk '{print $1}')
fi
# Trigger a backend build of this sha1.
circle_api=https://circleci.com/api/v1
tree_url=$circle_api/project/circleci/circle/tree/$backend_branch
http_status=$(curl -o /dev/null \
--silent \
--write-out '%{http_code}\n' \
--header "Content-Type: application/json" \
--data "{\"revision\": \"$backend_sha\", \"build_parameters\": {\"FRONTEND_DEPLOY_SHA1\": \"$CIRCLE_SHA1\"}}" \
--request POST \
-L $tree_url?circle-token=$BACKEND_CIRCLE_TOKEN)
[[ 201 = $http_status ]]