Files
coder/scripts/deploy-pr.sh
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
1.8 KiB
Bash
Raw Normal View History

2023-07-27 13:07:53 +03:00
#!/usr/bin/env bash
2023-08-11 13:49:23 +03:00
# Usage: ./deploy-pr.sh [--dry-run -n] [--yes -y] [--experiments -e <experiments>] [--build -b] [--deploy -d]
2023-07-27 13:07:53 +03:00
# deploys the current branch to a PR environment and posts login credentials to
# [#pr-deployments](https://codercom.slack.com/archives/C05DNE982E8) Slack channel
2023-07-27 15:40:59 +03:00
set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
cdroot
2023-07-27 13:07:53 +03:00
2023-07-27 15:40:59 +03:00
# default settings
dryRun=false
confirm=true
2023-08-11 13:49:23 +03:00
build=false
deploy=false
experiments=""
2023-07-27 13:07:53 +03:00
2023-07-27 15:40:59 +03:00
# parse arguments
while (("$#")); do
case "$1" in
2023-08-11 13:49:23 +03:00
-b | --build)
build=true
shift
;;
-d | --deploy)
deploy=true
shift
2023-07-27 15:40:59 +03:00
;;
-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
2023-07-27 15:40:59 +03:00
;;
-y | --yes)
confirm=false
shift
;;
--)
shift
break
;;
--*)
echo "Error: Unsupported flag $1" >&2
exit 1
2023-07-27 15:40:59 +03:00
;;
*)
shift
2023-07-27 15:40:59 +03:00
;;
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
2023-07-27 13:07:53 +03:00
fi
# Authenticate gh CLI
gh_auth
2023-07-27 15:40:59 +03:00
# get branch name and pr number
branchName=$(gh pr view --json headRefName | jq -r .headRefName)
prNumber=$(gh pr view --json number | jq -r .number)
2023-08-11 13:49:23 +03:00
if [[ "$dryRun" = true ]]; then
2023-07-27 15:40:59 +03:00
echo "dry run"
echo "branchName: ${branchName}"
echo "prNumber: ${prNumber}"
echo "experiments: ${experiments}"
2023-08-11 13:49:23 +03:00
echo "build: ${build}"
echo "deploy: ${deploy}"
2023-07-27 15:40:59 +03:00
exit 0
fi
echo "branchName: ${branchName}"
echo "prNumber: ${prNumber}"
echo "experiments: ${experiments}"
2023-08-11 13:49:23 +03:00
echo "build: ${build}"
echo "deploy: ${deploy}"
gh workflow run pr-deploy.yaml --ref "${branchName}" -f "experiments=${experiments}" -f "build=${build}" -f "deploy=${deploy}"