Skip to content

Commit 2989645

Browse files
authored
copilot: Install pants lazily (#3253)
Signed-off-by: Ryan Northey <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent baf91fd commit 2989645

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ jobs:
9090
python-version: "3.12"
9191
- name: Pants
9292
run: |
93-
./get-pants.sh
93+
# Install the pants wrapper script that auto-installs pants if needed
94+
sudo cp pants-wrapper.sh /usr/local/bin/pants
95+
sudo chmod +x /usr/local/bin/pants
9496
echo "PANTS_CA_CERTS_PATH=/etc/ssl/certs/ca-certificates.crt" >> $GITHUB_ENV
95-
pants --version

pants-wrapper.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
# Pants wrapper script that auto-installs pants if not already available
3+
#
4+
# This wrapper is installed to /usr/local/bin/pants during Copilot setup.
5+
# It allows users to just run "pants" without worrying about installation.
6+
#
7+
# How it works:
8+
# 1. Check if pants is already installed in ~/.local/bin (default install location)
9+
# 2. If not, automatically run get-pants.sh to install it
10+
# 3. Then execute pants with all arguments passed through
11+
#
12+
# This means users can always run "pants <args>" and it will "just work"
13+
14+
set -euo pipefail
15+
16+
GET_PANTS="${GET_PANTS:-}"
17+
18+
19+
run_pants () {
20+
if [[ -x "$HOME/.local/bin/pants" ]]; then
21+
exec "$HOME/.local/bin/pants" "$@"
22+
exit 0
23+
fi
24+
}
25+
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
39+
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)