From 4fe7a0e1ae880ad505967648fe73190ec7665182 Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Wed, 29 Jul 2026 18:02:23 +0000 Subject: [PATCH] ci: speed up Rust builds and tests Signed-off-by: Vikrant Puppala --- .github/workflows/coverage.yml | 6 +++ .github/workflows/license-check.yml | 6 +++ .github/workflows/napi-checks.yml | 42 +++++------------ .github/workflows/pr-checks.yml | 24 ++++++++++ .github/workflows/pyo3-checks.yml | 72 ++++++++++++----------------- .github/workflows/rust-e2e.yml | 10 ++++ .github/workflows/securityScan.yml | 6 +++ src/auth/oauth/m2m.rs | 16 ++++++- src/auth/oauth/oidc.rs | 17 +++++-- tests/v0_session_wiremock.rs | 25 +++++----- 10 files changed, 135 insertions(+), 89 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index ddceb311..a81da812 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -61,6 +61,9 @@ jobs: runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest + env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: @@ -75,6 +78,9 @@ jobs: toolchain: stable components: llvm-tools-preview + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + - name: Install cargo-llvm-cov uses: taiki-e/install-action@07b4745e0c39a41822af610387492e3e53aa222b # v2.83.4 with: diff --git a/.github/workflows/license-check.yml b/.github/workflows/license-check.yml index 225f99d1..638707b1 100644 --- a/.github/workflows/license-check.yml +++ b/.github/workflows/license-check.yml @@ -47,6 +47,12 @@ on: - "napi/Cargo.lock" - ".github/workflows/license-check.yml" +concurrency: + # A newer commit makes an older run for the same PR irrelevant. + # Main pushes remain distinct and must finish independently. + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + permissions: contents: read # Required for the OIDC token exchange that the diff --git a/.github/workflows/napi-checks.yml b/.github/workflows/napi-checks.yml index 41b79a7e..730f927b 100644 --- a/.github/workflows/napi-checks.yml +++ b/.github/workflows/napi-checks.yml @@ -49,45 +49,16 @@ concurrency: permissions: contents: read -# `id-token: write` is NOT granted workflow-wide: the `precondition` -# job only checks out and inspects the tree, so least-privilege keeps -# it on the single job that needs it (`check-and-test`, below). +# `id-token: write` is scoped to the single job that exchanges an OIDC +# token for JFrog access. defaults: run: shell: bash jobs: - # Cheap gate job — runs once, no toolchain installs. The check-and-test - # job depends on this and is skipped (no runner boot beyond the - # precondition runner itself) when the napi/ sub-crate doesn't - # exist. Avoids wasted setup cost on kernel-only PRs that trigger - # this workflow via root Cargo.toml changes before the napi crate - # has merged. - precondition: - name: "Check napi sub-crate exists" - runs-on: - group: databricks-protected-runner-group - labels: linux-ubuntu-latest - outputs: - ready: ${{ steps.check.outputs.ready }} - steps: - - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: "Check for napi/Cargo.toml" - id: check - run: | - if [[ -f "napi/Cargo.toml" ]]; then - echo "ready=true" >> "$GITHUB_OUTPUT" - else - echo "::notice::napi/ sub-crate does not exist yet — skipping napi checks. (Workflow may fire on root Cargo.toml changes before the napi crate has merged.)" - echo "ready=false" >> "$GITHUB_OUTPUT" - fi - check-and-test: name: "napi fmt + clippy + test" - needs: precondition - if: needs.precondition.outputs.ready == 'true' # Scoped here (not workflow-wide): `id-token: write` is only needed # for the OIDC token exchange in `.github/actions/setup-jfrog` that # authenticates against the JFrog cargo proxy. See go/hardened-gha. @@ -97,6 +68,9 @@ jobs: runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest + env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" defaults: run: # All cargo commands run from the napi/ standalone workspace. @@ -116,6 +90,12 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 with: components: rustfmt, clippy + # napi is a standalone workspace; cache its actual target and + # lockfile instead of the unused repository-root target. + cache-workspaces: "napi -> target" + + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 - name: cargo fmt --all -- --check run: cargo fmt --all -- --check diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 946a94b7..1e93b834 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -80,6 +80,9 @@ jobs: runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest + env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 @@ -92,6 +95,9 @@ jobs: toolchain: stable components: clippy + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + - name: cargo clippy run: cargo clippy --all-targets -- -D warnings @@ -100,6 +106,9 @@ jobs: runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest + env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 @@ -111,6 +120,9 @@ jobs: with: toolchain: stable + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + - name: cargo test # Runs every test the default suite executes: unit tests, # doc tests, and wiremock-backed integration tests. Does NOT @@ -123,6 +135,9 @@ jobs: runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest + env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 @@ -134,6 +149,9 @@ jobs: with: toolchain: stable + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + - name: make c-abi-test # Builds the cdylib and compiles + runs the hand-written C smoke # tests in tests/c/ against the C ABI exported from src/c_abi/. @@ -146,6 +164,9 @@ jobs: runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest + env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 @@ -158,6 +179,9 @@ jobs: toolchain: stable components: clippy + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + - name: cargo check (tls-rustls) # Default features pull in `tls-native`; the napi binding crate # opts INTO `tls-rustls` instead. Without this job, a feature- diff --git a/.github/workflows/pyo3-checks.yml b/.github/workflows/pyo3-checks.yml index 356ba86d..765a7391 100644 --- a/.github/workflows/pyo3-checks.yml +++ b/.github/workflows/pyo3-checks.yml @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# PyO3 sub-crate CI. Path-gated on `pyo3/**` so this workflow -# only fires when the directory exists (it lands in PR #13). The -# job is skipped automatically on every PR that doesn't touch -# the pyo3/ tree. +# PyO3 sub-crate CI. Path-gated so the matrix runs only when the +# binding or one of its root Cargo inputs changes. name: PyO3 Checks @@ -51,36 +49,8 @@ defaults: shell: bash jobs: - # Cheap gate job — runs once, no matrix, no toolchain installs. - # The matrix `build-and-test` job depends on this and is skipped - # entirely (no runner boot, no checkout) when the pyo3/ sub-crate - # doesn't exist. This avoids the per-Python-version setup cost on - # kernel-only PRs that trigger this workflow via root Cargo.toml - # / Cargo.lock changes. - precondition: - name: "Check pyo3 sub-crate exists" - runs-on: - group: databricks-protected-runner-group - labels: linux-ubuntu-latest - outputs: - ready: ${{ steps.check.outputs.ready }} - steps: - - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - - name: "Check for pyo3/Cargo.toml" - id: check - run: | - if [[ -f "pyo3/Cargo.toml" ]]; then - echo "ready=true" >> "$GITHUB_OUTPUT" - else - echo "::notice::pyo3/ sub-crate does not exist yet — skipping pyo3 build/test matrix. (Workflow fires on root Cargo.toml changes; the pyo3 sub-crate lands in PR #13.)" - echo "ready=false" >> "$GITHUB_OUTPUT" - fi - build-and-test: name: "PyO3 build + test (Python ${{ matrix.python-version }})" - needs: precondition - if: needs.precondition.outputs.ready == 'true' runs-on: group: databricks-protected-runner-group labels: linux-ubuntu-latest @@ -96,6 +66,10 @@ jobs: DATABRICKS_HTTP_PATH: ${{ secrets.TEST_PECO_WAREHOUSE_HTTP_PATH }} DATABRICKS_TOKEN: ${{ secrets.DATABRICKS_TOKEN }} RUST_LOG: databricks_sql_kernel=info + RUSTC_WRAPPER: sccache + # Select sccache's GitHub Actions backend. Without this, the + # protected runner's local cache disappears with the job. + SCCACHE_GHA_ENABLED: "true" strategy: fail-fast: false matrix: @@ -119,6 +93,17 @@ jobs: python-version: ${{ matrix.python-version }} - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 + with: + # pyo3 is a standalone workspace. The default "." mapping + # cached the unused root target/ and root Cargo.lock while + # every pyo3/target build remained cold. + cache-workspaces: "pyo3 -> target" + # PyO3 build-script output is interpreter-specific even though + # the published extension uses abi3. + cache-key: "py${{ matrix.python-version }}" + + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 # uv is the Python package manager the kernel pyo3 sub-crate # uses for env management. uv itself is installed via @@ -139,12 +124,10 @@ jobs: # re-resolves each run within those bounds. working-directory: pyo3 # `--no-install-project` installs only the dependency groups, - # NOT the kernel cdylib itself. Without it, `uv sync` runs a - # full maturin/cargo RELEASE build of the extension here — and - # then the `maturin develop` step below rebuilds it again in - # debug, so the kernel compiled twice per matrix Python version - # (~5 min each, x5 versions). The Rust extension is built - # exactly once, by `maturin develop`. + # NOT the kernel cdylib itself. The later `uv run --no-sync` + # calls preserve that choice: plain `uv run` would implicitly + # sync and build the project before invoking maturin, compiling + # the extension twice per matrix entry. run: uv sync --group dev --no-install-project - name: Cargo unit tests (pyo3 crate) @@ -168,9 +151,12 @@ jobs: # # maturin's `develop` always targets the active virtualenv's # interpreter and (unlike `build`) has no --interpreter flag; - # `uv run` already activates the venv `uv sync` created for the - # matrix Python version, so the interpreter is selected for us. - run: uv run maturin develop + # `uv run` activates the venv `uv sync` created for the matrix + # Python version, so the interpreter is selected for us. + # `--no-sync` is load-bearing: without it uv first installs the + # project through its maturin build backend, then this command + # asks maturin to build and install it a second time. + run: uv run --no-sync maturin develop - name: pytest (no-network + live tiers) working-directory: pyo3 @@ -181,4 +167,6 @@ jobs: # repo; on fork PRs without approval, the no-network tier # (test_module.py + test_auth.py) runs and the live tier # skips cleanly. - run: uv run pytest -v + # The extension and dependencies are already installed above; + # avoid another implicit project sync before starting pytest. + run: uv run --no-sync pytest -v diff --git a/.github/workflows/rust-e2e.yml b/.github/workflows/rust-e2e.yml index 067f56b0..b41dcdb7 100644 --- a/.github/workflows/rust-e2e.yml +++ b/.github/workflows/rust-e2e.yml @@ -73,6 +73,8 @@ jobs: DATABRICKS_TEST_CLIENT_SECRET: ${{ secrets.DATABRICKS_TEST_CLIENT_SECRET }} RUST_LOG: databricks_sql_kernel=debug RUST_BACKTRACE: 1 + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: @@ -85,6 +87,9 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + - name: Run v0 E2E tests run: | for suite in v0_session_e2e v0_execute_e2e v0_async_execute_e2e v0_metadata_e2e v0_query_tags_headers_e2e; do @@ -123,6 +128,8 @@ jobs: DATABRICKS_TEST_CLIENT_SECRET: ${{ secrets.DATABRICKS_TEST_CLIENT_SECRET }} RUST_LOG: databricks_sql_kernel=debug RUST_BACKTRACE: 1 + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: "true" steps: - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 with: @@ -135,6 +142,9 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@166cdcfd11aee3cb47222f9ddb555ce30ddb9659 # v1.17.0 + - name: Setup sccache + uses: Mozilla-Actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 + - name: Start mitmproxy run: | docker run -d --name mitmproxy \ diff --git a/.github/workflows/securityScan.yml b/.github/workflows/securityScan.yml index b77cacd6..955ec103 100644 --- a/.github/workflows/securityScan.yml +++ b/.github/workflows/securityScan.yml @@ -64,6 +64,12 @@ on: - cron: '0 0 * * 0' # Every Sunday at midnight UTC workflow_dispatch: +concurrency: + # Coalesce only PR activity. Scheduled and manual scans remain + # distinct runs so one audit cannot cancel another. + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + permissions: id-token: write contents: read diff --git a/src/auth/oauth/m2m.rs b/src/auth/oauth/m2m.rs index 74e93ec8..5f68a795 100644 --- a/src/auth/oauth/m2m.rs +++ b/src/auth/oauth/m2m.rs @@ -324,6 +324,8 @@ impl AuthProvider for ClientCredentialsProvider { mod tests { use super::*; use crate::client::http::HttpClientConfig; + use crate::client::retry::{build_retry_configs, RetryConfig}; + use std::collections::HashMap; use wiremock::matchers::{header, method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; @@ -522,9 +524,19 @@ mod tests { .mount(&mock_server) .await; + // This test covers OIDC error propagation, not retry timing. A + // production retry ladder turns the one mocked 500 into more than a + // minute of real backoff sleeps. + let retry = RetryConfig { + max_retries: 0, + ..RetryConfig::default() + }; let http_client = Arc::new( - DatabricksHttpClient::with_default_retry(HttpClientConfig::default()) - .expect("Failed to create HTTP client"), + DatabricksHttpClient::new( + HttpClientConfig::default(), + build_retry_configs(&retry, &HashMap::new()), + ) + .expect("Failed to create HTTP client"), ); // Provider creation should fail with descriptive error diff --git a/src/auth/oauth/oidc.rs b/src/auth/oauth/oidc.rs index 32ff809b..2d0e7e3c 100644 --- a/src/auth/oauth/oidc.rs +++ b/src/auth/oauth/oidc.rs @@ -145,6 +145,8 @@ impl OidcEndpoints { mod tests { use super::*; use crate::client::http::HttpClientConfig; + use crate::client::retry::{build_retry_configs, RetryConfig}; + use std::collections::HashMap; use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; @@ -297,10 +299,19 @@ mod tests { .mount(&mock_server) .await; - // Create HTTP client + // This test covers HTTP error propagation, not retry timing. Avoid + // sleeping through the production backoff ladder for a permanent + // mocked response. + let retry = RetryConfig { + max_retries: 0, + ..RetryConfig::default() + }; let http_client = Arc::new( - DatabricksHttpClient::with_default_retry(HttpClientConfig::default()) - .expect("Failed to create HTTP client"), + DatabricksHttpClient::new( + HttpClientConfig::default(), + build_retry_configs(&retry, &HashMap::new()), + ) + .expect("Failed to create HTTP client"), ); // Discovery should fail with HTTP error diff --git a/tests/v0_session_wiremock.rs b/tests/v0_session_wiremock.rs index 24757c16..5a9b7f07 100644 --- a/tests/v0_session_wiremock.rs +++ b/tests/v0_session_wiremock.rs @@ -19,15 +19,17 @@ //! resulting `kernel_error::Error` carries the right `ErrorCode` and //! `retryable` flag. This is the §7 follow-up that PR 1 deferred — //! `Session::open` is the natural place to drive it because it -//! exercises the full HTTP path (auth header injection, retry -//! orchestration, response decoding) end to end. +//! exercises the full HTTP path (auth header injection, request +//! dispatch, response decoding) end to end. //! -//! The retry-disabled requests give us a single-shot status check -//! per status code; the three "retryable" responses (429, 503, 504) -//! are stubbed to fire enough times to exhaust the auth retry -//! ceiling so we observe the final error code. - -use databricks_sql_kernel::{AuthConfig, ConnectionConfig, ErrorCode, ResultConfig, Session}; +//! Retries are disabled because these tests verify status mapping, not +//! retry orchestration (which has dedicated coverage in the HTTP client +//! tests). This keeps retryable responses from sleeping through the +//! production backoff ladder before their final error is observable. + +use databricks_sql_kernel::{ + AuthConfig, ConnectionConfig, ErrorCode, HttpConfig, ResultConfig, Session, +}; use wiremock::matchers::{body_partial_json, method, path, query_param}; use wiremock::{Mock, MockServer, ResponseTemplate}; @@ -35,6 +37,9 @@ use wiremock::{Mock, MockServer, ResponseTemplate}; /// Returns the `Result` directly so each test can assert the error /// shape. async fn open_session_against(server: &MockServer) -> databricks_sql_kernel::Result { + let mut http = HttpConfig::default(); + http.retry_max_retries = 0; + Session::builder() .connection( ConnectionConfig::from_http_path(server.uri(), "/sql/1.0/warehouses/test_wh") @@ -43,6 +48,7 @@ async fn open_session_against(server: &MockServer) -> databricks_sql_kernel::Res .auth(AuthConfig::Pat { token: "dapi_test_token".into(), }) + .http(http) .open() .await } @@ -94,9 +100,6 @@ async fn create_session_404_maps_to_not_found() { #[tokio::test] async fn create_session_429_maps_to_resource_exhausted_retryable() { - // 429 is retryable, so the HTTP client will burn through its - // retry ceiling before surfacing the error. We stub the same - // 429 response on every attempt. let server = MockServer::start().await; Mock::given(method("POST")) .and(path("/api/2.0/sql/sessions"))