aboutsummaryrefslogtreecommitdiff
path: root/mod/mod-ci-github.cxx
diff options
context:
space:
mode:
authorFrancois Kritzinger <francois@codesynthesis.com>2024-12-12 14:22:18 +0200
committerFrancois Kritzinger <francois@codesynthesis.com>2024-12-13 11:09:58 +0200
commit4108a65af34829c5dd7e350ca1058eb4e0e4eee4 (patch)
treecc8e84e64951172a168f3633361e601bb256dc8d /mod/mod-ci-github.cxx
parentd50e2ae861180d6f965b0c4dee4d401d01f571b5 (diff)
ci-github: Cancel CI when history is overwritten
Cancel CI for previous, now-overwritten head commit when a forced push is done.
Diffstat (limited to 'mod/mod-ci-github.cxx')
-rw-r--r--mod/mod-ci-github.cxx66
1 files changed, 66 insertions, 0 deletions
diff --git a/mod/mod-ci-github.cxx b/mod/mod-ci-github.cxx
index 721c047..0f9a926 100644
--- a/mod/mod-ci-github.cxx
+++ b/mod/mod-ci-github.cxx
@@ -494,6 +494,27 @@ namespace brep
return true;
}
}
+ else if (event == "push")
+ {
+ gh_push_event ps;
+ try
+ {
+ json::parser p (body.data (), body.size (), "push event");
+
+ ps = gh_push_event (p);
+ }
+ catch (const json::invalid_json_input& e)
+ {
+ string m ("malformed JSON in " + e.name + " request body");
+
+ error << m << ", line: " << e.line << ", column: " << e.column
+ << ", byte offset: " << e.position << ", error: " << e;
+
+ throw invalid_request (400, move (m));
+ }
+
+ return handle_push_request (move (ps));
+ }
else
{
// Log to investigate.
@@ -1465,6 +1486,51 @@ namespace brep
return true;
}
+ bool ci_github::
+ handle_push_request (gh_push_event ps)
+ {
+ HANDLER_DIAG;
+
+ l3 ([&]{trace << "push event { " << ps << " }";});
+
+ // Do nothing if this is a fast-forwarding push.
+ //
+ if (!ps.forced)
+ {
+ l3 ([&]{trace << "ignoring fast-forward push "
+ << ps.after << " to " << ps.ref;});
+ return true;
+ }
+
+ // Cancel the CI tenant associated with the overwritten previous head
+ // commit.
+
+ // Service id that will uniquely identify the CI tenant.
+ //
+ string sid (ps.repository.node_id + ':' + ps.before);
+
+ if (optional<tenant_service> ts = cancel (error, warn,
+ verb_ ? &trace : nullptr,
+ *build_db_, retry_,
+ "ci-github", sid))
+ {
+ l3 ([&]{trace << "forced push to " << ps.ref
+ << ": canceled CI of previous head commit"
+ << " with tenant_service id " << sid;});
+ }
+ else
+ {
+ // It's possible that there was no CI for the previous commit for
+ // various reasons (e.g., CI was not enabled).
+ //
+ l3 ([&]{trace << "forced push to " << ps.ref
+ << ": failed to cancel CI of previous head commit"
+ << " with tenant_service id " << sid;});
+ }
+
+ return true;
+ }
+
function<optional<string> (const string&, const tenant_service&)> ci_github::
build_unloaded (const string& ti,
tenant_service&& ts,