Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 63 additions & 5 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
e2e: ${{ steps.scope.outputs.e2e }}
browser: ${{ steps.scope.outputs.browser }}
packaging: ${{ steps.scope.outputs.packaging }}
demo: ${{ steps.scope.outputs.demo }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -37,16 +38,18 @@ jobs:
echo "e2e=$2"
echo "browser=$3"
echo "packaging=$4"
echo "demo=$5"
} >> "${GITHUB_OUTPUT}"
}

if [[ "${EVENT_NAME}" != "pull_request" ]]; then
write_scope true true true true
write_scope true true true true true
exit 0
fi

focused=true
packaging=false
demo=false
browser=false
changed=false
while IFS= read -r -d '' path; do
Expand All @@ -56,6 +59,12 @@ jobs:
packaging=true
;;
esac
# What sqt plans and writes, which the UI demo prepared ahead, and what runs it in chdb-wasm.
case "${path}" in
Cargo.*|crates/*|src/sqltide/*|pyproject.toml|uv.lock|ui/scripts/prepare-demo.mjs|ui/scripts/demo-engine.*|ui/scripts/check-demo-readers.mjs|ui/src/lib/demo/*|ui/src/lib/demo-readers/*|website/package*.json|.github/workflows/verify.yml)
demo=true
;;
esac
case "${path}" in
ui/*)
browser=true
Expand All @@ -74,11 +83,11 @@ jobs:
done < <(git diff --name-only -z "${BASE_SHA}" "${HEAD_SHA}")

if [[ "${changed}" != "true" || "${focused}" != "true" ]]; then
write_scope true true true "${packaging}"
write_scope true true true "${packaging}" "${demo}"
exit 0
fi

write_scope false false "${browser}" "${packaging}"
write_scope false false "${browser}" "${packaging}" "${demo}"

checks:
name: Static, UI, and unit checks
Expand Down Expand Up @@ -220,6 +229,54 @@ jobs:
if-no-files-found: error
retention-days: 7

demo:
name: UI demo matches sqt and runs on its engine
needs: changes
if: needs.changes.outputs.demo == 'true'
runs-on: ubuntu-latest
timeout-minutes: 75
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
version: "0.12.3"
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/setup-node@v4
with:
# chdb-wasm needs Memory64, which Node has from 23.
node-version: 24
cache: npm
cache-dependency-path: |
ui/package-lock.json
website/package-lock.json
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2
- name: Install Python
run: uv python install "$(cat .python-version)"
- name: Install dependencies
run: uv sync --locked --all-groups
- name: Install UI and website dependencies
run: |
make ui-install
cd website && npm ci
- name: Build the UI sqt dev serves
run: make ui-build
- name: Prepare the demo again with sqt and compare
working-directory: ui
env:
SQT: ${{ github.workspace }}/.venv/bin/sqt
run: node scripts/prepare-demo.mjs --check
- name: Compare the demo's warehouse readers with sqt dev
run: node ui/scripts/check-demo-readers.mjs
- name: Run every prepared action on the demo's engine
working-directory: ui
env:
CHDB_WASM: ${{ github.workspace }}/website/node_modules/chdb-wasm
run: npx vitest run --config scripts/demo-engine.config.ts

distributions:
name: Distributions
needs: changes
Expand All @@ -233,7 +290,7 @@ jobs:
verify:
name: Verify
if: always()
needs: [changes, checks, integration, e2e, browser, distributions, website]
needs: [changes, checks, integration, e2e, browser, demo, distributions, website]
runs-on: ubuntu-latest
steps:
- name: Confirm all required verification jobs passed
Expand All @@ -243,6 +300,7 @@ jobs:
INTEGRATION_RESULT: ${{ needs.integration.result }}
E2E_RESULT: ${{ needs.e2e.result }}
BROWSER_RESULT: ${{ needs.browser.result }}
DEMO_RESULT: ${{ needs.demo.result }}
DISTRIBUTIONS_RESULT: ${{ needs.distributions.result }}
WEBSITE_RESULT: ${{ needs.website.result }}
run: |
Expand All @@ -251,7 +309,7 @@ jobs:
exit 1
fi
for result in "${INTEGRATION_RESULT}" "${E2E_RESULT}" "${BROWSER_RESULT}" \
"${DISTRIBUTIONS_RESULT}"; do
"${DEMO_RESULT}" "${DISTRIBUTIONS_RESULT}"; do
if [[ "${result}" != "success" && "${result}" != "skipped" ]]; then
echo "A selected verification suite did not pass: ${result}" >&2
exit 1
Expand Down
12 changes: 9 additions & 3 deletions crates/sqltide-python/src/dev_server/authz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,14 @@ pub(crate) fn require_run_cancel(
)
}

/// Require `DEPLOYMENT_PROMOTE` over every pipeline the promotion changes.
/// Require `DEPLOYMENT_PROMOTE` over every pipeline publishing `deployment_id` changes, for
/// its `operation`: a promotion, or a rollback to that deployment.
pub(crate) fn require_promotion(
call: &Call<'_, '_>,
analysis: &Bound<'_, PyAny>,
deployment_id: &str,
logical_ids: &Bound<'_, PyAny>,
operation: &str,
) -> Outcome<()> {
let list = pyo3::types::PyList::new(
call.py,
Expand All @@ -499,7 +501,7 @@ pub(crate) fn require_promotion(
Some(pipelines) if !pipelines.is_empty() => pipelines,
_ => {
return Err(unresolved(format!(
"Cannot resolve pipeline scope for deployment '{deployment_id}' promotion"
"Cannot resolve pipeline scope for deployment '{deployment_id}' {operation}"
)));
}
};
Expand All @@ -510,7 +512,11 @@ pub(crate) fn require_promotion(
permission: "DEPLOYMENT_PROMOTE",
grant_scope: None,
affected_pipelines: pipelines,
denial_message: "Promoting this deployment is not permitted".to_owned(),
denial_message: if operation == "rollback" {
"Rolling back to this deployment is not permitted".to_owned()
} else {
"Promoting this deployment is not permitted".to_owned()
},
},
)
}
Expand Down
130 changes: 121 additions & 9 deletions crates/sqltide-python/src/dev_server/deployments.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Deployment lifecycle mutations the dev server runs as recorded, observable invocations, and
//! the deployment comparison payload.

use pyo3::exceptions::PyException;
use pyo3::exceptions::{PyException, PyValueError};
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyList, PySet, PyString, PyTuple};

Expand All @@ -11,6 +11,7 @@ use crate::handling::while_handling;
use crate::py_kwargs;

const PROMOTE_COMMAND: &str = "deployment promote";
const ROLLBACK_COMMAND: &str = "deployment rollback";
const CLEANUP_COMMAND: &str = "janitor";
const VIRTUAL_ENVIRONMENT_MODE: &str = "virtual_environment";

Expand Down Expand Up @@ -145,6 +146,119 @@ pub(crate) fn run_dev_deployment_promotion<'py>(
metadata_database: &Any<'py>,
deployment_id: &Any<'py>,
project_dir: &Any<'py>,
) -> PyResult<Bound<'py, PyDict>> {
let py: Python<'py> = connection.py();
run_recorded_publish(
connection,
database,
metadata_database,
deployment_id,
project_dir,
PROMOTE_COMMAND,
|| {
attr(py, "sqltide.executor.promotion.models", "PublishRequest")?.call(
(),
Some(&py_kwargs!(py; deployment_id = deployment_id, metadata_database = metadata_database, default_database = database)?),
)
},
)
}

/// Roll the active deployment back to a superseded one, recording it as a run the UI can follow.
///
/// Only a superseded deployment is a rollback target here, and the rollback is resolved before
/// the run starts, so a refused target changes nothing and records no run.
#[pyfunction]
#[pyo3(signature = (*, connection, database, metadata_database, deployment_id, project_dir))]
pub(crate) fn run_dev_deployment_rollback<'py>(
connection: &Any<'py>,
database: &Any<'py>,
metadata_database: &Any<'py>,
deployment_id: &Any<'py>,
project_dir: &Any<'py>,
) -> PyResult<Bound<'py, PyDict>> {
let py: Python<'py> = connection.py();
let inventory: Any<'py> = call(
py,
"sqltide._native",
"load_deployments",
py_kwargs!(py; client = connection, metadata_database = metadata_database, default_database = database)?,
)?;
let mut state: Option<String> = None;
for item in inventory.getattr("deployments")?.try_iter()? {
let item: Any<'py> = item?;
if item.getattr("deployment_id")?.eq(deployment_id)? {
state = Some(item.getattr("state")?.getattr("value")?.extract()?);
break;
}
}
let shown: String = deployment_id.str()?.extract()?;
match state.as_deref() {
Some("superseded") => {}
Some(state) => {
return Err(PyValueError::new_err(format!(
"Deployment '{shown}' is {state}, not superseded; only a superseded deployment \
can be rolled back to"
)));
}
None => {
return Err(PyValueError::new_err(format!(
"Deployment '{shown}' was not found"
)));
}
}
let request: Any<'py> = attr(py, "sqltide.executor.promotion.models", "RollbackRequest")?
.call(
(),
Some(&py_kwargs!(py;
deployment_id = deployment_id,
previous = false,
metadata_database = metadata_database,
default_database = database,
)?),
)?;
let plan: Any<'py> = call(
py,
"sqltide._native",
"resolve_deployment_rollback",
py_kwargs!(py; request = request, client = connection)?,
)?;
let previous_deployment_id: Any<'py> = plan.getattr("current_deployment_id")?;
let target_deployment_id: Any<'py> = plan.getattr("target_deployment_id")?;
let payload: Bound<'py, PyDict> = run_recorded_publish(
connection,
database,
metadata_database,
&target_deployment_id,
project_dir,
ROLLBACK_COMMAND,
|| {
attr(py, "sqltide.executor.promotion.models", "PublishRequest")?.call(
(),
Some(&py_kwargs!(py;
deployment_id = &target_deployment_id,
metadata_database = metadata_database,
default_database = database,
operation = "rollback",
previous_deployment_id = &previous_deployment_id,
)?),
)
},
)?;
payload.set_item("previousDeploymentId", previous_deployment_id)?;
Ok(payload)
}

/// Publish one deployment as a recorded run: `run_started`, the publish, `run_completed`, and
/// the terminal invocation record, with the published views as the payload.
fn run_recorded_publish<'py>(
connection: &Any<'py>,
database: &Any<'py>,
metadata_database: &Any<'py>,
deployment_id: &Any<'py>,
project_dir: &Any<'py>,
command: &str,
publish_request: impl FnOnce() -> PyResult<Any<'py>>,
) -> PyResult<Bound<'py, PyDict>> {
let py: Python<'py> = connection.py();
let started: Bound<'py, PyTuple> = start(py)?;
Expand All @@ -166,19 +280,16 @@ pub(crate) fn run_dev_deployment_promotion<'py>(
"run_started",
(),
Some(&py_kwargs!(py;
command = PROMOTE_COMMAND,
display_command = fstring(py, &[literal(py, "sqt deployment promote "), deployment_id.clone()])?,
command = command,
display_command = fstring(py, &[literal(py, &format!("sqt {command} ")), deployment_id.clone()])?,
mode = VIRTUAL_ENVIRONMENT_MODE,
total_statements = 0,
selected_node_count = selected_node_count,
executed_logical_ids = &executed_logical_ids,
)?),
)?;
let published: PyResult<Any<'py>> = (|| {
let request: Any<'py> = attr(py, "sqltide.executor.promotion.models", "PublishRequest")?.call(
(),
Some(&py_kwargs!(py; deployment_id = deployment_id, metadata_database = metadata_database, default_database = database)?),
)?;
let request: Any<'py> = publish_request()?;
call(
py,
"sqltide._native",
Expand All @@ -202,7 +313,7 @@ pub(crate) fn run_dev_deployment_promotion<'py>(
&started,
project_dir,
database,
PROMOTE_COMMAND,
command,
deployment_id.clone(),
"failed",
py.None().into_bound(py),
Expand Down Expand Up @@ -231,7 +342,7 @@ pub(crate) fn run_dev_deployment_promotion<'py>(
&started,
project_dir,
database,
PROMOTE_COMMAND,
command,
result.getattr("deployment_id")?,
"succeeded",
PyString::new(py, "applied").into_any(),
Expand Down Expand Up @@ -408,6 +519,7 @@ fn deployment_diff_payload<'py>(result: &Any<'py>) -> PyResult<Bound<'py, PyDict
pub(crate) fn register(module: &Bound<'_, PyModule>) -> PyResult<()> {
module.add_function(wrap_pyfunction!(promotion_executed_logical_ids, module)?)?;
module.add_function(wrap_pyfunction!(run_dev_deployment_promotion, module)?)?;
module.add_function(wrap_pyfunction!(run_dev_deployment_rollback, module)?)?;
module.add_function(wrap_pyfunction!(run_dev_deployment_cleanup, module)?)?;
module.add_function(wrap_pyfunction!(build_deployment_diff_payload, module)?)?;
module.add_function(wrap_pyfunction!(deployment_diff_payload_py, module)?)
Expand Down
Loading
Loading