Skip to content

Commit b443254

Browse files
committed
fix install script latest version parsing
Signed-off-by: Sodawyx <sodawyx@126.com>
1 parent e2677ed commit b443254

2 files changed

Lines changed: 98 additions & 1 deletion

File tree

scripts/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ info "Detected target: $TARGET"
5858
if [ -z "$VERSION" ]; then
5959
info "Resolving latest release from github.com/${REPO}"
6060
VERSION=$($DOWNLOAD "https://api.github.com/repos/${REPO}/releases/latest" \
61-
| grep '"tag_name"' | head -1 | sed -E 's/.*"tag_name":\s*"([^"]+)".*/\1/')
61+
| grep '"tag_name"' | head -1 | sed -E 's/.*"tag_name":[[:space:]]*"([^"]+)".*/\1/')
6262
[ -n "$VERSION" ] || err "could not resolve latest release tag"
6363
fi
6464
info "Version: $VERSION"
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""Integration tests for the Unix installer script."""
2+
3+
import os
4+
import stat
5+
import subprocess
6+
from pathlib import Path
7+
8+
9+
def _write_executable(path: Path, content: str) -> None:
10+
path.write_text(content)
11+
path.chmod(path.stat().st_mode | stat.S_IXUSR)
12+
13+
14+
def test_install_sh_parses_latest_release_tag_on_posix_sed(tmp_path):
15+
repo_root = Path(__file__).resolve().parents[2]
16+
fake_bin = tmp_path / "bin"
17+
fake_bin.mkdir()
18+
install_dir = tmp_path / "install"
19+
20+
calls = tmp_path / "curl-calls.txt"
21+
_write_executable(
22+
fake_bin / "curl",
23+
f"""#!/usr/bin/env sh
24+
set -eu
25+
url="${{@:$#}}"
26+
printf '%s\\n' "$url" >> "{calls}"
27+
case "$url" in
28+
*"/releases/latest")
29+
printf '%s\\n' '{{'
30+
printf '%s\\n' ' "tag_name": "v0.1.0",'
31+
printf '%s\\n' '}}'
32+
;;
33+
*".sha256")
34+
printf '%s\\n' 'expected-sha agentrun-0.1.0-darwin-arm64.tar.gz'
35+
;;
36+
*)
37+
printf '%s\\n' 'fake archive'
38+
;;
39+
esac
40+
""",
41+
)
42+
_write_executable(
43+
fake_bin / "uname",
44+
"""#!/usr/bin/env sh
45+
case "${1:-}" in
46+
-s) printf '%s\n' Darwin ;;
47+
-m) printf '%s\n' arm64 ;;
48+
*) printf '%s\n' Darwin ;;
49+
esac
50+
""",
51+
)
52+
_write_executable(
53+
fake_bin / "tar",
54+
"""#!/usr/bin/env sh
55+
while [ "$#" -gt 0 ]; do
56+
if [ "$1" = "-C" ]; then
57+
shift
58+
install_dir="$1"
59+
break
60+
fi
61+
shift
62+
done
63+
printf '%s\n' '#!/usr/bin/env sh' > "$install_dir/agentrun"
64+
chmod +x "$install_dir/agentrun"
65+
""",
66+
)
67+
_write_executable(
68+
fake_bin / "shasum",
69+
"""#!/usr/bin/env sh
70+
printf '%s\n' 'expected-sha agentrun-0.1.0-darwin-arm64.tar.gz'
71+
""",
72+
)
73+
74+
env = {
75+
**os.environ,
76+
"PATH": f"{fake_bin}:{os.environ['PATH']}",
77+
"AGENTRUN_INSTALL": str(install_dir),
78+
"AGENTRUN_REPO": "Serverless-Devs/agentrun-cli",
79+
}
80+
81+
result = subprocess.run(
82+
["sh", str(repo_root / "scripts" / "install.sh")],
83+
env=env,
84+
text=True,
85+
stdout=subprocess.PIPE,
86+
stderr=subprocess.PIPE,
87+
check=False,
88+
)
89+
90+
assert result.returncode == 0, result.stdout + result.stderr
91+
assert "Version: v0.1.0" in result.stdout
92+
assert "Downloading agentrun-0.1.0-darwin-arm64.tar.gz" in result.stdout
93+
assert (install_dir / "agentrun").exists()
94+
assert (
95+
"https://github.com/Serverless-Devs/agentrun-cli/releases/download/"
96+
"v0.1.0/agentrun-0.1.0-darwin-arm64.tar.gz"
97+
) in calls.read_text()

0 commit comments

Comments
 (0)