feat: add a deploy rule requiring passing CI tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hugocasa
2026-11-23 17:08:56 +01:00
co-authored by Claude Opus 5.5
parent 28985a122c
commit d80b5b5b37
22 changed files with 621 additions and 8 deletions
@@ -0,0 +1,29 @@
{
"db_name": "PostgreSQL",
"query": "SELECT f.value AS \"value: sqlx::types::Json<serde_json::Value>\", (SELECT max(created_at) FROM flow_version WHERE workspace_id = $1 AND path = $2) AS deployed_at FROM flow f WHERE f.workspace_id = $1 AND f.path = $2 AND f.archived = false",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "value: sqlx::types::Json<serde_json::Value>",
"type_info": "Jsonb"
},
{
"ordinal": 1,
"name": "deployed_at",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
false,
null
]
},
"hash": "38c0223226923ceef271f70cb55125bd99eb19407547b6a46015ef578122798f"
}
@@ -0,0 +1,29 @@
{
"db_name": "PostgreSQL",
"query": "SELECT value AS \"value: sqlx::types::Json<serde_json::Value>\", edited_at FROM resource WHERE workspace_id = $1 AND path = $2",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "value: sqlx::types::Json<serde_json::Value>",
"type_info": "Jsonb"
},
{
"ordinal": 1,
"name": "edited_at",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
true,
true
]
},
"hash": "4be62c01b78e3bbccdf905b96934faa950827a51990aea4b0a5a0cab46f4bbe5"
}
@@ -0,0 +1,36 @@
{
"db_name": "PostgreSQL",
"query": "SELECT test_script_path, tested_item_path, has_wildcard AS \"has_wildcard!\" FROM ci_test_reference WHERE workspace_id = $1 AND tested_item_kind = $2 AND (has_wildcard OR tested_item_path = $3)",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "test_script_path",
"type_info": "Varchar"
},
{
"ordinal": 1,
"name": "tested_item_path",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "has_wildcard!",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Text",
"Text",
"Text"
]
},
"nullable": [
false,
false,
true
]
},
"hash": "4d7d4f72e8c5dc489f2f230b93d6569f941100dd9641655ad4518e6e9fb76949"
}
@@ -0,0 +1,29 @@
{
"db_name": "PostgreSQL",
"query": "SELECT content, created_at FROM script WHERE workspace_id = $1 AND path = $2 AND deleted = false AND archived = false ORDER BY created_at DESC LIMIT 1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "content",
"type_info": "Text"
},
{
"ordinal": 1,
"name": "created_at",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
false,
false
]
},
"hash": "af6179af83d71da36480328217306422db7507fcf073ae306db3ca2a916e3f7c"
}
@@ -0,0 +1,22 @@
{
"db_name": "PostgreSQL",
"query": "SELECT id FROM workspace WHERE parent_workspace_id = $1 AND deleted = false ORDER BY id",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false
]
},
"hash": "f5fb9fdef71564d8ea6b2b8a609c15a39193978bf6da4a0af9b876de97e8f5c3"
}
@@ -0,0 +1,37 @@
{
"db_name": "PostgreSQL",
"query": "SELECT j.created_at, jc.status::text AS status, (s.content IS NOT DISTINCT FROM t.content) AS \"same_test!\" FROM v2_job j LEFT JOIN v2_job_completed jc ON jc.id = j.id LEFT JOIN script s ON s.workspace_id = j.workspace_id AND s.hash = j.runnable_id LEFT JOIN LATERAL ( SELECT content FROM script WHERE workspace_id = $4 AND path = $2 AND deleted = false AND archived = false ORDER BY created_at DESC LIMIT 1 ) t ON true WHERE j.workspace_id = $1 AND j.runnable_path = $2 AND j.trigger_kind = 'ci_test' AND j.trigger = $3 ORDER BY j.created_at DESC LIMIT 1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 1,
"name": "status",
"type_info": "Text"
},
{
"ordinal": 2,
"name": "same_test!",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Text",
"Text",
"Text",
"Text"
]
},
"nullable": [
false,
null,
null
]
},
"hash": "fa53459440564be4a82cc9306482a93142379b318263f1b4ee054663aaadb810"
}
+1
View File
@@ -16606,6 +16606,7 @@ dependencies = [
"tokio",
"tracing",
"uuid",
"windmill-audit",
"windmill-common",
"windmill-parser-py-imports",
"windmill-parser-ts",
+20
View File
@@ -690,6 +690,16 @@ async fn create_flow(
}
validate_flow(&nf, flows_level, &authed, &db, &user_db, &w_id).await?;
windmill_dep_map::ci_tests::check_ci_tests_rule(
&db,
&w_id,
&nf.path,
windmill_dep_map::ci_tests::DeployedContent::Flow(&nf.value),
&authed,
&authed.groups,
authed.is_admin,
)
.await?;
if *CLOUD_HOSTED {
let nb_flows =
sqlx::query_scalar!("SELECT COUNT(*) FROM flow WHERE workspace_id = $1", &w_id)
@@ -1314,6 +1324,16 @@ async fn update_flow(
}
validate_flow(&nf, flows_level, &authed, &db, &user_db, &w_id).await?;
windmill_dep_map::ci_tests::check_ci_tests_rule(
&db,
&w_id,
&nf.path,
windmill_dep_map::ci_tests::DeployedContent::Flow(&nf.value),
&authed,
&authed.groups,
authed.is_admin,
)
.await?;
let authed = maybe_refresh_folders(&flow_path, &w_id, authed, &db).await;
// Before `tx` opens, for the reason given in `create_flow`.
@@ -1381,6 +1381,16 @@ async fn create_script_internal<'c>(
)> {
windmill_common::workspaces::check_role_can_code(&db, &w_id, &authed, "create scripts").await?;
check_scopes(&authed, || format!("scripts:write:{}", ns.path))?;
windmill_dep_map::ci_tests::check_ci_tests_rule(
&db,
&w_id,
&ns.path,
windmill_dep_map::ci_tests::DeployedContent::Script(&ns.content),
&authed,
&authed.groups,
authed.is_admin,
)
.await?;
// Normalize positive-only settings so a `<= 0` value (e.g. a CLI-pushed `0`) persists as
// disabled rather than as a zero-slot concurrency cap or a 0-second timeout. Deserialization
+1
View File
@@ -41400,6 +41400,7 @@ components:
- RestrictPublicRunSharing
- RestrictGuestAppDeployment
- RequireIsolatedForks
- RequirePassingCiTests
RuleBypasserGroups:
type: array
description: Groups that can bypass this ruleset
File diff suppressed because one or more lines are too long
@@ -81,6 +81,7 @@ bitflags::bitflags! {
const RESTRICT_PUBLIC_RUN_SHARING = 1 << 4;
const RESTRICT_GUEST_APP_DEPLOYMENT = 1 << 5;
const REQUIRE_ISOLATED_FORKS = 1 << 6;
const REQUIRE_PASSING_CI_TESTS = 1 << 7;
}
}
@@ -95,6 +96,7 @@ pub enum ProtectionRuleKind {
RestrictPublicRunSharing,
RestrictGuestAppDeployment,
RequireIsolatedForks,
RequirePassingCiTests,
}
impl ProtectionRuleKind {
@@ -119,6 +121,7 @@ impl ProtectionRuleKind {
ProtectionRules::RESTRICT_GUEST_APP_DEPLOYMENT
}
ProtectionRuleKind::RequireIsolatedForks => ProtectionRules::REQUIRE_ISOLATED_FORKS,
ProtectionRuleKind::RequirePassingCiTests => ProtectionRules::REQUIRE_PASSING_CI_TESTS,
}
}
@@ -143,6 +146,9 @@ impl ProtectionRuleKind {
ProtectionRuleKind::RequireIsolatedForks => {
"Forks of this workspace must isolate its data: no shared object storage or ducklake, and every data table cloned"
}
ProtectionRuleKind::RequirePassingCiTests => {
"An item with CI tests can only be deployed here once those tests pass on it in a fork"
}
}
}
}
+1
View File
@@ -18,6 +18,7 @@ private = []
[dependencies]
windmill-common = { workspace = true, default-features = false }
windmill-queue.workspace = true
windmill-audit.workspace = true
windmill-parser-ts.workspace = true
windmill-parser-py-imports = { workspace = true, optional = true }
sqlx.workspace = true
+300
View File
@@ -196,3 +196,303 @@ pub async fn trigger_all_ci_tests(
) -> error::Result<Vec<Uuid>> {
Ok(vec![])
}
/// What a deploy writes at its path, as `RequirePassingCiTests` compares it with a fork's.
pub enum DeployedContent<'a> {
Script(&'a str),
Flow(&'a serde_json::value::RawValue),
Resource(&'a serde_json::value::RawValue),
}
impl DeployedContent<'_> {
fn kind(&self) -> &'static str {
match self {
DeployedContent::Script(_) => "script",
DeployedContent::Flow(_) => "flow",
DeployedContent::Resource(_) => "resource",
}
}
}
/// Enforces `RequirePassingCiTests` on a deploy of `path` in `w_id`. The workspace's own CI tests
/// of the item must all have passed, in a fork of it holding the same content, on that content
/// and with the same test code. A user who may bypass the rule deploys anyway, and a deploy that
/// would have been refused is audited.
pub async fn check_ci_tests_rule(
db: &sqlx::Pool<sqlx::Postgres>,
w_id: &str,
path: &str,
content: DeployedContent<'_>,
author: &impl windmill_audit::audit_oss::AuditAuthorable,
groups: &[String],
is_admin: bool,
) -> error::Result<()> {
use windmill_common::workspaces::{
check_user_against_rule, get_protection_rules, ProtectionRuleKind, ProtectionRules,
RuleCheckResult,
};
let rulesets = get_protection_rules(w_id, db).await?;
if !rulesets
.iter()
.any(|r| r.rules.contains(ProtectionRules::REQUIRE_PASSING_CI_TESTS))
{
return Ok(());
}
let Some(failure) = ci_tests_failure(db, w_id, path, &content).await? else {
return Ok(());
};
match check_user_against_rule(
w_id,
&ProtectionRuleKind::RequirePassingCiTests,
author.username(),
groups,
is_admin,
db,
)
.await?
{
RuleCheckResult::Blocked(msg) => {
Err(error::Error::PermissionDenied(format!("{msg}. {failure}")))
}
RuleCheckResult::Allowed => {
windmill_audit::audit_oss::audit_log(
db,
author,
"ci_tests.bypass",
windmill_audit::ActionKind::Update,
w_id,
Some(&format!("{}/{path}", content.kind())),
Some([("reason", failure.as_str())].into()),
)
.await?;
Ok(())
}
}
}
/// Why `content` at `path` has not passed `w_id`'s CI tests in any fork, or `None` when it has,
/// or when no test covers it.
async fn ci_tests_failure(
db: &sqlx::Pool<sqlx::Postgres>,
w_id: &str,
path: &str,
content: &DeployedContent<'_>,
) -> error::Result<Option<String>> {
let kind = content.kind();
let refs = sqlx::query!(
"SELECT test_script_path, tested_item_path, has_wildcard AS \"has_wildcard!\" \
FROM ci_test_reference \
WHERE workspace_id = $1 AND tested_item_kind = $2 \
AND (has_wildcard OR tested_item_path = $3)",
w_id,
kind,
path
)
.fetch_all(db)
.await?;
let tests: BTreeSet<String> = refs
.into_iter()
.filter(|r| {
!r.has_wildcard
|| windmill_common::schema::ci_test_path_matches(path, &r.tested_item_path)
})
.map(|r| r.test_script_path)
.collect();
if tests.is_empty() {
return Ok(None);
}
let forks = sqlx::query_scalar!(
"SELECT id FROM workspace WHERE parent_workspace_id = $1 AND deleted = false ORDER BY id",
w_id
)
.fetch_all(db)
.await?;
let value = match content {
DeployedContent::Script(_) => None,
DeployedContent::Flow(v) | DeployedContent::Resource(v) => Some(
serde_json::from_str::<serde_json::Value>(v.get())
.map_err(|e| error::Error::BadRequest(format!("invalid {kind} value: {e}")))?,
),
};
let mut failure = format!("No fork of {w_id} holds this version of {kind} {path}");
for fork in forks {
let Some(deployed_at) = fork_deployed_at(db, &fork, path, content, value.as_ref()).await?
else {
continue;
};
match fork_tests_failure(db, w_id, &fork, kind, path, &tests, deployed_at).await? {
None => return Ok(None),
Some(f) => failure = f,
}
}
Ok(Some(failure))
}
/// When `fork` last deployed `path`, if what it holds there is `content` (`value` being its JSON,
/// parsed, for a flow or a resource).
async fn fork_deployed_at(
db: &sqlx::Pool<sqlx::Postgres>,
fork: &str,
path: &str,
content: &DeployedContent<'_>,
value: Option<&serde_json::Value>,
) -> error::Result<Option<chrono::DateTime<chrono::Utc>>> {
Ok(match (content, value) {
(DeployedContent::Script(c), _) => sqlx::query!(
"SELECT content, created_at FROM script \
WHERE workspace_id = $1 AND path = $2 AND deleted = false AND archived = false \
ORDER BY created_at DESC LIMIT 1",
fork,
path
)
.fetch_optional(db)
.await?
.filter(|s| s.content == *c)
.map(|s| s.created_at),
(DeployedContent::Flow(_), Some(v)) => sqlx::query!(
"SELECT f.value AS \"value: sqlx::types::Json<serde_json::Value>\", \
(SELECT max(created_at) FROM flow_version \
WHERE workspace_id = $1 AND path = $2) AS deployed_at \
FROM flow f WHERE f.workspace_id = $1 AND f.path = $2 AND f.archived = false",
fork,
path
)
.fetch_optional(db)
.await?
.filter(|f| same_flow(&f.value.0, v))
.and_then(|f| f.deployed_at),
(DeployedContent::Resource(_), Some(v)) => sqlx::query!(
"SELECT value AS \"value: sqlx::types::Json<serde_json::Value>\", edited_at \
FROM resource WHERE workspace_id = $1 AND path = $2",
fork,
path
)
.fetch_optional(db)
.await?
.filter(|r| same_resource(r.value.as_ref().map(|v| &v.0), v))
.and_then(|r| r.edited_at),
_ => None,
})
}
/// Why the latest run of one of `tests` for `kind/path` in `fork` does not vouch for what it
/// deployed at `deployed_at`, or `None` when every one does.
async fn fork_tests_failure(
db: &sqlx::Pool<sqlx::Postgres>,
w_id: &str,
fork: &str,
kind: &str,
path: &str,
tests: &BTreeSet<String>,
deployed_at: chrono::DateTime<chrono::Utc>,
) -> error::Result<Option<String>> {
let trigger = format!("{kind}/{path}");
for test in tests {
let run = sqlx::query!(
"SELECT j.created_at, jc.status::text AS status, \
(s.content IS NOT DISTINCT FROM t.content) AS \"same_test!\" \
FROM v2_job j \
LEFT JOIN v2_job_completed jc ON jc.id = j.id \
LEFT JOIN script s ON s.workspace_id = j.workspace_id AND s.hash = j.runnable_id \
LEFT JOIN LATERAL ( \
SELECT content FROM script \
WHERE workspace_id = $4 AND path = $2 AND deleted = false AND archived = false \
ORDER BY created_at DESC LIMIT 1 \
) t ON true \
WHERE j.workspace_id = $1 AND j.runnable_path = $2 \
AND j.trigger_kind = 'ci_test' AND j.trigger = $3 \
ORDER BY j.created_at DESC LIMIT 1",
fork,
test,
&trigger,
w_id
)
.fetch_optional(db)
.await?;
let failure = match run {
None => "has not run",
Some(r) if r.created_at < deployed_at => "has not run since its last deploy",
Some(r) if !r.same_test => "ran with test code that differs from this workspace's",
Some(r) => match r.status.as_deref() {
None => "is still running",
Some("success") => continue,
Some(_) => "failed",
},
};
return Ok(Some(format!(
"CI test {test} of {kind} {path} {failure} in fork {fork}"
)));
}
Ok(None)
}
/// A flow carries over to its parent without the hashes of its script steps, and its locks
/// are recomputed per workspace: neither tells two versions of its logic apart.
fn same_flow(a: &serde_json::Value, b: &serde_json::Value) -> bool {
fn strip(v: &serde_json::Value) -> serde_json::Value {
match v {
serde_json::Value::Object(m) => {
let step = matches!(
m.get("type").and_then(|t| t.as_str()),
Some("rawscript" | "script" | "flow")
);
serde_json::Value::Object(
m.iter()
.filter(|(k, _)| !(step && matches!(k.as_str(), "hash" | "lock")))
.map(|(k, v)| (k.clone(), strip(v)))
.collect(),
)
}
serde_json::Value::Array(a) => serde_json::Value::Array(a.iter().map(strip).collect()),
v => v.clone(),
}
}
strip(a) == strip(b)
}
/// An agent carries over to its parent with the principal it runs as replaced.
fn same_resource(a: Option<&serde_json::Value>, b: &serde_json::Value) -> bool {
fn strip(v: &serde_json::Value) -> serde_json::Value {
let mut v = v.clone();
if let Some(m) = v.as_object_mut() {
m.remove("on_behalf_of");
}
v
}
a.map(strip) == Some(strip(b))
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
#[test]
fn same_flow_ignores_step_hashes_and_locks_only() {
let fork = json!({"modules": [{"id": "a", "value": {"type": "rawscript", "content": "x",
"lock": "l1", "input_transforms": {"lock": {"type": "static", "value": 1}}}},
{"id": "b", "value": {"type": "script", "path": "f/s", "hash": "h1"}}]});
let merged = json!({"modules": [{"id": "a", "value": {"type": "rawscript", "content": "x",
"input_transforms": {"lock": {"type": "static", "value": 1}}}},
{"id": "b", "value": {"type": "script", "path": "f/s"}}]});
assert!(same_flow(&fork, &merged));
let mut changed_arg = merged.clone();
changed_arg["modules"][0]["value"]["input_transforms"]["lock"]["value"] = json!(2);
assert!(!same_flow(&fork, &changed_arg));
let mut changed_code = merged;
changed_code["modules"][0]["value"]["content"] = json!("y");
assert!(!same_flow(&fork, &changed_code));
}
#[test]
fn same_resource_ignores_agent_principal() {
let fork = json!({"model": "m", "on_behalf_of": "u/a"});
assert!(same_resource(
Some(&fork),
&json!({"model": "m", "on_behalf_of": "u/b"})
));
assert!(!same_resource(Some(&fork), &json!({"model": "n"})));
assert!(!same_resource(None, &json!({"model": "m"})));
}
}
+38
View File
@@ -1315,6 +1315,18 @@ async fn create_resource(
.as_ref(),
)
.await?;
if let Some(value) = resource.value.as_deref() {
windmill_dep_map::ci_tests::check_ci_tests_rule(
&db,
&w_id,
&resource.path,
windmill_dep_map::ci_tests::DeployedContent::Resource(value),
&authed,
&authed.groups,
authed.is_admin,
)
.await?;
}
let mut tx = user_db.begin(&authed).await?;
@@ -2204,6 +2216,18 @@ async fn update_resource(
.as_ref(),
)
.await?;
if let Some(value) = ns.value.as_deref() {
windmill_dep_map::ci_tests::check_ci_tests_rule(
&db,
&w_id,
ns.path.as_deref().unwrap_or(path),
windmill_dep_map::ci_tests::DeployedContent::Resource(value),
&authed,
&authed.groups,
authed.is_admin,
)
.await?;
}
let mut tx = user_db.begin(&authed).await?;
@@ -2648,6 +2672,20 @@ async fn set_resource_value(
return Err(Error::PermissionDenied(msg));
}
authorize_azure_devops_reference(authed, db, user_db, w_id, value.as_ref()).await?;
if let Some(value) = value.as_ref() {
let raw = serde_json::value::to_raw_value(value)
.map_err(|e| Error::internal_err(e.to_string()))?;
windmill_dep_map::ci_tests::check_ci_tests_rule(
db,
w_id,
path,
windmill_dep_map::ci_tests::DeployedContent::Resource(&raw),
authed,
&authed.groups,
authed.is_admin,
)
.await?;
}
let mut tx = user_db.clone().begin(authed).await?;
+1 -1
View File
@@ -8659,7 +8659,7 @@ write a secret you were not given: keep the placeholder.
| \`git_sync\` | \`{ repositories: [...] }\`, each with \`git_repo_resource_path\`, \`script_path\` and \`settings\` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
| \`datatable\` | \`{ datatables: { <name>: { database: { resource_type, resource_path } } } }\`, both required: \`resource_type: postgresql\` with \`resource_path\` a Postgres resource's path, or \`instance\`, or \`external_instance\` (Enterprise only), with \`resource_path\` the name of a database a superadmin set up. A fork's entry can instead be \`{ reference: { workspace_id, datatable } }\`, pointing at its parent's data table; keep it as is. \`main\` is the one scripts use by default. Role permissions are \`datatable_permissions\`. |
| \`datatable_permissions\` | \`{ <data table>: { default_role, roles: { <role>: [tenants] } } }\`: who may connect to each data table as which role. Tenants are \`u/<user>\`, \`g/<group>\`, \`f/<folder>\` or \`*\`; \`admin\` is always a role, and \`default_role: null\` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`, \`RequirePassingCiTests\`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| \`ducklake\` | \`{ ducklakes: { <name>: { catalog, storage, ... } } }\`. |
| \`dbt_warehouses\` | dbt warehouse connections. |
| \`default_app\` | Path of the app shown as the workspace home. |
@@ -1665,6 +1665,12 @@
{#if mergeIntoParent}
<ParentWorkspaceProtectionAlert
{parentWorkspaceId}
ciBlockedItems={selectedDiffs
.filter((d) => {
const status = getCiTestStatus(d)
return status === 'fail' || status === 'running'
})
.map((d) => d.path)}
onUpdateCanDeploy={(canDeploy) => {
canDeployToParent = canDeploy
}}
@@ -14,16 +14,20 @@
let {
parentWorkspaceId,
displayName,
ciBlockedItems = [],
onUpdateCanDeploy = (value) => {}
}: {
parentWorkspaceId: string
/** How to name the target in the message, when its id is not what a reader would recognize
* — a remote deploy target is addressed through a proxy path. */
displayName?: string
/** Selected items whose CI tests are failing or still running in the source workspace. */
ciBlockedItems?: string[]
onUpdateCanDeploy?: (value: boolean) => void
} = $props()
let overrideChecked = $state(false)
let ciOverrideChecked = $state(false)
// Fetch the parent's rules and the user's identity in the parent together. Both must come from the
// parent: bypass is judged with is_admin/groups in the PARENT (per-workspace), not the active/fork
@@ -50,19 +54,29 @@
canUserBypassRuleKindInRulesets(parentRulesets, 'DisableDirectDeployment', parentUserInfo)
)
let ciRulesets = $derived(
getActiveRulesetsForKindInRulesets(parentRulesets, 'RequirePassingCiTests')
)
let canBypassCi = $derived(
canUserBypassRuleKindInRulesets(parentRulesets, 'RequirePassingCiTests', parentUserInfo)
)
let ciBlocked = $derived(ciRulesets.length > 0 && ciBlockedItems.length > 0)
// Block deploy until the parent's rules/identity have loaded: while loading `parentRulesets` is
// empty, which would otherwise read as "no lock" and briefly enable deploy before the real
// lock/bypass check resolves.
let canDeploy = $derived(
!parentDataResource.loading &&
(!isRuleActiveInRulesets(parentRulesets, 'DisableDirectDeployment') ||
(canBypass && overrideChecked))
(canBypass && overrideChecked)) &&
(!ciBlocked || (canBypassCi && ciOverrideChecked))
)
// Reset override when parent workspace changes
$effect(() => {
parentWorkspaceId
overrideChecked = false
ciOverrideChecked = false
})
// Communicate deployment status to parent
@@ -95,3 +109,21 @@
</div>
</Alert>
{/if}
{#if ciBlocked}
<Alert type="warning" title="CI tests must pass before deploying" class="my-2">
<div class="flex flex-col gap-2">
<p>
The workspace {displayName ?? parentWorkspaceId} requires passing CI tests (<b
>{ciRulesets.map((r) => r.name).join(', ')}</b
>). These selected items have tests that are failing or still running:
<b>{ciBlockedItems.join(', ')}</b>.
</p>
{#if canBypassCi}
<label class="flex items-center gap-2 cursor-pointer">
<input class="rounded max-w-4" type="checkbox" bind:checked={ciOverrideChecked} />
<span class="text-xs">Bypass and deploy anyway (recorded in the audit log)</span>
</label>
{/if}
</div>
</Alert>
{/if}
@@ -48,6 +48,7 @@
let restrictPublicRunSharing = $state(hasRule('RestrictPublicRunSharing'))
let restrictGuestAppDeployment = $state(hasRule('RestrictGuestAppDeployment'))
let requireIsolatedForks = $state(hasRule('RequireIsolatedForks'))
let requirePassingCiTests = $state(hasRule('RequirePassingCiTests'))
let selectedGroups = $state<string[]>(
untrack(() => rule)?.bypass_groups?.map((g) => g.replace('g/', '')) ?? []
)
@@ -68,6 +69,7 @@
let initialRestrictPublicRunSharing = $state(hasRule('RestrictPublicRunSharing'))
let initialRestrictGuestAppDeployment = $state(hasRule('RestrictGuestAppDeployment'))
let initialRequireIsolatedForks = $state(hasRule('RequireIsolatedForks'))
let initialRequirePassingCiTests = $state(hasRule('RequirePassingCiTests'))
let initialSelectedGroups = $state<string[]>(
untrack(() => rule)?.bypass_groups
? untrack(() => rule)!.bypass_groups.map((g) => g.replace('g/', ''))
@@ -126,6 +128,7 @@
restrictPublicRunSharing ||
restrictGuestAppDeployment ||
requireIsolatedForks ||
requirePassingCiTests ||
selectedGroups.length > 0 ||
selectedUsers.length > 0 ||
forkRoleMapping.length > 0
@@ -137,6 +140,7 @@
restrictPublicRunSharing !== initialRestrictPublicRunSharing ||
restrictGuestAppDeployment !== initialRestrictGuestAppDeployment ||
requireIsolatedForks !== initialRequireIsolatedForks ||
requirePassingCiTests !== initialRequirePassingCiTests ||
JSON.stringify([...selectedGroups].sort()) !==
JSON.stringify([...initialSelectedGroups].sort()) ||
JSON.stringify([...selectedUsers].sort()) !==
@@ -193,7 +197,8 @@
...(restrictGuestAppDeployment
? ['RestrictGuestAppDeployment' as ProtectionRuleKind]
: []),
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : [])
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : []),
...(requirePassingCiTests ? ['RequirePassingCiTests' as ProtectionRuleKind] : [])
],
bypass_groups: selectedGroups,
bypass_users: selectedUsers,
@@ -234,7 +239,8 @@
...(restrictGuestAppDeployment
? ['RestrictGuestAppDeployment' as ProtectionRuleKind]
: []),
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : [])
...(requireIsolatedForks ? ['RequireIsolatedForks' as ProtectionRuleKind] : []),
...(requirePassingCiTests ? ['RequirePassingCiTests' as ProtectionRuleKind] : [])
],
bypass_groups: selectedGroups,
bypass_users: selectedUsers,
@@ -253,6 +259,7 @@
initialRestrictPublicRunSharing = restrictPublicRunSharing
initialRestrictGuestAppDeployment = restrictGuestAppDeployment
initialRequireIsolatedForks = requireIsolatedForks
initialRequirePassingCiTests = requirePassingCiTests
initialSelectedGroups = clone(selectedGroups)
initialSelectedUsers = clone(selectedUsers)
initialForkRoleMapping = clone(forkRoleMapping)
@@ -356,6 +363,15 @@
'Only workspace admins and members of wm_deployers can deploy to this workspace. Non-deployers can still fork, browse, and request a review.'
)}
</div>
<div class="flex flex-col gap-1">
<Toggle
bind:checked={requirePassingCiTests}
options={{ right: 'Require passing CI tests' }}
/>
{@render description(
"An item this workspace's CI tests cover deploys only once every one of them has passed on that exact version in a fork. Applies to wm_deployers too."
)}
</div>
<div class="flex flex-col gap-1">
<Toggle
bind:checked={restrictAnonymousAppDeployment}
+1 -1
View File
@@ -1632,7 +1632,7 @@ write a secret you were not given: keep the placeholder.
| \`git_sync\` | \`{ repositories: [...] }\`, each with \`git_repo_resource_path\`, \`script_path\` and \`settings\` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
| \`datatable\` | \`{ datatables: { <name>: { database: { resource_type, resource_path } } } }\`, both required: \`resource_type: postgresql\` with \`resource_path\` a Postgres resource's path, or \`instance\`, or \`external_instance\` (Enterprise only), with \`resource_path\` the name of a database a superadmin set up. A fork's entry can instead be \`{ reference: { workspace_id, datatable } }\`, pointing at its parent's data table; keep it as is. \`main\` is the one scripts use by default. Role permissions are \`datatable_permissions\`. |
| \`datatable_permissions\` | \`{ <data table>: { default_role, roles: { <role>: [tenants] } } }\`: who may connect to each data table as which role. Tenants are \`u/<user>\`, \`g/<group>\`, \`f/<folder>\` or \`*\`; \`admin\` is always a role, and \`default_role: null\` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| \`protection_rules\` | \`{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }\`, rules among \`DisableDirectDeployment\`, \`DisableWorkspaceForking\`, \`RestrictDeployToDeployers\`, \`RestrictAnonymousAppDeployment\`, \`RestrictPublicRunSharing\`, \`RestrictGuestAppDeployment\`, \`RequireIsolatedForks\`, \`RequirePassingCiTests\`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| \`ducklake\` | \`{ ducklakes: { <name>: { catalog, storage, ... } } }\`. |
| \`dbt_warehouses\` | dbt warehouse connections. |
| \`default_app\` | Path of the app shown as the workspace home. |
@@ -47,7 +47,7 @@ write a secret you were not given: keep the placeholder.
| `git_sync` | `{ repositories: [...] }`, each with `git_repo_resource_path`, `script_path` and `settings` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
| `datatable` | `{ datatables: { <name>: { database: { resource_type, resource_path } } } }`, both required: `resource_type: postgresql` with `resource_path` a Postgres resource's path, or `instance`, or `external_instance` (Enterprise only), with `resource_path` the name of a database a superadmin set up. A fork's entry can instead be `{ reference: { workspace_id, datatable } }`, pointing at its parent's data table; keep it as is. `main` is the one scripts use by default. Role permissions are `datatable_permissions`. |
| `datatable_permissions` | `{ <data table>: { default_role, roles: { <role>: [tenants] } } }`: who may connect to each data table as which role. Tenants are `u/<user>`, `g/<group>`, `f/<folder>` or `*`; `admin` is always a role, and `default_role: null` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`, `RequirePassingCiTests`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| `ducklake` | `{ ducklakes: { <name>: { catalog, storage, ... } } }`. |
| `dbt_warehouses` | dbt warehouse connections. |
| `default_app` | Path of the app shown as the workspace home. |
+1 -1
View File
@@ -42,7 +42,7 @@ write a secret you were not given: keep the placeholder.
| `git_sync` | `{ repositories: [...] }`, each with `git_repo_resource_path`, `script_path` and `settings` (include/exclude paths and types). Server-owned fields (webhook secrets, sync state, credentials) are never read nor written. |
| `datatable` | `{ datatables: { <name>: { database: { resource_type, resource_path } } } }`, both required: `resource_type: postgresql` with `resource_path` a Postgres resource's path, or `instance`, or `external_instance` (Enterprise only), with `resource_path` the name of a database a superadmin set up. A fork's entry can instead be `{ reference: { workspace_id, datatable } }`, pointing at its parent's data table; keep it as is. `main` is the one scripts use by default. Role permissions are `datatable_permissions`. |
| `datatable_permissions` | `{ <data table>: { default_role, roles: { <role>: [tenants] } } }`: who may connect to each data table as which role. Tenants are `u/<user>`, `g/<group>`, `f/<folder>` or `*`; `admin` is always a role, and `default_role: null` means no default. A data table the value omits is no longer under roles. Only a data table on a cluster Windmill manages can be. |
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| `protection_rules` | `{ <rule name>: { rules: [...], bypass_groups: [...], bypass_users: [...], fork_role_mapping?: { <role here>: <role in its forks> } } }`, rules among `DisableDirectDeployment`, `DisableWorkspaceForking`, `RestrictDeployToDeployers`, `RestrictAnonymousAppDeployment`, `RestrictPublicRunSharing`, `RestrictGuestAppDeployment`, `RequireIsolatedForks`, `RequirePassingCiTests`. A rule the value omits is deleted. The dev workspace lock is not listed and cannot be set here. |
| `ducklake` | `{ ducklakes: { <name>: { catalog, storage, ... } } }`. |
| `dbt_warehouses` | dbt warehouse connections. |
| `default_app` | Path of the app shown as the workspace home. |