'Generic Commit'
Some checks failed
Build-Test-Publish / build (push) Failing after 23s

This commit is contained in:
Your Name 2025-06-17 20:59:06 +12:00
parent e97a893e3b
commit ab9a5292aa
2 changed files with 83 additions and 14 deletions

View File

@ -24,6 +24,8 @@
- creates a tgz archive of the folder, and uploads it to getpkg.xyz, a simple object server.
- prints the URL and hash of the uploaded archive
- uses the token from env variable SOS_WRITE_TOKEN to write to getpkg.xyz
- ARCH is optional, and if not provided it's assumed that the tool is compatible with all architectures
- ARCH should match $(uname -m), i.e. x86_64 or aarch64
getpkg update
- updates getpkg itself, and then runs install on all already installed tools
@ -379,7 +381,7 @@ help
std::cout << "Commands:" << std::endl;
std::cout << " <tool_name> Install/update the specified tool" << std::endl;
std::cout << " install <tool_name> Install/update tool (legacy)" << std::endl;
std::cout << " publish <tool_name:ARCH> <folder> Publish a tool" << std::endl;
std::cout << " publish <tool_name[:ARCH]> <folder> Publish a tool (ARCH optional)" << std::endl;
std::cout << " update Update getpkg and all tools" << std::endl;
std::cout << " version Show getpkg version" << std::endl;
std::cout << " create <tool_name> <directory> Create new tool directory" << std::endl;

View File

