From fe8bc3f23e3bc01ff7af90ad3b25aef410fd51ad Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Wed, 28 May 2025 12:55:41 +0100 Subject: [PATCH] ci: Only run rustfmt when necessary The rules we want here are pretty simple: - only run rustfmt when Rust code changes, to the extent that we can tell what has or hasn't changed (only really reliable for pre-merge) - make rustfmt success mandatory for pre-merge, advisory for other branches Encode that, and make sure we don't run rustfmt when we don't need to. Signed-off-by: Daniel Stone Part-of: --- .gitlab-ci/test-source-dep.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci/test-source-dep.yml b/.gitlab-ci/test-source-dep.yml index 2ed42f5f2ef..c656b9f11c0 100644 --- a/.gitlab-ci/test-source-dep.yml +++ b/.gitlab-ci/test-source-dep.yml @@ -198,18 +198,25 @@ rules: - !reference [.never-post-merge-rules, rules] - !reference [.no_scheduled_pipelines-rules, rules] - - changes: + # pre-merge: must succeed if changing Rust, skip if not + - if: &is-merge-attempt $GITLAB_USER_LOGIN == "marge-bot" && $CI_PIPELINE_SOURCE == "merge_request_event" + changes: &rustfmt_files - .gitlab-ci.yml - .gitlab-ci/**/* - # in merge pipeline, formatting checks are not allowed to fail - - if: $GITLAB_USER_LOGIN == "marge-bot" && $CI_PIPELINE_SOURCE == "merge_request_event" - changes: &rust_file_list - src/**/*.rs when: on_success allow_failure: false - # in other pipelines, formatting checks are allowed to fail - - changes: *rust_file_list - when: on_success + - if: *is-merge-attempt + when: never + - if: &is-merge-request $CI_PIPELINE_SOURCE == "merge_request_event" + changes: + *rustfmt_files + when: manual + allow_failure: false + - if: *is-merge-request + when: never + # non-pre-merge: run but only advisory + - when: manual allow_failure: true # Rules for .mr-label-maker.yml