-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtugfloat
More file actions
111 lines (96 loc) · 2.68 KB
/
tugfloat
File metadata and controls
111 lines (96 loc) · 2.68 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
set -e
print_usage() {
echo "Manage Tugboat instances with git branch name"
echo " "
echo "usage: $0 [options]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-b name of git branch to preview (required)"
echo "-p name of base preview branch (optional)"
echo "-r tugboat repo ID (required; can be set with TUGBOAT_REPO_ID)"
echo "-t Tugboat API token (required; can be set with TUGBOAT_TOKEN)"
echo "-o operation: launch|sink|link|id"
}
auth_token=${TUGBOAT_TOKEN}
repo_id=${TUGBOAT_REPO_ID}
while getopts 'b:p:r:t:o:' flag; do
case "${flag}" in
b) git_branch=${OPTARG};;
p) git_base_branch=${OPTARG};;
r) repo_id=${OPTARG} ;;
t) auth_token=${OPTARG};;
o) operation=${OPTARG};;
*) print_usage
exit 1 ;;
esac
done
shift $((OPTIND -1))
if [ -z $repo_id ]; then
echo "No repository ID specified. See --help";
exit 1;
fi
if [ -z $git_branch ]; then
echo "No git branch specified. See --help";
exit 1;
fi
use_token=""
if [ -n "$auth_token" ]; then
use_token="-t $auth_token"
fi
get_boats(){
get_preview_ids $git_branch
}
get_preview_ids(){
get_previews $1 | jq -r '.id'
}
get_previews(){
tugboat list previews repo=$repo_id $use_token -j | \
jq ".[] | select(.ref == \"$1\")"
}
sink(){
for boat in $(get_boats)
do
tugboat delete $boat $use_token
echo "Deleted tugboat instance with id $boat"
done
}
get_boat_urls(){
get_previews $git_branch | jq -r '.url'
}
launch_or_update(){
for boat in $(get_boats)
do
echo "Rebuilding tugboat instance with id $boat"
tugboat rebuild $boat children=true force=true $use_token
return
done
base=$(get_preview_ids $git_base_branch | head -n 1)
if [ -n $base ]; then
echo "Creating new tugboat preview from git branch $git_branch based on $git_base_branch"
tugboat create preview $git_branch base=$base repo=$repo_id $use_token
else
echo "Creating new tugboat preview from git branch $git_branch"
tugboat create preview $git_branch repo=$repo_id $use_token
fi
}
case $operation in
launch)
echo "Launching or updating tugboat preview for branch $git_branch"
launch_or_update
;;
sink)
echo "Deleting all tugboat previews for branch $git_branch"
sink
;;
link)
get_boat_urls
;;
id)
get_boats
;;
*)
echo "Operation not specified. See --help"
;;
esac