@ -73,9 +73,23 @@ mkdir -p "$TEST_DIR"
echo -e "${YELLOW}Running getpkg tests...${NC}\n"
# Check if getpkg binary exists
if [ ! -f "$GETPKG" ]; then
echo -e "${RED}Error: getpkg binary not found at $GETPKG${NC}"
echo "Please run ./build.sh first to build getpkg"
exit 1
fi
if [ ! -x "$GETPKG" ]; then
echo -e "${RED}Error: getpkg binary is not executable${NC}"
exit 1
fi
echo "Using getpkg binary: $GETPKG"
# Test 1: Version command
echo "Test 1: Version command"
VERSION=$("$GETPKG" version 2>&1) || VERSION=""
VERSION=$(timeout 3 "$GETPKG" version 2>&1) || VERSION=""
if [[ "$VERSION" =~ ^[0-9]{4}\.[0-9]{4}\.[0-9]{4}$ ]]; then
print_test_result "Version format (YYYY.MMDD.HHMM)" 0
else
@ -84,7 +98,7 @@ fi
# Test 2: Help command
echo -e "\nTest 2: Help command"
HELP_OUTPUT=$("$GETPKG" help 2>&1) || HELP_OUTPUT=""
HELP_OUTPUT=$(timeout 3 "$GETPKG" help 2>&1) || HELP_OUTPUT=""
if [[ "$HELP_OUTPUT" =~ "Usage: getpkg" ]]; then
print_test_result "Help command output" 0
else
@ -93,7 +107,7 @@ fi
# Test 3: Autocomplete command
echo -e "\nTest 3: Autocomplete command"
AUTOCOMPLETE_OUTPUT=$("$GETPKG" autocomplete 2>&1) || AUTOCOMPLETE_OUTPUT=""
AUTOCOMPLETE_OUTPUT=$(timeout 3 "$GETPKG" autocomplete 2>&1) || AUTOCOMPLETE_OUTPUT=""
if [[ "$AUTOCOMPLETE_OUTPUT" =~ "install" ]] && [[ "$AUTOCOMPLETE_OUTPUT" =~ "publish" ]]; then
print_test_result "Autocomplete command output" 0
else
@ -103,7 +117,7 @@ fi
# Test 4: Create command
echo -e "\nTest 4: Create command"
CREATE_DIR="${TEST_DIR}/${TEST_TOOL_NAME}"
"$GETPKG" create "$TEST_TOOL_NAME" "$CREATE_DIR" >/dev/null 2>&1 || true
timeout 3 "$GETPKG" create "$TEST_TOOL_NAME" "$CREATE_DIR" >/dev/null 2>&1 || true
if [ -d "$CREATE_DIR" ] && [ -f "$CREATE_DIR/setup_script.sh" ]; then
print_test_result "Create tool directory" 0
else
@ -136,12 +150,35 @@ else
print_test_result "Create test tool binary" 1
fi
# Test 5b: Test basic publish functionality
echo -e "\nTest 5b: Testing basic publish command"
# Test with a dummy token to see error message
DUMMY_OUTPUT=$(timeout 3 "$GETPKG" publish "dummy:x86_64" "$CREATE_DIR" 2>&1 <<< "") || true
echo "Dummy publish output: $DUMMY_OUTPUT"
# Test 6: Publish command (requires SOS_WRITE_TOKEN)
if [ -n "${SOS_WRITE_TOKEN:-}" ]; then
echo -e "\nTest 6: Publish command"
PUBLISH_OUTPUT=$("$GETPKG" publish "${TEST_TOOL_NAME}:${TEST_ARCH}" "$CREATE_DIR" 2>&1) || PUBLISH_OUTPUT=""
echo -e "\nTest 6: Publish command with ARCH"
echo "SOS_WRITE_TOKEN is set: ${#SOS_WRITE_TOKEN} characters"
echo "Publishing ${TEST_TOOL_NAME}:${TEST_ARCH} from $CREATE_DIR"
echo "Directory contents:"
ls -la "$CREATE_DIR"
echo "Running: $GETPKG publish ${TEST_TOOL_NAME}:${TEST_ARCH} $CREATE_DIR"
# Make sure the token is exported for the subprocess
export SOS_WRITE_TOKEN
# Run publish command and capture both stdout and stderr
PUBLISH_OUTPUT=$(timeout 3 "$GETPKG" publish "${TEST_TOOL_NAME}:${TEST_ARCH}" "$CREATE_DIR" 2>&1)
PUBLISH_EXIT_CODE=$?
echo "Publish exit code: $PUBLISH_EXIT_CODE"
echo "Publish output: $PUBLISH_OUTPUT"
# Check if the output indicates a crash or missing dependencies
if [ -z "$PUBLISH_OUTPUT" ] && [ $PUBLISH_EXIT_CODE -ne 0 ]; then
echo "Publish command failed with no output. Checking for missing dependencies..."
ldd "$GETPKG" 2>&1 | grep "not found" || echo "All dependencies found"
fi
if [[ "$PUBLISH_OUTPUT" =~ "Published!" ]] && [[ "$PUBLISH_OUTPUT" =~ "URL:" ]] && [[ "$PUBLISH_OUTPUT" =~ "Hash:" ]]; then
print_test_result "Publish tool to getpkg.xyz" 0
print_test_result "Publish tool with ARCH to getpkg.xyz" 0
# Extract hash for later cleanup
PUBLISHED_HASH=$(echo "$PUBLISH_OUTPUT" | grep "Hash:" | cut -d' ' -f2)
@ -157,7 +194,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then
# Test 8: Install command
echo -e "\nTest 8: Install command"
INSTALL_OUTPUT=$("$GETPKG" install "$TEST_TOOL_NAME" 2>&1) || INSTALL_OUTPUT=""
INSTALL_OUTPUT=$(timeout 3 "$GETPKG" install "$TEST_TOOL_NAME" 2>&1) || INSTALL_OUTPUT=""
if [[ "$INSTALL_OUTPUT" =~ "Installed ${TEST_TOOL_NAME} successfully" ]] || [[ "$INSTALL_OUTPUT" =~ "${TEST_TOOL_NAME} is already up to date" ]]; then
print_test_result "Install tool from getpkg.xyz" 0
@ -183,7 +220,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then
rm -rf ~/.local/bin/getpkg/"${TEST_TOOL_NAME}"
rm -f ~/.config/getpkg/"${TEST_TOOL_NAME}.json"
DIRECT_INSTALL_OUTPUT=$("$GETPKG" "$TEST_TOOL_NAME" 2>&1) || DIRECT_INSTALL_OUTPUT=""
DIRECT_INSTALL_OUTPUT=$(timeout 3 "$GETPKG" "$TEST_TOOL_NAME" 2>&1) || DIRECT_INSTALL_OUTPUT=""
if [[ "$DIRECT_INSTALL_OUTPUT" =~ "Installed ${TEST_TOOL_NAME} successfully" ]] || [[ "$DIRECT_INSTALL_OUTPUT" =~ "${TEST_TOOL_NAME} is already up to date" ]]; then
print_test_result "Direct tool name install syntax" 0
else
@ -192,7 +229,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then
# Test 12: Update already installed tool (should say up to date)
echo -e "\nTest 12: Update check for installed tool"
UPDATE_OUTPUT=$("$GETPKG" install "$TEST_TOOL_NAME" 2>&1) || UPDATE_OUTPUT=""
UPDATE_OUTPUT=$(timeout 3 "$GETPKG" install "$TEST_TOOL_NAME" 2>&1) || UPDATE_OUTPUT=""
if [[ "$UPDATE_OUTPUT" =~ "${TEST_TOOL_NAME} is already up to date" ]]; then
print_test_result "Update check recognizes up-to-date tool" 0
else
@ -209,7 +246,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then
fi
else
print_test_result "Publish tool to getpkg.xyz" 1
print_test_result "Publish tool with ARCH to getpkg.xyz" 1
# Skip dependent tests
print_test_result "Published tool exists on server" 1
print_test_result "Install tool from getpkg.xyz" 1
@ -218,6 +255,36 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then
print_test_result "Direct tool name install syntax" 1
print_test_result "Update check recognizes up-to-date tool" 1
fi
# Test 12b: Publish without ARCH (for cross-platform tools)
echo -e "\nTest 12b: Publish without ARCH"
TEST_TOOL_NOARCH="${TEST_TOOL_NAME}-noarch"
mkdir -p "${TEST_DIR}/${TEST_TOOL_NOARCH}"
cat > "${TEST_DIR}/${TEST_TOOL_NOARCH}/${TEST_TOOL_NOARCH}" << 'EOF'
#!/bin/bash
case "$1" in
version)
echo "1.0.0"
;;
*)
echo "Cross-platform test tool"
;;
esac
EOF
chmod +x "${TEST_DIR}/${TEST_TOOL_NOARCH}/${TEST_TOOL_NOARCH}"
PUBLISH_NOARCH_OUTPUT=$(timeout 3 "$GETPKG" publish "${TEST_TOOL_NOARCH}" "${TEST_DIR}/${TEST_TOOL_NOARCH}" 2>&1) || PUBLISH_NOARCH_OUTPUT=""
if [[ "$PUBLISH_NOARCH_OUTPUT" =~ "Published!" ]] && [[ "$PUBLISH_NOARCH_OUTPUT" =~ "URL:" ]] && [[ "$PUBLISH_NOARCH_OUTPUT" =~ "Hash:" ]]; then
print_test_result "Publish tool without ARCH" 0
# Clean up the noarch tool
NOARCH_HASH=$(curl -s "https://getpkg.xyz/hash/${TEST_TOOL_NOARCH}" 2>/dev/null || echo "")
if [ -n "$NOARCH_HASH" ] && [ "$NOARCH_HASH" != "null" ] && [ "$NOARCH_HASH" != "Not found" ]; then
curl -s -H "Authorization: Bearer ${SOS_WRITE_TOKEN}" \
"https://getpkg.xyz/deleteobject?hash=${NOARCH_HASH}" >/dev/null 2>&1 || true
fi
else
print_test_result "Publish tool without ARCH" 1
fi
else
echo -e "\n${YELLOW}Skipping publish/install tests (SOS_WRITE_TOKEN not set)${NC}"
echo "To run full tests, set SOS_WRITE_TOKEN environment variable"
@ -225,7 +292,7 @@ fi
# Test 13: Invalid tool name validation
echo -e "\nTest 13: Invalid tool name validation"
INVALID_OUTPUT=$("$GETPKG" install "../evil-tool" 2>&1) || INVALID_OUTPUT=""
INVALID_OUTPUT=$(timeout 3 "$GETPKG" install "../evil-tool" 2>&1) || INVALID_OUTPUT=""
if [[ "$INVALID_OUTPUT" =~ "Invalid tool name" ]]; then
print_test_result "Invalid tool name rejection" 0
else
@ -235,7 +302,7 @@ fi
# Test 14: Update command (if we have tools installed)
if [ -d ~/.config/getpkg ] && [ "$(ls -A ~/.config/getpkg/*.json 2>/dev/null | wc -l)" -gt 0 ]; then
echo -e "\nTest 14: Update command"
UPDATE_ALL_OUTPUT=$("$GETPKG" update 2>&1) || UPDATE_ALL_OUTPUT=""
UPDATE_ALL_OUTPUT=$(timeout 3 "$GETPKG" update 2>&1) || UPDATE_ALL_OUTPUT=""
if [[ "$UPDATE_ALL_OUTPUT" =~ "Update complete" ]]; then
print_test_result "Update all tools command" 0
else