ci: Avoid duplicate pipelines vol 2

This is a followup to GNOME/mutter!1578

This commit does a couple of things to avoid creating multiple
pipelines per commit.

First, it avoid catch all `when: manual` rules, which might
end up matching custom variables set which might potentially
not be handled.

Secondly it reworks the `workflow:rules:` and the pipeline guard
rules to avoid duplicate pipelines as the gitlab documentation
suggests.

Last, it switches from yaml anchors to the new `reference` gitlab
keyword which is more flexible.

https://docs.gitlab.com/ee/ci/jobs/job_control.html#avoid-duplicate-pipelines

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2534>
This commit is contained in:
Jordan Petridis 2022-07-26 22:36:22 +03:00 committed by Marge Bot
parent 642791673c
commit 5d81f6d89d

View File

@ -146,17 +146,31 @@ default:
workflow:
rules:
- if: '$CI_MERGE_REQUEST_IID'
- if: '$CI_COMMIT_TAG'
# Allow to switch from branch pipelines to MR pipelines seamlessly
# https://docs.gitlab.com/ee/ci/jobs/job_control.html#avoid-duplicate-pipelines
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# Don't trigger a branch pipeline if there is an open MR
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: '$CI_COMMIT_BRANCH'
- if: '$CI_COMMIT_TAG'
.pipline-guard: &pipline-guard
.pipeline-guard:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_TAG'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- if: '$CI_COMMIT_BRANCH =~ /^gnome-[0-9-]+$/'
- when: 'manual'
# Avoid catchall `when: manual` rule which might
# cause duplicate pipelines to be triggered.
# https://docs.gitlab.com/ee/ci/jobs/job_control.html#avoid-duplicate-pipelines
#
# Also make it so pipelines without MR need to be started
# manually, since their state will most likely be WIP
- if: '$CI_COMMIT_BRANCH'
when: 'manual'
check-commit-log:
extends:
@ -177,7 +191,8 @@ check-commit-log:
- commit-message-junit-report.xml
reports:
junit: commit-message-junit-report.xml
<<: *pipline-guard
rules:
- !reference [.pipeline-guard, rules]
check-merge-request:
extends:
@ -198,7 +213,8 @@ check-merge-request:
- check-merge-request-report.xml
reports:
junit: check-merge-request-report.xml
<<: *pipline-guard
rules:
- !reference [.pipeline-guard, rules]
build-fedora-container@x86_64:
extends:
@ -447,7 +463,8 @@ test-mutter-coverity:
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule" && $MUTTER_SCHEDULED_JOB == "coverity"'
when: always
- when: manual
- if: '$CI_COMMIT_BRANCH'
when: 'manual'
extends:
- .fdo.distribution-image@fedora
- .mutter.fedora:35@x86_64