-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup-shared-env.sh
executable file
·44 lines (34 loc) · 1.22 KB
/
setup-shared-env.sh
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
#!/bin/bash
source "${GITHUB_ACTION_PATH}/util.sh"
# Fail on non-zero exit
set -e
DEPLOY_REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}"
echo "DEPLOY_REPO_URL=${DEPLOY_REPO_URL}" >> "${GITHUB_ENV}"
ENV_DIR="env/${ENV}"
echo "ENV_DIR=${ENV_DIR}" >> "${GITHUB_ENV}"
ENV_BRANCH="$(echo "${ENV_DIR}" | tr "/" "-")"
echo "ENV_BRANCH=${ENV_BRANCH}" >> "${GITHUB_ENV}"
set +e
if git branch -r --contains "origin/deploy-pr/${ENV_BRANCH}"; then
DIFF_BRANCH="deploy-pr/${ENV_BRANCH}"
else
DIFF_BRANCH="${ENV_BRANCH}"
fi
set -e
echo "DIFF_BRANCH=${DIFF_BRANCH}" >> "${GITHUB_ENV}"
ENV_BRANCH_URL="${DEPLOY_REPO_URL}/tree/${ENV_BRANCH}"
echo "ENV_BRANCH_URL=${ENV_BRANCH_URL}" >> "${GITHUB_ENV}"
if [[ -n "${PUSH_ENVIRONMENT_REGEX}" ]]; then
DEPLOY_METHOD="push"
PUSH_BRANCH="${ENV_BRANCH}"
elif [[ -n "${PR_ENVIRONMENT_REGEX}" ]]; then
DEPLOY_METHOD="pull-request"
PUSH_BRANCH="deploy-pr/${ENV_BRANCH}"
else
echo "Environment ${ENV} did not match any of the provided push or PR regexes."
exit 1
fi
echo "DEPLOY_METHOD=${DEPLOY_METHOD}" >> "${GITHUB_ENV}"
echo "PUSH_BRANCH=${PUSH_BRANCH}" >> "${GITHUB_ENV}"
RUN_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
echo "RUN_URL=${RUN_URL}" >> "${GITHUB_ENV}"