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 <daniels@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35203>
This commit is contained in:
Daniel Stone 2025-05-28 12:55:41 +01:00 committed by Marge Bot
parent a3efd8284a
commit fe8bc3f23e

View file

@ -198,18 +198,25 @@
rules: rules:
- !reference [.never-post-merge-rules, rules] - !reference [.never-post-merge-rules, rules]
- !reference [.no_scheduled_pipelines-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.yml
- .gitlab-ci/**/* - .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 - src/**/*.rs
when: on_success when: on_success
allow_failure: false allow_failure: false
# in other pipelines, formatting checks are allowed to fail - if: *is-merge-attempt
- changes: *rust_file_list when: never
when: on_success - 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 allow_failure: true
# Rules for .mr-label-maker.yml # Rules for .mr-label-maker.yml