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

This commit is contained in:
Your Name 2025-06-17 22:43:58 +12:00
parent f20c8ff330
commit a4ce65fa5b
6 changed files with 69 additions and 7 deletions

View File

@ -157,11 +157,12 @@ int install_tool(int argc, char* argv[]) {
tfile.close(); tfile.close();
std::string localHash = toolInfo.value("hash", ""); std::string localHash = toolInfo.value("hash", "");
std::string localArch = toolInfo.value("arch", arch);
// Get remote hash to compare // Get remote hash to compare - use the same arch that was originally installed
GetbinClient getbin; GetbinClient getbin;
std::string remoteHash; std::string remoteHash;
if (getbin.getHash(toolName, arch, remoteHash) && !remoteHash.empty()) { if (getbin.getHash(toolName, localArch, remoteHash) && !remoteHash.empty()) {
if (localHash != remoteHash) { if (localHash != remoteHash) {
needsUpdate = true; needsUpdate = true;
std::cout << "Updating " << toolName << "..." << std::endl; std::cout << "Updating " << toolName << "..." << std::endl;
@ -183,12 +184,19 @@ int install_tool(int argc, char* argv[]) {
scriptManager.removeToolEntry(toolName); scriptManager.removeToolEntry(toolName);
if (std::filesystem::exists(binDir)) std::filesystem::remove_all(binDir); if (std::filesystem::exists(binDir)) std::filesystem::remove_all(binDir);
// Download tool // Download tool - try arch-specific version first, then universal fallback
GetbinClient getbin2; GetbinClient getbin2;
std::string downloadArch = arch;
std::cout << "Downloading " << toolName << ":" << arch << "..." << std::endl; std::cout << "Downloading " << toolName << ":" << arch << "..." << std::endl;
if (!getbin2.download(toolName, arch, archivePath.string())) { if (!getbin2.download(toolName, arch, archivePath.string())) {
std::cerr << "Failed to download tool archive." << std::endl; // Try universal version as fallback
return 1; std::cout << "Arch-specific version not found, trying universal version..." << std::endl;
std::cout << "Downloading " << toolName << ":universal..." << std::endl;
if (!getbin2.download(toolName, "universal", archivePath.string())) {
std::cerr << "Failed to download tool archive (tried both " << arch << " and universal)." << std::endl;
return 1;
}
downloadArch = "universal";
} }
// Unpack tool // Unpack tool
@ -207,7 +215,7 @@ int install_tool(int argc, char* argv[]) {
// Get tool info // Get tool info
std::string hash; std::string hash;
getbin2.getHash(toolName, arch, hash); getbin2.getHash(toolName, downloadArch, hash);
std::string version; std::string version;
std::string toolPath = binDir.string() + "/" + toolName; std::string toolPath = binDir.string() + "/" + toolName;
std::string versionCmd = shellEscape(toolPath) + " version"; std::string versionCmd = shellEscape(toolPath) + " version";
@ -231,7 +239,7 @@ int install_tool(int argc, char* argv[]) {
{"name", toolName}, {"name", toolName},
{"version", version}, {"version", version},
{"hash", hash}, {"hash", hash},
{"arch", arch} {"arch", downloadArch}
}; };
std::ofstream toolInfoFile(toolInfoPath); std::ofstream toolInfoFile(toolInfoPath);
toolInfoFile << toolInfo.dump(2); toolInfoFile << toolInfo.dump(2);
@ -256,6 +264,11 @@ int publish_tool(int argc, char* argv[]) {
} }
std::string labeltag = argv[2]; std::string labeltag = argv[2];
std::string folder = argv[3]; std::string folder = argv[3];
// If no ARCH is provided (no colon in labeltag), append ":universal" for cross-platform tools
if (labeltag.find(':') == std::string::npos) {
labeltag += ":universal";
}
std::string home = get_home(); std::string home = get_home();
std::filesystem::path archivePath = std::filesystem::path(home) / ".tmp" / (labeltag + ".tgz"); std::filesystem::path archivePath = std::filesystem::path(home) / ".tmp" / (labeltag + ".tgz");
std::filesystem::create_directories(archivePath.parent_path()); std::filesystem::create_directories(archivePath.parent_path());

View File

@ -285,6 +285,25 @@ EOF
else else
print_test_result "Publish tool without ARCH" 1 print_test_result "Publish tool without ARCH" 1
fi fi
# Test 12c: Install universal tool (arch fallback)
echo -e "\nTest 12c: Install universal tool (arch fallback)"
rm -rf ~/.config/getpkg/"${TEST_TOOL_NOARCH}.json" ~/.local/bin/getpkg/"${TEST_TOOL_NOARCH}" 2>/dev/null || true
FALLBACK_INSTALL_OUTPUT=$(timeout 3 "$GETPKG" install "${TEST_TOOL_NOARCH}" 2>&1) || FALLBACK_INSTALL_OUTPUT=""
if [[ "$FALLBACK_INSTALL_OUTPUT" =~ "Arch-specific version not found, trying universal version" ]] && [[ "$FALLBACK_INSTALL_OUTPUT" =~ "Installed ${TEST_TOOL_NOARCH} successfully" ]]; then
print_test_result "Install universal tool with arch fallback" 0
# Test update check for universal tool
UPDATE_UNIVERSAL_OUTPUT=$(timeout 3 "$GETPKG" install "${TEST_TOOL_NOARCH}" 2>&1) || UPDATE_UNIVERSAL_OUTPUT=""
if [[ "$UPDATE_UNIVERSAL_OUTPUT" =~ "${TEST_TOOL_NOARCH} is already up to date" ]]; then
print_test_result "Update check for universal tool" 0
else
print_test_result "Update check for universal tool" 1
fi
else
print_test_result "Install universal tool with arch fallback" 1
print_test_result "Update check for universal tool" 1
fi
else else
echo -e "\n${YELLOW}Skipping publish/install tests (SOS_WRITE_TOKEN not set)${NC}" 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" echo "To run full tests, set SOS_WRITE_TOKEN environment variable"

View File

@ -0,0 +1,10 @@
#\!/bin/bash
case "$1" in
version)
echo "1.0.0"
;;
*)
echo "Cross-platform test tool"
;;
esac
EOF < /dev/null

View File

@ -0,0 +1,9 @@
#\!/bin/bash
case "$1" in
version)
echo "1.0.0"
;;
*)
echo "Cross-platform test tool"
;;
esac

View File

@ -0,0 +1,9 @@
#\!/bin/bash
case "$1" in
version)
echo "1.0.0"
;;
*)
echo "Universal test tool"
;;
esac

View File

@ -0,0 +1,2 @@
#\!/bin/bash
echo "Universal test tool v1.0.0"