feat: filter daemon actions by kind; show registry release detail
This commit is contained in:
1 parent
624016d904
commit
691560a369
11 files changed
+228
-21
No files matched your search
+15
-4
@@ -1341,8 +1341,8 @@ std::string target_info_project(const DaemonOptions &options, std::string_view p
|
||||
// Lists the lowered graph's actions (bounded) for editor extensions and diagnostics.
|
||||
std::string actions_project(const DaemonOptions &options, std::string_view profile_name,
|
||||
std::optional<CompilerFamily> compiler_override,
|
||||
std::string_view target_filter, std::size_t limit,
|
||||
std::string_view member) {
|
||||
std::string_view target_filter, std::string_view kind_filter,
|
||||
std::size_t limit, std::string_view member) {
|
||||
auto effective_result = resolve_member_options(options, member);
|
||||
if (!effective_result) {
|
||||
return error_response(std::format("actions: {}", effective_result.error()));
|
||||
@@ -1363,6 +1363,9 @@ std::string actions_project(const DaemonOptions &options, std::string_view profi
|
||||
if (!target_filter.empty() && action.target_name != target_filter) {
|
||||
continue;
|
||||
}
|
||||
if (!kind_filter.empty() && action_kind_label(action.kind) != kind_filter) {
|
||||
continue;
|
||||
}
|
||||
++total;
|
||||
if (actions.size() >= limit) {
|
||||
continue;
|
||||
@@ -2372,6 +2375,14 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
}
|
||||
target_filter = *value;
|
||||
}
|
||||
std::string kind_filter;
|
||||
if (const auto entry = object->find("kind"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::string>(&entry->second.value);
|
||||
if (value == nullptr || value->size() > 64) {
|
||||
return {error_response("\"kind\" must be a bounded string"), false};
|
||||
}
|
||||
kind_filter = *value;
|
||||
}
|
||||
std::size_t limit = 100;
|
||||
if (const auto entry = object->find("limit"); entry != object->end()) {
|
||||
const auto *value = std::get_if<std::int64_t>(&entry->second.value);
|
||||
@@ -2383,8 +2394,8 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
|
||||
}
|
||||
limit = static_cast<std::size_t>(*value);
|
||||
}
|
||||
return {actions_project(options, profile_name, compiler_override, target_filter, limit,
|
||||
member),
|
||||
return {actions_project(options, profile_name, compiler_override, target_filter,
|
||||
kind_filter, limit, member),
|
||||
false};
|
||||
}
|
||||
if (*name == "target_info" || *name == "target_flags") {
|
||||
|
||||
+57
-14
@@ -1157,6 +1157,7 @@ int execute_publish_binary_command(const PublishBinaryCmdOptions &opts) {
|
||||
struct ReleasesCmdOptions {
|
||||
std::optional<std::string> registry_arg;
|
||||
std::optional<std::string> name_arg;
|
||||
std::optional<std::string> version_arg;
|
||||
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||
};
|
||||
|
||||
@@ -1182,6 +1183,29 @@ int execute_releases_list_command(const ReleasesCmdOptions &opts) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int execute_releases_show_command(const ReleasesCmdOptions &opts) {
|
||||
const std::string registry_url = opts.registry_arg
|
||||
? *opts.registry_arg
|
||||
: Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
|
||||
if (registry_url.empty() || !opts.name_arg || !opts.version_arg) {
|
||||
std::cerr << "vbs releases show: --registry, --name, and --version are required\n";
|
||||
return 2;
|
||||
}
|
||||
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
|
||||
auto release =
|
||||
Package::fetch_release_detail(registry_url, *opts.name_arg, *opts.version_arg, auth);
|
||||
if (!release) {
|
||||
std::cerr << "vbs releases show: " << release.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
std::cout << "name=" << release->name << " version=" << release->version
|
||||
<< " sha256=" << release->sha256 << " size=" << release->size_bytes
|
||||
<< " yanked=" << (release->yanked ? "true" : "false")
|
||||
<< " binaries=" << release->binary_count
|
||||
<< " signed=" << (release->signature && release->public_key ? "yes" : "no") << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct BinariesCmdOptions {
|
||||
std::optional<std::string> registry_arg;
|
||||
std::optional<std::string> name_arg;
|
||||
@@ -1534,6 +1558,7 @@ struct DaemonCmdOptions {
|
||||
std::optional<std::string> member_arg;
|
||||
std::string graph_format_arg{"dot"};
|
||||
std::optional<std::string> target_arg;
|
||||
std::optional<std::string> action_kind_arg;
|
||||
std::optional<std::string> pack_output_arg;
|
||||
std::optional<std::string> prefix_arg;
|
||||
std::optional<std::string> input_arg;
|
||||
@@ -1634,19 +1659,23 @@ int execute_daemon_command(std::string_view sub, const DaemonCmdOptions &opts) {
|
||||
Util::json_quote(opts.profile_arg),
|
||||
Util::json_quote(opts.graph_format_arg));
|
||||
} else if (sub == "actions") {
|
||||
request_json = std::format(R"({{"op":"actions","profile":{},"limit":{}}})",
|
||||
Util::json_quote(opts.profile_arg), opts.limit_arg);
|
||||
request_json = std::format(
|
||||
R"({{"op":"actions","profile":{},"limit":{}{}}})", Util::json_quote(opts.profile_arg),
|
||||
opts.limit_arg,
|
||||
opts.action_kind_arg
|
||||
? std::format(",\"kind\":{}", Util::json_quote(*opts.action_kind_arg))
|
||||
: std::string{});
|
||||
} else if (sub == "target_flags") {
|
||||
if (!opts.target_arg || opts.target_arg->empty()) {
|
||||
std::cerr << "vbs daemon target flags: --name must not be empty\n";
|
||||
return 2;
|
||||
}
|
||||
request_json = std::format(
|
||||
R"({{"op":"target_flags","profile":{},"target":{}{}}})",
|
||||
Util::json_quote(opts.profile_arg), Util::json_quote(*opts.target_arg),
|
||||
opts.file_filter_arg
|
||||
? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg))
|
||||
: std::string{});
|
||||
request_json =
|
||||
std::format(R"({{"op":"target_flags","profile":{},"target":{}{}}})",
|
||||
Util::json_quote(opts.profile_arg), Util::json_quote(*opts.target_arg),
|
||||
opts.file_filter_arg
|
||||
? std::format(",\"file\":{}", Util::json_quote(*opts.file_filter_arg))
|
||||
: std::string{});
|
||||
} else if (sub == "target_info") {
|
||||
if (!opts.target_arg || opts.target_arg->empty()) {
|
||||
std::cerr << "vbs daemon target: --name must not be empty\n";
|
||||
@@ -2527,6 +2556,16 @@ int main(int argc, char **argv) {
|
||||
releases_opts.token_env, "VBS_REGISTRY_TOKEN");
|
||||
add_log_flags(releases_list_cmd);
|
||||
|
||||
auto &releases_show_cmd = releases_cmd.subcommand("show", "Show one release's details");
|
||||
releases_show_cmd
|
||||
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
|
||||
releases_opts.registry_arg)
|
||||
.option("--name", "-n", "Package name", releases_opts.name_arg)
|
||||
.option("--version", "-v", "Release version", releases_opts.version_arg)
|
||||
.option_default("--token-env", "", "Environment variable holding bearer token",
|
||||
releases_opts.token_env, "VBS_REGISTRY_TOKEN");
|
||||
add_log_flags(releases_show_cmd, false); // `-v` is `--version` on releases show.
|
||||
|
||||
auto &binaries_cmd =
|
||||
root.subcommand("binaries", "Inspect prebuilt binary variants in a package registry");
|
||||
auto configure_binaries = [&](Void::Argparse::Parser &p) {
|
||||
@@ -2672,9 +2711,9 @@ int main(int argc, char **argv) {
|
||||
daemon_cmd.subcommand("describe", "Describe a project's build graph via the daemon");
|
||||
configure_daemon_common(daemon_describe_cmd);
|
||||
daemon_describe_cmd
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg,
|
||||
"debug")
|
||||
.option("--member", "", "Workspace member to describe (default: all)", daemon_opts.member_arg);
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
||||
.option("--member", "", "Workspace member to describe (default: all)",
|
||||
daemon_opts.member_arg);
|
||||
auto &daemon_build_cmd = daemon_cmd.subcommand("build", "Build a project graph via the daemon");
|
||||
configure_daemon_common(daemon_build_cmd);
|
||||
daemon_build_cmd
|
||||
@@ -2779,8 +2818,7 @@ int main(int argc, char **argv) {
|
||||
"flags", "Report one target's bounded compile arguments per unit");
|
||||
configure_daemon_common(daemon_target_flags_cmd);
|
||||
daemon_target_flags_cmd
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg,
|
||||
"debug")
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
||||
.option("--name", "-n", "Target name", daemon_opts.target_arg)
|
||||
.option("--file", "", "Only units whose source path ends with this value",
|
||||
daemon_opts.file_filter_arg);
|
||||
@@ -2793,7 +2831,9 @@ int main(int argc, char **argv) {
|
||||
daemon_cmd.subcommand("actions", "List lowered build actions via the daemon");
|
||||
configure_daemon_common(daemon_actions_cmd);
|
||||
daemon_actions_cmd
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg, "debug")
|
||||
.option_default("--profile", "-p", "Profile to evaluate", daemon_opts.profile_arg,
|
||||
"debug")
|
||||
.option("--kind", "", "Only actions of this kind (compile|link|archive|...)", daemon_opts.action_kind_arg)
|
||||
.option_default("--limit", "", "Maximum actions returned (0-1000)", daemon_opts.limit_arg,
|
||||
"100");
|
||||
auto &daemon_graph_cmd =
|
||||
@@ -2912,6 +2952,9 @@ int main(int argc, char **argv) {
|
||||
return execute_binaries_command(parsed.matched_command_path.at(1), binaries_opts);
|
||||
}
|
||||
if (cmd == "releases") {
|
||||
if (parsed.matched_command_path.at(1) == "show") {
|
||||
return execute_releases_show_command(releases_opts);
|
||||
}
|
||||
return execute_releases_list_command(releases_opts);
|
||||
}
|
||||
if (cmd == "bridge") {
|
||||
|
||||
@@ -558,6 +558,66 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na
|
||||
return variants;
|
||||
}
|
||||
|
||||
Void::Result::Result<ReleaseInfo, Void::Result::Error>
|
||||
fetch_release_detail(std::string_view registry_url, std::string_view package_name,
|
||||
std::string_view version, const RegistryAuth &auth) {
|
||||
auto parsed_url = parse_registry_url(registry_url);
|
||||
if (!parsed_url) {
|
||||
return std::unexpected{parsed_url.error()};
|
||||
}
|
||||
std::map<std::string, std::string, std::less<>> headers;
|
||||
if (!auth.bearer_token.empty()) {
|
||||
headers["Authorization"] = "Bearer " + auth.bearer_token;
|
||||
}
|
||||
const std::string path = "/api/v1/packages/" + Void::Encoding::Url::encode(package_name) + "/" +
|
||||
Void::Encoding::Url::encode(version);
|
||||
auto reply = send_http_request(*parsed_url, "GET", path, headers, {});
|
||||
if (!reply) {
|
||||
return std::unexpected{reply.error()};
|
||||
}
|
||||
if (reply->status != 200) {
|
||||
auto code = Void::System::SystemErrorCode::io_error;
|
||||
if (reply->status == 404) {
|
||||
code = Void::System::SystemErrorCode::not_found;
|
||||
} else if (reply->status == 401 || reply->status == 403) {
|
||||
code = Void::System::SystemErrorCode::permission_denied;
|
||||
}
|
||||
return std::unexpected{
|
||||
make_error(code, std::format("registry GET {} failed with HTTP {}: {}", path,
|
||||
reply->status, reply->body))};
|
||||
}
|
||||
auto json = Void::Json::Strict::parse(reply->body);
|
||||
if (!json) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"invalid JSON returned by registry release endpoint")};
|
||||
}
|
||||
const auto *root = std::get_if<JsonVal::Object>(&json->value);
|
||||
if (!root) {
|
||||
return std::unexpected{make_error(Void::System::SystemErrorCode::io_error,
|
||||
"registry response root must be a JSON object")};
|
||||
}
|
||||
|
||||
ReleaseInfo info;
|
||||
info.name = get_str(*root, "name");
|
||||
info.version = get_str(*root, "version");
|
||||
info.sha256 = get_str(*root, "sha256");
|
||||
info.size_bytes = static_cast<std::uint64_t>(get_i64(*root, "size_bytes", 0));
|
||||
info.yanked = get_bool(*root, "yanked", false);
|
||||
if (const auto sig = get_str(*root, "signature"); !sig.empty()) {
|
||||
info.signature = sig;
|
||||
}
|
||||
if (const auto key = get_str(*root, "public_key"); !key.empty()) {
|
||||
info.public_key = key;
|
||||
}
|
||||
const auto bit = root->find("binaries");
|
||||
if (bit != root->end()) {
|
||||
if (const auto *binaries = std::get_if<JsonVal::Array>(&bit->second.value)) {
|
||||
info.binary_count = binaries->size();
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::vector<std::string>, Void::Result::Error>
|
||||
fetch_package_owners(std::string_view registry_url, std::string_view package_name,
|
||||
const RegistryAuth &auth) {
|
||||
|
||||
Reference in new issue
Block a user