-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathdeploy-pr.sh
More file actions
executable file
·93 lines (84 loc) · 1.8 KB
/
deploy-pr.sh
File metadata and controls
executable file
·93 lines (84 loc) · 1.8 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
#!/usr/bin/env bash
# Usage: ./deploy-pr.sh [--dry-run -n] [--yes -y] [--experiments -e <experiments>] [--build -b] [--deploy -d]
# deploys the current branch to a PR environment and posts login credentials to
# [#pr-deployments](https://codercom.slack.com/archives/C05DNE982E8) Slack channel
set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
cdroot
# default settings
dryRun=false
confirm=true
build=false
deploy=false
experiments=""
# parse arguments
while (("$#")); do
case "$1" in
-b | --build)
build=true
shift
;;
-d | --deploy)
deploy=true
shift
;;
-n | --dry-run)
dryRun=true
shift
;;
-e | --experiments)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
experiments="$2"
shift
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
shift
;;
-y | --yes)
confirm=false
shift
;;
--)
shift
break
;;
--*)
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*)
shift
;;
esac
done
# confirm if not passed -y or --yes
if $confirm; then
read -p "Are you sure you want to deploy? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Authenticate gh CLI
gh_auth
# get branch name and pr number
branchName=$(gh pr view --json headRefName | jq -r .headRefName)
prNumber=$(gh pr view --json number | jq -r .number)
if [[ "$dryRun" = true ]]; then
echo "dry run"
echo "branchName: ${branchName}"
echo "prNumber: ${prNumber}"
echo "experiments: ${experiments}"
echo "build: ${build}"
echo "deploy: ${deploy}"
exit 0
fi
echo "branchName: ${branchName}"
echo "prNumber: ${prNumber}"
echo "experiments: ${experiments}"
echo "build: ${build}"
echo "deploy: ${deploy}"
gh workflow run pr-deploy.yaml --ref "${branchName}" -f "experiments=${experiments}" -f "build=${build}" -f "deploy=${deploy}"