aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/brep-module.conf8
-rw-r--r--etc/private/install/brep-module.conf8
-rw-r--r--libbrep/utility.hxx5
-rw-r--r--manifest6
-rw-r--r--mod/mod-build-configs.cxx6
-rw-r--r--mod/mod-builds.cxx6
-rw-r--r--mod/mod-ci-github-gq.cxx93
-rw-r--r--mod/mod-ci-github-gq.hxx36
-rw-r--r--mod/mod-ci-github-service-data.hxx13
-rw-r--r--mod/mod-ci-github.cxx195
-rw-r--r--mod/mod-ci-github.hxx7
-rw-r--r--mod/mod-ci.cxx48
-rw-r--r--mod/mod-submit.cxx10
-rw-r--r--mod/module.cli10
14 files changed, 325 insertions, 126 deletions
diff --git a/etc/brep-module.conf b/etc/brep-module.conf
index fd6ba67..cdf028a 100644
--- a/etc/brep-module.conf
+++ b/etc/brep-module.conf
@@ -454,13 +454,15 @@ menu About=?about
# The GitHub App's configured webhook secret. If not set, then the GitHub CI
-# service is disabled. Note: make sure to choose a strong (random) secret.
+# service is disabled. Note that the path must be absolute. Note: make sure to
+# choose a strong (random) secret.
#
-# ci-github-app-webhook-secret
+# ci-github-app-webhook-secret <path>
# The private key used during GitHub API authentication for the specified
-# GitHub App ID. Both vales are found in the GitHub App's settings.
+# GitHub App ID. Both vales are found in the GitHub App's settings. Note that
+# the paths must be absolute.
#
# ci-github-app-id-private-key <id>=<path>
diff --git a/etc/private/install/brep-module.conf b/etc/private/install/brep-module.conf
index 07db881..2545a87 100644
--- a/etc/private/install/brep-module.conf
+++ b/etc/private/install/brep-module.conf
@@ -462,13 +462,15 @@ submit-handler-timeout 120
# The GitHub App's configured webhook secret. If not set, then the GitHub CI
-# service is disabled. Note: make sure to choose a strong (random) secret.
+# service is disabled. Note that the path must be absolute. Note: make sure to
+# choose a strong (random) secret.
#
-# ci-github-app-webhook-secret
+# ci-github-app-webhook-secret <path>
# The private key used during GitHub API authentication for the specified
-# GitHub App ID. Both vales are found in the GitHub App's settings.
+# GitHub App ID. Both vales are found in the GitHub App's settings. Note that
+# the paths must be absolute.
#
# ci-github-app-id-private-key <id>=<path>
diff --git a/libbrep/utility.hxx b/libbrep/utility.hxx
index fce8fb5..1925d01 100644
--- a/libbrep/utility.hxx
+++ b/libbrep/utility.hxx
@@ -12,7 +12,7 @@
#include <algorithm> // *
#include <libbutl/utility.hxx> // icasecmp(), reverse_iterate(),
- // operator<<(ostream, exception)
+ // operator<<(ostream, exception), etc
namespace brep
{
@@ -28,6 +28,9 @@ namespace brep
// <libbutl/utility.hxx>
//
using butl::utf8;
+ using butl::trim;
+ using butl::trim_left;
+ using butl::trim_right;
using butl::icasecmp;
using butl::reverse_iterate;
}
diff --git a/manifest b/manifest
index 720f35e..7681a23 100644
--- a/manifest
+++ b/manifest
@@ -24,9 +24,9 @@ depends: libapr1
depends: libapreq2
depends: libcmark-gfm == 0.29.0-a.4
depends: libcmark-gfm-extensions == 0.29.0-a.4
-depends: libstudxml ^1.1.0-b.10
-depends: libodb ^2.5.0-b.27
-depends: libodb-pgsql ^2.5.0-b.27
+depends: libstudxml ^1.1.0
+depends: libodb ^2.5.0
+depends: libodb-pgsql ^2.5.0
depends: libbutl [0.18.0-a.0.1 0.18.0-a.1)
depends: libbpkg [0.18.0-a.0.1 0.18.0-a.1)
depends: libbbot [0.18.0-a.0.1 0.18.0-a.1)
diff --git a/mod/mod-build-configs.cxx b/mod/mod-build-configs.cxx
index ce79edb..2754f95 100644
--- a/mod/mod-build-configs.cxx
+++ b/mod/mod-build-configs.cxx
@@ -34,10 +34,12 @@ init (scanner& s)
s, unknown_mode::fail, unknown_mode::fail);
if (options_->build_config_specified ())
+ {
build_config_module::init (*options_);
- if (options_->root ().empty ())
- options_->root (dir_path ("/"));
+ if (options_->root ().empty ())
+ options_->root (dir_path ("/"));
+ }
}
bool brep::build_configs::
diff --git a/mod/mod-builds.cxx b/mod/mod-builds.cxx
index 0155c2e..b11b3d7 100644
--- a/mod/mod-builds.cxx
+++ b/mod/mod-builds.cxx
@@ -58,10 +58,10 @@ init (scanner& s)
{
database_module::init (*options_, options_->build_db_retry ());
build_config_module::init (*options_);
- }
- if (options_->root ().empty ())
- options_->root (dir_path ("/"));
+ if (options_->root ().empty ())
+ options_->root (dir_path ("/"));
+ }
}
template <typename T, typename C>
diff --git a/mod/mod-ci-github-gq.cxx b/mod/mod-ci-github-gq.cxx
index db69f0c..2afad81 100644
--- a/mod/mod-ci-github-gq.cxx
+++ b/mod/mod-ci-github-gq.cxx
@@ -380,9 +380,11 @@ namespace brep
assert (cr.state != build_state::built); // Not supported.
- // Ensure details URL is non-empty if present.
+ // Ensure details URL and output are non-empty if present.
//
assert (!cr.details_url || !cr.details_url->empty ());
+ assert (!cr.output ||
+ (!cr.output->title.empty () && !cr.output->summary.empty ()));
string al ("cr" + to_string (i)); // Field alias.
@@ -396,6 +398,13 @@ namespace brep
os << '\n';
os << " detailsUrl: " << gq_str (*cr.details_url);
}
+ if (cr.output)
+ {
+ os << " output: {" << '\n'
+ << " title: " << gq_str (cr.output->title) << '\n'
+ << " summary: " << gq_str (cr.output->summary) << '\n'
+ << " }";
+ }
os << "})" << '\n'
// Specify the selection set (fields to be returned). Note that we
// rename `id` to `node_id` (using a field alias) for consistency with
@@ -417,9 +426,9 @@ namespace brep
// Serialize a `createCheckRun` mutation for a build to GraphQL.
//
- // The build result argument (`br`) is required if the build_state is built
- // because GitHub does not allow a check run status of completed without a
- // conclusion.
+ // The conclusion argument (`co`) is required if the check run status is
+ // completed because GitHub does not allow a check run status of completed
+ // without a conclusion.
//
// The details URL argument (`du`) can be empty for queued but not for the
// other states.
@@ -433,12 +442,18 @@ namespace brep
const optional<string>& du, // Details URL.
const check_run& cr,
const string& st, // Check run status.
- optional<gq_built_result> br = nullopt)
+ const string& ti, // Output title.
+ const string& su, // Output summary.
+ optional<string> co = nullopt) // Conclusion.
{
// Ensure details URL is non-empty if present.
//
assert (!du || !du->empty ());
+ // Ensure we have conclusion if the status is completed.
+ //
+ assert (st != "COMPLETED" || co);
+
ostringstream os;
os << "mutation {" << '\n';
@@ -455,15 +470,13 @@ namespace brep
os << '\n';
os << " detailsUrl: " << gq_str (*du);
}
- if (br)
- {
- os << '\n';
- os << " conclusion: " << gq_enum (br->conclusion) << '\n'
- << " output: {" << '\n'
- << " title: " << gq_str (br->title) << '\n'
- << " summary: " << gq_str (br->summary) << '\n'
- << " }";
- }
+ os << '\n';
+ if (co)
+ os << " conclusion: " << gq_enum (*co) << '\n';
+ os << " output: {" << '\n'
+ << " title: " << gq_str (ti) << '\n'
+ << " summary: " << gq_str (su) << '\n'
+ << " }";
os << "})" << '\n'
// Specify the selection set (fields to be returned). Note that we
// rename `id` to `node_id` (using a field alias) for consistency with
@@ -485,7 +498,7 @@ namespace brep
// Serialize an `updateCheckRun` mutation for one build to GraphQL.
//
- // The `co` (conclusion) argument is required if the build_state is built
+ // The `br` argument is required if the check run status is completed
// because GitHub does not allow updating a check run to completed without a
// conclusion.
//
@@ -495,14 +508,11 @@ namespace brep
static string
gq_mutation_update_check_run (const string& ri, // Repository ID.
const string& ni, // Node ID.
- const optional<string>& du, // Details URL.
const string& st, // Check run status.
optional<timestamp> sa, // Started at.
optional<gq_built_result> br)
{
- // Ensure details URL is non-empty if present.
- //
- assert (!du || !du->empty ());
+ assert (st != "COMPLETED" || br);
ostringstream os;
@@ -527,11 +537,6 @@ namespace brep
": " + e.what ());
}
}
- if (du)
- {
- os << '\n';
- os << " detailsUrl: " << gq_str (*du);
- }
if (br)
{
os << '\n';
@@ -586,11 +591,11 @@ namespace brep
const string& hs,
const optional<string>& du,
build_state st,
- optional<gq_built_result> br)
+ string ti, string su)
{
- // Must have a result if state is built.
+ // State cannot be built without a conclusion.
//
- assert (st != build_state::built || br);
+ assert (st != build_state::built && !ti.empty () && !su.empty ());
string rq (
gq_serialize_request (
@@ -599,7 +604,8 @@ namespace brep
du,
cr,
gh_to_status (st),
- move (br))));
+ move (ti), move (su),
+ nullopt /* conclusion */)));
vector<check_run> crs {move (cr)};
crs[0].state = st;
@@ -612,12 +618,40 @@ namespace brep
}
bool
+ gq_create_check_run (const basic_mark& error,
+ check_run& cr,
+ const string& iat,
+ const string& rid,
+ const string& hs,
+ const optional<string>& du,
+ gq_built_result br)
+ {
+ string rq (
+ gq_serialize_request (
+ gq_mutation_create_check_run (rid,
+ hs,
+ du,
+ cr,
+ gh_to_status (build_state::built),
+ move (br.title), move (br.summary),
+ move (br.conclusion))));
+
+ vector<check_run> crs {move (cr)};
+ crs[0].state = build_state::built;
+
+ bool r (gq_mutate_check_runs (error, crs, iat, move (rq)));
+
+ cr = move (crs[0]);
+
+ return r;
+ }
+
+ bool
gq_update_check_run (const basic_mark& error,
check_run& cr,
const string& iat,
const string& rid,
const string& nid,
- const optional<string>& du,
build_state st,
optional<gq_built_result> br)
{
@@ -636,7 +670,6 @@ namespace brep
gq_serialize_request (
gq_mutation_update_check_run (rid,
nid,
- du,
gh_to_status (st),
sa,
move (br))));
diff --git a/mod/mod-ci-github-gq.hxx b/mod/mod-ci-github-gq.hxx
index 50950d4..0fc3817 100644
--- a/mod/mod-ci-github-gq.hxx
+++ b/mod/mod-ci-github-gq.hxx
@@ -20,7 +20,7 @@ namespace brep
//
// Create a new check run on GitHub for each build with the build state,
- // name, and details_url taken from each check_run object. Update
+ // name, details_url, and output taken from each check_run object. Update
// `check_runs` with the new data (node id and state_synced). Return false
// and issue diagnostics if the request failed.
//
@@ -39,18 +39,32 @@ namespace brep
const string& repository_id,
const string& head_sha);
- // Create a new check run on GitHub for a build. Update `cr` with the new
- // data (node id, state, and state_synced). Return false and issue
- // diagnostics if the request failed.
+ // Create a new check run on GitHub for a build in the queued or building
+ // state. Note that the state cannot be built because in that case a
+ // conclusion is required.
+ //
+ // Update `cr` with the new data (node id, state, and state_synced). Return
+ // false and issue diagnostics if the request failed.
//
// Throw invalid_argument if the passed data is invalid, missing, or
// inconsistent.
//
- // If the details_url is absent GitHub will use the app's homepage.
+ // If the details_url is absent GitHub will use the app's homepage. Title
+ // and summary are required and cannot be empty.
//
- // The gq_built_result is required if the build_state is built because
- // GitHub does not allow a check run status of `completed` without at least
- // a conclusion.
+ bool
+ gq_create_check_run (const basic_mark& error,
+ check_run& cr,
+ const string& installation_access_token,
+ const string& repository_id,
+ const string& head_sha,
+ const optional<string>& details_url,
+ build_state,
+ string title,
+ string summary);
+
+ // As above but create a check run in the built state (which requires a
+ // conclusion).
//
struct gq_built_result
{
@@ -66,8 +80,7 @@ namespace brep
const string& repository_id,
const string& head_sha,
const optional<string>& details_url,
- build_state,
- optional<gq_built_result> = nullopt);
+ gq_built_result);
// Update a check run on GitHub. Update `cr` with the new data (state and
// state_synced). Return false and issue diagnostics if the request failed.
@@ -79,8 +92,6 @@ namespace brep
// built to built is allowed). The latter case is signalled by setting the
// check_run state_synced member to false and the state member to built.
//
- // If the details_url is absent GitHub will use the app's homepage.
- //
// The gq_built_result is required if the build_state is built because
// GitHub does not allow a check run status of `completed` without at least
// a conclusion.
@@ -91,7 +102,6 @@ namespace brep
const string& installation_access_token,
const string& repository_id,
const string& node_id,
- const optional<string>& details_url,
build_state,
optional<gq_built_result> = nullopt);
diff --git a/mod/mod-ci-github-service-data.hxx b/mod/mod-ci-github-service-data.hxx
index 50bb49d..5d36696 100644
--- a/mod/mod-ci-github-service-data.hxx
+++ b/mod/mod-ci-github-service-data.hxx
@@ -33,10 +33,17 @@ namespace brep
optional<result_status> status; // Only if state is built & synced.
- // Note: never serialized (only used to pass information to the GraphQL
- // functions).
+ // Note: these are never serialized (only used to pass information to the
+ // GraphQL functions).
//
- optional<string> details_url;
+ struct description_type
+ {
+ string title;
+ string summary;
+ };
+
+ optional<string> details_url;
+ optional<description_type> description;
string
state_string () const
diff --git a/mod/mod-ci-github.cxx b/mod/mod-ci-github.cxx
index 44de247..aec5e5e 100644
--- a/mod/mod-ci-github.cxx
+++ b/mod/mod-ci-github.cxx
@@ -77,12 +77,45 @@ namespace brep
// Prepare for the CI requests handling, if configured.
//
- if (options_->build_config_specified () &&
- options_->ci_github_app_webhook_secret_specified ())
+ if (options_->ci_github_app_webhook_secret_specified ())
{
+ if (!options_->build_config_specified ())
+ fail << "package building functionality must be enabled";
+
if (!options_->ci_github_app_id_private_key_specified ())
fail << "no app id/private key mappings configured";
+ for (const auto& pr: options_->ci_github_app_id_private_key ())
+ {
+ if (pr.second.relative ())
+ fail << "ci-github-app-id-private-key path must be absolute";
+ }
+
+ // Read the webhook secret from the configured path.
+ //
+ {
+ const path& p (options_->ci_github_app_webhook_secret ());
+
+ if (p.relative ())
+ fail << "ci-github-app-webhook-secret path must be absolute";
+
+ try
+ {
+ ifdstream is (p);
+ getline (is, webhook_secret_, '\0');
+
+ // Trim leading/trailing whitespaces (presumably GitHub does the
+ // same in its web UI).
+ //
+ if (trim (webhook_secret_).empty ())
+ fail << "empty webhook secret in " << p;
+ }
+ catch (const io_error& e)
+ {
+ fail << "unable to read webhook secret from " << p << ": " << e;
+ }
+ }
+
ci_start::init (make_shared<options::ci_start> (*options_));
database_module::init (*options_, options_->build_db_retry ());
@@ -207,10 +240,10 @@ namespace brep
//
try
{
- string h (
- compute_hmac (*options_,
- body.data (), body.size (),
- options_->ci_github_app_webhook_secret ().c_str ()));
+ string h (compute_hmac (*options_,
+ body.data (),
+ body.size (),
+ webhook_secret_.c_str ()));
if (!icasecmp (h, hmac))
{
@@ -546,6 +579,10 @@ namespace brep
//
static string conclusion_check_run_name ("CONCLUSION");
+ static check_run::output_type conclusion_check_run_building_output {
+ "\U000026AA IN PROGRESS", // "Medium white" circle.
+ "Waiting for all builds to complete"};
+
bool ci_github::
handle_branch_push (gh_push_event ps, bool warning_success)
{
@@ -1124,8 +1161,14 @@ namespace brep
static gq_built_result
make_built_result (result_status rs, bool warning_success, string message)
{
+ string title (circle (rs == result_status::warning && !warning_success
+ ? result_status::error
+ : rs));
+ title += ' ';
+ title += ucase (to_string (rs));
+
return {gh_to_conclusion (rs, warning_success),
- circle (rs) + ' ' + ucase (to_string (rs)),
+ move (title),
move (message)};
}
@@ -1286,7 +1329,6 @@ namespace brep
if (gq_update_check_run (error, bcr, iat->token,
repo_node_id, cr.check_run.node_id,
- nullopt /* details_url */,
build_state::built, br))
{
l3 ([&]{trace << "updated check_run { " << bcr << " }";});
@@ -1300,7 +1342,6 @@ namespace brep
if (gq_update_check_run (error, ccr, iat->token,
repo_node_id, *sd.conclusion_node_id,
- nullopt /* details_url */,
build_state::built, move (br)))
{
l3 ([&]{trace << "updated conclusion check_run { " << ccr << " }";});
@@ -1349,7 +1390,6 @@ namespace brep
//
if (gq_update_check_run (error, ccr, iat->token,
repo_node_id, *sd.conclusion_node_id,
- nullopt /* details_url */,
build_state::built, move (br)))
{
l3 ([&]{trace << "updated conclusion check_run { " << ccr << " }";});
@@ -1430,6 +1470,8 @@ namespace brep
ccr.state = build_state::building;
ccr.state_synced = false;
+ ccr.details_url = details_url (tenant_id);
+ ccr.output = conclusion_check_run_building_output;
if (gq_create_check_runs (error, check_runs, iat->token,
repo_node_id, head_sha))
@@ -1580,7 +1622,6 @@ namespace brep
//
if (gq_update_check_run (error, bcr, iat->token,
repo_node_id, *bcr.node_id,
- nullopt /* details_url */,
build_state::built, br))
{
l3 ([&]{trace << "updated check_run { " << bcr << " }";});
@@ -1597,7 +1638,6 @@ namespace brep
//
if (gq_update_check_run (error, ccr, iat->token,
repo_node_id, *ccr.node_id,
- nullopt /* details_url */,
build_state::built, move (br)))
{
l3 ([&]{trace << "updated conclusion check_run { " << ccr << " }";});
@@ -1896,9 +1936,13 @@ namespace brep
// Create a synthetic check run with an in-progress state. Return the
// check run on success or nullopt on failure.
//
- auto create_synthetic_cr = [iat,
+ auto create_synthetic_cr = [&tenant_id,
+ iat,
&sd,
- &error] (string name) -> optional<check_run>
+ &error,
+ this] (string name,
+ const check_run::output_type& output)
+ -> optional<check_run>
{
check_run cr;
cr.name = move (name);
@@ -1910,8 +1954,9 @@ namespace brep
iat->token,
sd.repository_node_id,
sd.report_sha,
- nullopt /* details_url */,
- build_state::building))
+ details_url (tenant_id),
+ build_state::building,
+ output.title, output.summary))
{
return cr;
}
@@ -1946,7 +1991,6 @@ namespace brep
iat->token,
sd.repository_node_id,
node_id,
- nullopt /* details_url */,
build_state::built,
move (br)))
{
@@ -1969,7 +2013,8 @@ namespace brep
if (!sd.conclusion_node_id)
{
- if (auto cr = create_synthetic_cr (conclusion_check_run_name))
+ if (auto cr = create_synthetic_cr (conclusion_check_run_name,
+ conclusion_check_run_building_output))
{
l3 ([&]{trace << "created check_run { " << *cr << " }";});
@@ -2270,7 +2315,7 @@ namespace brep
build_state::queued,
false /* state_synced */,
nullopt /* status */,
- nullopt /* details_url */});
+ details_url (b)});
}
}
@@ -2474,7 +2519,6 @@ namespace brep
iat->token,
sd.repository_node_id,
*cr->node_id,
- details_url (b),
build_state::building))
{
// Do nothing further if the state was already built on GitHub (note
@@ -2589,8 +2633,51 @@ namespace brep
//
optional<result_status> conclusion (*b.status);
+ // Conclusion check run summary. Will include the success/warning/failure
+ // count breakdown.
+ //
+ string summary;
+
check_run cr; // Updated check run.
{
+ // The success/warning/failure counts.
+ //
+ // Note that the warning count will be included in the success or
+ // failure count (depending on the value of sd.warning_success).
+ //
+ size_t succ_count (0), warn_count (0), fail_count (0);
+
+ // Count a result_status under the appropriate category.
+ //
+ auto count = [&succ_count,
+ &warn_count,
+ &fail_count,
+ ws = sd.warning_success] (result_status rs)
+ {
+ switch (rs)
+ {
+ case result_status::success: ++succ_count; break;
+
+ case result_status::error:
+ case result_status::abort:
+ case result_status::abnormal: ++fail_count; break;
+
+ case result_status::warning:
+ {
+ ++warn_count;
+
+ if (ws)
+ ++succ_count;
+ else
+ ++fail_count;
+
+ break;
+ }
+ }
+ };
+
+ count (*b.status);
+
string bid (gh_check_run_name (b)); // Full build id.
optional<check_run> scr;
@@ -2609,6 +2696,8 @@ namespace brep
if (conclusion)
*conclusion |= *cr.status;
+
+ count (*cr.status);
}
else
conclusion = nullopt;
@@ -2646,6 +2735,29 @@ namespace brep
}
cr.state_synced = false;
+
+ // Construct the conclusion check run summary if all check runs are
+ // built.
+ //
+ if (conclusion)
+ {
+ ostringstream os;
+
+ // Note: the warning count has already been included in the success or
+ // failure count.
+ //
+ os << fail_count << " failed";
+ if (!sd.warning_success && warn_count != 0)
+ os << " (" << warn_count << " due to warnings)";
+
+ os << ", " << succ_count << " succeeded";
+ if (sd.warning_success && warn_count != 0)
+ os << " (" << warn_count << " with warnings)";
+
+ os << ", " << (succ_count + fail_count) << " total";
+
+ summary = os.str ();
+ }
}
// Get a new installation access token if the current one has expired.
@@ -2790,7 +2902,6 @@ namespace brep
iat->token,
sd.repository_node_id,
*cr.node_id,
- details_url (b),
build_state::built,
move (br)))
{
@@ -2814,7 +2925,6 @@ namespace brep
sd.repository_node_id,
sd.report_sha,
details_url (b),
- build_state::built,
move (br)))
{
assert (cr.state == build_state::built);
@@ -2838,8 +2948,7 @@ namespace brep
result_status rs (*conclusion);
gq_built_result br (
- make_built_result (rs, sd.warning_success,
- "All configurations are built"));
+ make_built_result (rs, sd.warning_success, move (summary)));
check_run cr;
@@ -2855,7 +2964,6 @@ namespace brep
iat->token,
sd.repository_node_id,
*sd.conclusion_node_id,
- nullopt /* details_url */,
build_state::built,
move (br)))
{
@@ -2975,10 +3083,11 @@ namespace brep
{
// This code is based on build_force_url() in mod/build.cxx.
//
- return options_->host () +
- "/@" + b.tenant +
+ return
+ options_->host () +
+ tenant_dir (options_->root (), b.tenant).string () +
"?builds=" + mime_url_encode (b.package_name.string ()) +
- "&pv=" + b.package_version.string () +
+ "&pv=" + mime_url_encode (b.package_version.string ()) +
"&tg=" + mime_url_encode (b.target.string ()) +
"&tc=" + mime_url_encode (b.target_config_name) +
"&pc=" + mime_url_encode (b.package_config_name) +
@@ -2986,6 +3095,15 @@ namespace brep
b.toolchain_version.string ();
}
+ string ci_github::
+ details_url (const string& t) const
+ {
+ return
+ options_->host () +
+ tenant_dir (options_->root (), t).string () +
+ "?builds";
+ }
+
static optional<build_id>
parse_details_url (const string& details_url)
try
@@ -2998,12 +3116,21 @@ namespace brep
// Extract the tenant from the URL path.
//
- // Example path: @d2586f57-21dc-40b7-beb2-6517ad7917dd
+ // Example paths:
+ //
+ // @d2586f57-21dc-40b7-beb2-6517ad7917dd (37 characters)
+ // <brep-root>/@d2586f57-21dc-40b7-beb2-6517ad7917dd
//
- if (!u.path || u.path->size () != 37 || (*u.path)[0] != '@')
+ if (!u.path)
return nullopt;
- r.package.tenant = u.path->substr (1);
+ {
+ size_t p (u.path->find ('@'));
+ if (p == string::npos || u.path->size () - p != 37)
+ return nullopt; // Tenant not found or too short.
+
+ r.package.tenant = u.path->substr (p + 1);
+ }
// Extract the rest of the build_id members from the URL query.
//
@@ -3046,7 +3173,7 @@ namespace brep
};
if (c (pn, "builds")) r.package.name = package_name (decval ());
- else if (c (pv, "pv")) r.package.version = make_version (rawval ());
+ else if (c (pv, "pv")) r.package.version = make_version (decval ());
else if (c (tg, "tg")) r.target = target_triplet (decval ());
else if (c (tc, "tc")) r.target_config_name = decval ();
else if (c (pc, "pc")) r.package_config_name = decval ();
@@ -3058,8 +3185,8 @@ namespace brep
// Note: parsing code based on mod/mod-builds.cxx.
//
- size_t p (v.find_first_of ('-'));
- if (p >= v.size () - 1)
+ size_t p (v.find ('-'));
+ if (p == string::npos || p >= v.size () - 1)
return nullopt; // Invalid format.
r.toolchain_name = v.substr (0, p);
diff --git a/mod/mod-ci-github.hxx b/mod/mod-ci-github.hxx
index 4fcfa7e..c21d3db 100644
--- a/mod/mod-ci-github.hxx
+++ b/mod/mod-ci-github.hxx
@@ -127,6 +127,11 @@ namespace brep
string
details_url (const build&) const;
+ // Build a check run details_url for a tenant.
+ //
+ string
+ details_url (const string& tenant) const;
+
optional<string>
generate_jwt (const string& app_id,
const basic_mark& trace,
@@ -145,6 +150,8 @@ namespace brep
shared_ptr<options::ci_github> options_;
tenant_service_map& tenant_service_map_;
+
+ string webhook_secret_;
};
}
diff --git a/mod/mod-ci.cxx b/mod/mod-ci.cxx
index 46fbf6a..16ec5a7 100644
--- a/mod/mod-ci.cxx
+++ b/mod/mod-ci.cxx
@@ -105,17 +105,17 @@ init (scanner& s)
fail << "unable to read ci-form file '" << ci_form << "': " << e;
}
}
- }
#ifdef BREP_CI_TENANT_SERVICE_UNLOADED
- if (!options_->build_config_specified ())
- fail << "package building functionality must be enabled";
+ if (!options_->build_config_specified ())
+ fail << "package building functionality must be enabled";
- database_module::init (*options_, options_->build_db_retry ());
+ database_module::init (*options_, options_->build_db_retry ());
#endif
- if (options_->root ().empty ())
- options_->root (dir_path ("/"));
+ if (options_->root ().empty ())
+ options_->root (dir_path ("/"));
+ }
}
bool brep::ci::
@@ -131,8 +131,6 @@ handle (request& rq, response& rs)
HANDLER_DIAG;
- const dir_path& root (options_->root ());
-
// We will respond with the manifest to the CI request submission protocol
// violations and with a plain text message on the internal errors. In the
// latter case we will always respond with the same neutral message for
@@ -180,6 +178,8 @@ handle (request& rq, response& rs)
if (!options_->ci_data_specified ())
return respond_manifest (404, "CI request submission disabled");
+ const dir_path& root (options_->root ());
+
// Parse the request form data and verify the submission size limit.
//
// Note that the submission may include the overrides upload that we don't
@@ -387,18 +387,19 @@ handle (request& rq, response& rs)
optional<start_result> r;
- if (optional<string> ref = create (error,
- warn,
- verb_ ? &trace : nullptr,
- *build_db_,
- tenant_service ("", "ci", rl.string ()),
- chrono::seconds (40),
- chrono::seconds (10)))
+ if (optional<pair<string, duplicate_tenant_result>> ref =
+ create (error,
+ warn,
+ verb_ ? &trace : nullptr,
+ *build_db_, retry_,
+ tenant_service ("", "ci", rl.string ()),
+ chrono::seconds (40),
+ chrono::seconds (10)))
{
string msg ("unloaded CI request is created: " +
- options_->host () + tenant_dir (root, *ref).string ());
+ options_->host () + tenant_dir (root, ref->first).string ());
- r = start_result {200, move (msg), move (*ref), {}};
+ r = start_result {200, move (msg), move (ref->first), {}};
}
#endif
@@ -519,8 +520,10 @@ build_built (const string& /*tenant_id*/,
}
#ifdef BREP_CI_TENANT_SERVICE_UNLOADED
-function<optional<string> (const brep::tenant_service&)> brep::ci::
-build_unloaded (tenant_service&& ts,
+function<optional<string> (const string& tenant_id,
+ const brep::tenant_service&)> brep::ci::
+build_unloaded (const string& /* tenant_id */,
+ tenant_service&& ts,
const diag_epilogue& log_writer) const noexcept
{
NOTIFICATION_DIAG (log_writer);
@@ -532,7 +535,7 @@ build_unloaded (tenant_service&& ts,
repository_location rl (*ts.data);
if (!load (error, warn, verb_ ? &trace : nullptr,
- *build_db_,
+ *build_db_, retry_,
move (ts),
rl))
return nullptr; // The diagnostics is already issued.
@@ -545,7 +548,10 @@ build_unloaded (tenant_service&& ts,
return nullptr;
}
- return [] (const tenant_service& ts) {return "loaded " + *ts.data;};
+ return [] (const string& tenant_id, const tenant_service& ts)
+ {
+ return "loaded " + tenant_id + ' ' + *ts.data;
+ };
}
#endif
#endif
diff --git a/mod/mod-submit.cxx b/mod/mod-submit.cxx
index 5ee358a..6c767cb 100644
--- a/mod/mod-submit.cxx
+++ b/mod/mod-submit.cxx
@@ -93,10 +93,10 @@ init (scanner& s)
if (options_->submit_handler_specified () &&
options_->submit_handler ().relative ())
fail << "submit-handler path must be absolute";
- }
- if (options_->root ().empty ())
- options_->root (dir_path ("/"));
+ if (options_->root ().empty ())
+ options_->root (dir_path ("/"));
+ }
}
bool brep::submit::
@@ -109,8 +109,6 @@ handle (request& rq, response& rs)
HANDLER_DIAG;
- const dir_path& root (options_->root ());
-
// We will respond with the manifest to the submission protocol violations
// and with a plain text message on the internal errors. In the latter case
// we will always respond with the same neutral message for security reason,
@@ -163,6 +161,8 @@ handle (request& rq, response& rs)
if (!options_->submit_data_specified ())
return respond_manifest (404, "submission disabled");
+ const dir_path& root (options_->root ());
+
// Parse the request form data and verify the submission size limit.
//
// Note that if it is exceeded, then there are parameters and this is the
diff --git a/mod/module.cli b/mod/module.cli
index 1273bf4..ba2b986 100644
--- a/mod/module.cli
+++ b/mod/module.cli
@@ -850,12 +850,12 @@ namespace brep
// GitHub CI-specific options.
//
- string ci-github-app-webhook-secret
+ path ci-github-app-webhook-secret
{
- "<secret>",
+ "<path>",
"The GitHub App's configured webhook secret. If not set, then the
- GitHub CI service is disabled. Note: make sure to choose a strong
- (random) secret."
+ GitHub CI service is disabled. Note that the path must be absolute.
+ Note: make sure to choose a strong (random) secret."
}
std::map<string, dir_path> ci-github-app-id-private-key
@@ -863,7 +863,7 @@ namespace brep
"<id>=<path>",
"The private key used during GitHub API authentication for the
specified GitHub App ID. Both vales are found in the GitHub App's
- settings."
+ settings. Note that the paths must be absolute."
}
uint16_t ci-github-jwt-validity-period = 600