From 6acc05ed190b7d6c744bc6ee69809e01bed34e3b Mon Sep 17 00:00:00 2001 From: MrSubidubi Date: Wed, 18 Mar 2026 13:35:53 +0100 Subject: [PATCH] WIP --- .github/workflows/run_tests.yml | 23 ++++--- .../src/tasks/workflows/extension_tests.rs | 4 +- .../xtask/src/tasks/workflows/run_tests.rs | 67 ++++++++++++------- tooling/xtask/src/tasks/workflows/vars.rs | 49 +++++++++++--- 4 files changed, 96 insertions(+), 47 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index fd7fecb4eb0309b7cc53c6efe0d2f2ece5f2a228..6afe7704e781f421b4433bc4a733ff702fef59ff 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -6,6 +6,7 @@ env: RUST_BACKTRACE: '1' CARGO_INCREMENTAL: '0' on: + merge_group: {} pull_request: branches: - '**' @@ -167,7 +168,7 @@ jobs: clippy_windows: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: self-32vcpu-windows-2022 steps: - name: steps::checkout_repo @@ -197,7 +198,7 @@ jobs: clippy_linux: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-16x32-ubuntu-2204 env: CC: clang @@ -235,7 +236,7 @@ jobs: clippy_mac: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-mac-large steps: - name: steps::checkout_repo @@ -266,7 +267,7 @@ jobs: run_tests_windows: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: self-32vcpu-windows-2022 steps: - name: steps::checkout_repo @@ -308,7 +309,7 @@ jobs: run_tests_linux: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-16x32-ubuntu-2204 env: CC: clang @@ -366,7 +367,7 @@ jobs: run_tests_mac: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-mac-large steps: - name: steps::checkout_repo @@ -409,7 +410,7 @@ jobs: doctests: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-16x32-ubuntu-2204 env: CC: clang @@ -453,7 +454,7 @@ jobs: check_workspace_binaries: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-8x16-ubuntu-2204 env: CC: clang @@ -497,7 +498,7 @@ jobs: check_wasm: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-8x16-ubuntu-2204 steps: - name: steps::checkout_repo @@ -536,7 +537,7 @@ jobs: check_dependencies: needs: - orchestrate - if: needs.orchestrate.outputs.run_tests == 'true' + if: needs.orchestrate.outputs.run_tests == 'true' && github.event_name != merge_group runs-on: namespace-profile-2x4-ubuntu-2404 env: CC: clang @@ -620,7 +621,7 @@ jobs: check_licenses: needs: - orchestrate - if: needs.orchestrate.outputs.run_licenses == 'true' + if: needs.orchestrate.outputs.run_licenses == 'true' && github.event_name != merge_group runs-on: namespace-profile-2x4-ubuntu-2404 steps: - name: steps::checkout_repo diff --git a/tooling/xtask/src/tasks/workflows/extension_tests.rs b/tooling/xtask/src/tasks/workflows/extension_tests.rs index caf57ce130f7d7e9f0018ef20d4cf4892823f4ab..d266a73e1737d6e1d29f278f2646442ccc93a870 100644 --- a/tooling/xtask/src/tasks/workflows/extension_tests.rs +++ b/tooling/xtask/src/tasks/workflows/extension_tests.rs @@ -30,8 +30,8 @@ pub(crate) fn extension_tests() -> Workflow { let jobs = [ orchestrate, - should_check_rust.guard(check_rust()), - should_check_extension.guard(check_extension()), + should_check_rust.and_always().guard(check_rust()), + should_check_extension.and_always().guard(check_extension()), ]; let tests_pass = tests_pass(&jobs, &[]); diff --git a/tooling/xtask/src/tasks/workflows/run_tests.rs b/tooling/xtask/src/tasks/workflows/run_tests.rs index 3ca8e456346dc5b1bbea89ca40993456e4f1354c..45933826ee02effcf97aca6804dab6c38fcc0710 100644 --- a/tooling/xtask/src/tasks/workflows/run_tests.rs +++ b/tooling/xtask/src/tasks/workflows/run_tests.rs @@ -1,5 +1,5 @@ use gh_workflow::{ - Concurrency, Container, Event, Expression, Input, Job, Level, Permissions, Port, PullRequest, + Container, Event, Expression, Input, Job, Level, MergeGroup, Permissions, Port, PullRequest, Push, Run, Step, Strategy, Use, UsesJob, Workflow, }; use indexmap::IndexMap; @@ -48,24 +48,49 @@ pub(crate) fn run_tests() -> Workflow { let mut jobs = vec![ orchestrate, check_style(), - should_run_tests.guard(clippy(Platform::Windows)), - should_run_tests.guard(clippy(Platform::Linux)), - should_run_tests.guard(clippy(Platform::Mac)), - should_run_tests.guard(run_platform_tests(Platform::Windows)), - should_run_tests.guard(run_platform_tests(Platform::Linux)), - should_run_tests.guard(run_platform_tests(Platform::Mac)), - should_run_tests.guard(doctests()), - should_run_tests.guard(check_workspace_binaries()), - should_run_tests.guard(check_wasm()), - should_run_tests.guard(check_dependencies()), // could be more specific here? - should_check_docs.guard(check_docs()), - should_check_licences.guard(check_licenses()), - should_check_scripts.guard(check_scripts()), + should_run_tests + .and_not_in_merge_queue() + .guard(clippy(Platform::Windows)), + should_run_tests + .and_not_in_merge_queue() + .guard(clippy(Platform::Linux)), + should_run_tests + .and_not_in_merge_queue() + .guard(clippy(Platform::Mac)), + should_run_tests + .and_not_in_merge_queue() + .guard(run_platform_tests(Platform::Windows)), + should_run_tests + .and_not_in_merge_queue() + .guard(run_platform_tests(Platform::Linux)), + should_run_tests + .and_not_in_merge_queue() + .guard(run_platform_tests(Platform::Mac)), + should_run_tests.and_not_in_merge_queue().guard(doctests()), + should_run_tests + .and_not_in_merge_queue() + .guard(check_workspace_binaries()), + should_run_tests + .and_not_in_merge_queue() + .guard(check_wasm()), + should_run_tests + .and_not_in_merge_queue() + .guard(check_dependencies()), // could be more specific here? + should_check_docs.and_always().guard(check_docs()), + should_check_licences + .and_not_in_merge_queue() + .guard(check_licenses()), + should_check_scripts.and_always().guard(check_scripts()), ]; let ext_tests = extension_tests(); let tests_pass = tests_pass(&jobs, &[&ext_tests.name]); - jobs.push(should_run_tests.guard(check_postgres_and_protobuf_migrations())); // could be more specific here? + // TODO: For merge queues, this should fail in the merge queue context + jobs.push( + should_run_tests + .and_always() + .guard(check_postgres_and_protobuf_migrations()), + ); // could be more specific here? named::workflow() .add_event( @@ -75,16 +100,10 @@ pub(crate) fn run_tests() -> Workflow { .add_branch("main") .add_branch("v[0-9]+.[0-9]+.x"), ) - .pull_request(PullRequest::default().add_branch("**")), - ) - .concurrency( - Concurrency::default() - .group(concat!( - "${{ github.workflow }}-${{ github.ref_name }}-", - "${{ github.ref_name == 'main' && github.sha || 'anysha' }}" - )) - .cancel_in_progress(true), + .pull_request(PullRequest::default().add_branch("**")) + .merge_group(MergeGroup::default()), ) + .concurrency(vars::one_workflow_per_non_main_branch()) .add_env(("CARGO_TERM_COLOR", "always")) .add_env(("RUST_BACKTRACE", 1)) .add_env(("CARGO_INCREMENTAL", 0)) diff --git a/tooling/xtask/src/tasks/workflows/vars.rs b/tooling/xtask/src/tasks/workflows/vars.rs index b3f8bdf56e9bb0f93f81992fbc61dab2b9754e63..b573a038be5a0ab5837dced336a53b82a148c5fb 100644 --- a/tooling/xtask/src/tasks/workflows/vars.rs +++ b/tooling/xtask/src/tasks/workflows/vars.rs @@ -1,4 +1,4 @@ -use std::cell::RefCell; +use std::{cell::RefCell, ops::Not}; use gh_workflow::{ Concurrency, Env, Expression, Step, WorkflowCallInput, WorkflowCallSecret, @@ -130,21 +130,50 @@ impl PathCondition { set_by_step: Default::default(), } } - pub fn guard(&self, job: NamedJob) -> NamedJob { + + pub fn and_always<'a>(&'a self) -> PathContextCondition<'a> { + PathContextCondition { + condition: self, + run_in_merge_queue: true, + } + } + + pub fn and_not_in_merge_queue<'a>(&'a self) -> PathContextCondition<'a> { + PathContextCondition { + condition: self, + run_in_merge_queue: false, + } + } +} + +pub struct PathContextCondition<'a> { + condition: &'a PathCondition, + run_in_merge_queue: bool, +} + +impl<'a> PathContextCondition<'a> { + pub fn guard(&'a self, job: NamedJob) -> NamedJob { let set_by_step = self + .condition .set_by_step .borrow() .clone() - .unwrap_or_else(|| panic!("condition {},is never set", self.name)); + .unwrap_or_else(|| panic!("condition {},is never set", self.condition.name)); NamedJob { name: job.name, - job: job - .job - .add_need(set_by_step.clone()) - .cond(Expression::new(format!( - "needs.{}.outputs.{} == 'true'", - &set_by_step, self.name - ))), + job: job.job.add_need(set_by_step.clone()).cond(Expression::new( + format!( + "needs.{}.outputs.{} == 'true' {merge_queue_condition}", + &set_by_step, + self.condition.name, + merge_queue_condition = self + .run_in_merge_queue + .not() + .then_some("&& github.event_name != merge_group") + .unwrap_or_default() + ) + .trim(), + )), } } }