Skip to content

Commit 3d64f81

Browse files
Peter Mounceca-johnson
andauthored
shfmt (#199)
Co-authored-by: Carl Johnson <[email protected]>
1 parent 5de106b commit 3d64f81

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

dev/setup_env_osx.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/bash
22
set -eo pipefail
33

4-
command -v "python3" >/dev/null 2>&1 || { echo >&2 "I require python3 but it's not installed. Officially supported version is 3.7.5"; exit 1; }
4+
command -v "python3" >/dev/null 2>&1 || {
5+
echo >&2 "I require python3 but it's not installed. Officially supported version is 3.7.5"
6+
exit 1
7+
}
58

69
readonly root="${BASH_SOURCE%/*}/.."
710

@@ -13,23 +16,23 @@ python3 -m virtualenv "${venv_dir}"
1316

1417
platform=$(python3 -c "import platform; print(platform.system())")
1518
if [[ "${platform}" == "Windows" ]]; then
16-
venv_bin="${venv_dir}/Scripts"
19+
venv_bin="${venv_dir}/Scripts"
1720
else
18-
venv_bin="${venv_dir}/bin"
21+
venv_bin="${venv_dir}/bin"
1922
fi
2023

2124
"${venv_bin}/python" -m pip install -r "${root}/python/requirements.txt"
2225
"${venv_bin}/python" -m pip install -r "${root}/ci/requirements.txt"
2326

2427
# Install p4d binary if missing
2528
if ! [[ -x "$(command -v p4d)" ]]; then
26-
wget http://www.perforce.com/downloads/perforce/r18.2/bin.macosx1010x86_64/p4d && sudo chmod +x p4d && sudo mv p4d /usr/local/bin/p4d
29+
wget http://www.perforce.com/downloads/perforce/r18.2/bin.macosx1010x86_64/p4d && sudo chmod +x p4d && sudo mv p4d /usr/local/bin/p4d
2730
fi
2831

2932
if ! p4d -V | grep '2018.2'; then
30-
echo "WARNING: Version r18.2 (2018.2) of p4d is recommended for running tests. This version may not be compatible with existing server fixture."
33+
echo "WARNING: Version r18.2 (2018.2) of p4d is recommended for running tests. This version may not be compatible with existing server fixture."
3134
fi
3235

3336
if ! [[ -x "$(command -v bk)" ]]; then
34-
echo "WARNING: `bk` cli is not installed. https://github.com/buildkite/cli"
37+
echo "WARNING: 'bk' cli is not installed. https://github.com/buildkite/cli"
3538
fi

examples/buildkite-trigger.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
54
# P4 Trigger script that triggers buildkite builds
65
# Usage:
76
# my-pipeline change-commit //depot/... "%//depot/scripts/buildkite-trigger.sh% <organisation> <pipeline> %changelist% %user% %email%"

hooks/checkout

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ set -eo pipefail
33

44
plugin_root="${BASH_SOURCE%/*}/.."
55

6-
76
# Try to use explicit python3 if its installed
87
python_bin="python3"
98
if ! [[ -x "$(command -v ${python_bin})" ]]; then
10-
python_bin="python"
9+
python_bin="python"
1110
fi
1211

1312
# Ensure some version of virtualenv is installed
1413
# Lazy install avoids races between different jobs wanting different versions
1514
if [[ ! $(${python_bin} -m pip freeze) =~ "virtualenv==" ]]; then
16-
${python_bin} -m pip install "virtualenv==16.7.7"
15+
${python_bin} -m pip install "virtualenv==16.7.7"
1716
fi
1817

1918
# Unique virtualenv for requirements.txt
@@ -22,20 +21,20 @@ venv_dir="${BUILDKITE_BUILD_CHECKOUT_PATH}/../.perforce-plugin-venv-${venv_md5}"
2221

2322
platform=$(${python_bin} -c "import platform; print(platform.system())")
2423
if [[ "${platform}" == "Windows" ]]; then
25-
venv_python_bin="/Scripts/python"
24+
venv_python_bin="/Scripts/python"
2625
else
27-
venv_python_bin="/bin/python"
26+
venv_python_bin="/bin/python"
2827
fi
2928

3029
if ! [[ -d "${venv_dir}" ]]; then
31-
temp_venv_dir=$(mktemp -d -t perforce-plugin-venv-XXXXXX)
32-
trap "rm -rf ${temp_venv_dir}" EXIT
33-
${python_bin} -m virtualenv "${temp_venv_dir}"
34-
${temp_venv_dir}${venv_python_bin} -m pip install -r "${plugin_root}/python/requirements.txt"
35-
if ! [[ -d "${venv_dir}" ]]; then # second check to minimize venv init race
36-
mv "${temp_venv_dir}" "${venv_dir}"
37-
fi
38-
echo "virtualenv created at ${venv_dir}"
30+
temp_venv_dir=$(mktemp -d -t perforce-plugin-venv-XXXXXX)
31+
trap "rm -rf ${temp_venv_dir}" EXIT
32+
${python_bin} -m virtualenv "${temp_venv_dir}"
33+
${temp_venv_dir}${venv_python_bin} -m pip install -r "${plugin_root}/python/requirements.txt"
34+
if ! [[ -d "${venv_dir}" ]]; then # second check to minimize venv init race
35+
mv "${temp_venv_dir}" "${venv_dir}"
36+
fi
37+
echo "virtualenv created at ${venv_dir}"
3938
fi
4039

4140
${venv_dir}${venv_python_bin} "${plugin_root}/python/checkout.py"

hooks/pre-checkout

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
set -eo pipefail
33

44
# Allow sharing of perforce client workspaces for the same stream between pipelines
5-
if [[ "${BUILDKITE_PLUGIN_PERFORCE_SHARE_WORKSPACE}" == true ]] ; then
6-
echo "Workspace sharing enabled"
5+
if [[ "${BUILDKITE_PLUGIN_PERFORCE_SHARE_WORKSPACE}" == true ]]; then
6+
echo "Workspace sharing enabled"
77

8-
STREAM="${BUILDKITE_PLUGIN_PERFORCE_STREAM}"
9-
if [[ -z "${STREAM}" ]] ; then
10-
echo "Error: You must use stream workspaces to enable shared workspaces" >&2
11-
exit 1
12-
fi
13-
if [[ "${BUILDKITE_AGENT_META_DATA_AGENT_COUNT}" -gt 1 ]] ; then
14-
echo "Error: You cannot share stream workspaces when running more than one agent" >&2
15-
exit 1
16-
fi
17-
if [[ "${BUILDKITE_PLUGIN_PERFORCE_STREAM_SWITCHING}" == true ]] ; then
18-
echo "Stream switching enabled"
19-
# Sanitize '//depot/stream-name' to 'depot'
20-
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().split('/')[2]);")
21-
else # Create a directory per-stream
22-
# Sanitize '//depot/stream-name' to '__depot_stream-name'
23-
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().replace('/', '_'));")
24-
fi
25-
# Instead of builds/<agent_number>/<pipeline>, checkout to builds/<stream_name>
26-
PERFORCE_CHECKOUT_PATH="${BUILDKITE_BUILD_CHECKOUT_PATH}/../../${SANITIZED_STREAM}"
27-
export BUILDKITE_BUILD_CHECKOUT_PATH="${PERFORCE_CHECKOUT_PATH}"
28-
echo "Changed BUILDKITE_BUILD_CHECKOUT_PATH to ${PERFORCE_CHECKOUT_PATH}"
8+
STREAM="${BUILDKITE_PLUGIN_PERFORCE_STREAM}"
9+
if [[ -z "${STREAM}" ]]; then
10+
echo "Error: You must use stream workspaces to enable shared workspaces" >&2
11+
exit 1
12+
fi
13+
if [[ "${BUILDKITE_AGENT_META_DATA_AGENT_COUNT}" -gt 1 ]]; then
14+
echo "Error: You cannot share stream workspaces when running more than one agent" >&2
15+
exit 1
16+
fi
17+
if [[ "${BUILDKITE_PLUGIN_PERFORCE_STREAM_SWITCHING}" == true ]]; then
18+
echo "Stream switching enabled"
19+
# Sanitize '//depot/stream-name' to 'depot'
20+
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().split('/')[2]);")
21+
else # Create a directory per-stream
22+
# Sanitize '//depot/stream-name' to '__depot_stream-name'
23+
SANITIZED_STREAM=$(echo $STREAM | python -c "import sys; print(sys.stdin.read().replace('/', '_'));")
24+
fi
25+
# Instead of builds/<agent_number>/<pipeline>, checkout to builds/<stream_name>
26+
PERFORCE_CHECKOUT_PATH="${BUILDKITE_BUILD_CHECKOUT_PATH}/../../${SANITIZED_STREAM}"
27+
export BUILDKITE_BUILD_CHECKOUT_PATH="${PERFORCE_CHECKOUT_PATH}"
28+
echo "Changed BUILDKITE_BUILD_CHECKOUT_PATH to ${PERFORCE_CHECKOUT_PATH}"
2929
fi

0 commit comments

Comments
 (0)