Skip to content

Commit 99cc227

Browse files
committed
cleanup
Signed-off-by: Ryan Northey <[email protected]>
1 parent a121c0c commit 99cc227

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

.github/workflows/copilot-setup-steps.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,3 @@ jobs:
9494
sudo cp pants-wrapper.sh /usr/local/bin/pants
9595
sudo chmod +x /usr/local/bin/pants
9696
echo "PANTS_CA_CERTS_PATH=/etc/ssl/certs/ca-certificates.crt" >> $GITHUB_ENV
97-
pants --version

pants-wrapper.sh

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# Pants wrapper script that auto-installs pants if not already available
3-
#
3+
#
44
# This wrapper is installed to /usr/local/bin/pants during Copilot setup.
55
# It allows users to just run "pants" without worrying about installation.
66
#
@@ -13,44 +13,44 @@
1313

1414
set -euo pipefail
1515

16-
# Check if pants exists in ~/.local/bin (default install location)
17-
if [ -x "$HOME/.local/bin/pants" ]; then
18-
exec "$HOME/.local/bin/pants" "$@"
19-
fi
16+
GET_PANTS="${GET_PANTS:-}"
2017

21-
# pants is not installed, install it now
22-
echo "Pants not found. Installing pants..." >&2
2318

24-
# Find the repository root (where get-pants.sh should be)
25-
REPO_ROOT="${REPO_ROOT:-}"
26-
if [ -z "$REPO_ROOT" ]; then
27-
# Try to find get-pants.sh
28-
if [ -f "get-pants.sh" ]; then
29-
REPO_ROOT="$(pwd)"
30-
elif [ -f "../get-pants.sh" ]; then
31-
REPO_ROOT="$(cd .. && pwd)"
32-
elif [ -f "/home/runner/work/toolshed/toolshed/get-pants.sh" ]; then
33-
REPO_ROOT="/home/runner/work/toolshed/toolshed"
34-
else
35-
echo "Error: Cannot find get-pants.sh. Please set REPO_ROOT or run from repository directory." >&2
36-
exit 1
19+
run_pants () {
20+
if [[ -x "$HOME/.local/bin/pants" ]]; then
21+
exec "$HOME/.local/bin/pants" "$@"
22+
exit 0
3723
fi
38-
fi
24+
}
3925

40-
# Run get-pants.sh to install pants
41-
if [ -f "$REPO_ROOT/get-pants.sh" ]; then
42-
echo "Running get-pants.sh from $REPO_ROOT..." >&2
43-
cd "$REPO_ROOT"
44-
./get-pants.sh
45-
46-
# Now that pants is installed, execute it
47-
if [ -x "$HOME/.local/bin/pants" ]; then
48-
exec "$HOME/.local/bin/pants" "$@"
49-
else
50-
echo "Error: pants installation failed" >&2
51-
exit 1
26+
find_get_pants () {
27+
if [[ -z "$GET_PANTS" ]]; then
28+
# Try to find get-pants.sh
29+
if [[ -f "get-pants.sh" ]]; then
30+
GET_PANTS="$(realpath ./get-pants.sh)"
31+
elif [[ -f "../get-pants.sh" ]]; then
32+
GET_PANTS="$(realpath ../get-pants.sh)"
33+
elif [[ -f "/home/runner/work/toolshed/toolshed/get-pants.sh" ]]; then
34+
GET_PANTS="/home/runner/work/toolshed/toolshed/get-pants.sh"
35+
else
36+
echo "Error: Cannot find get-pants.sh. Please set GET_PANTS or run from repository directory." >&2
37+
exit 1
38+
fi
5239
fi
53-
else
54-
echo "Error: get-pants.sh not found in $REPO_ROOT" >&2
55-
exit 1
56-
fi
40+
if [[ ! -f "$GET_PANTS" ]]; then
41+
echo "Error: Cannot find get-pants.sh (${GET_PANTS})." >&2
42+
fi
43+
}
44+
45+
install_pants () {
46+
echo "Pants not found. Installing pants..." >&2
47+
find_get_pants
48+
echo "Running get-pants.sh from $GET_PANTS..." >&2
49+
"${GET_PANTS}"
50+
}
51+
52+
run_pants "${@}"
53+
install_pants
54+
run_pants "${@}"
55+
echo "Error: pants installation failed" >&2
56+
exit 1

0 commit comments

Comments
 (0)