From 56263417b5290266e436c24973780804be41dd81 Mon Sep 17 00:00:00 2001 From: "Xuan (Sean) Hu" Date: Sat, 13 Jan 2024 14:12:49 +0800 Subject: [PATCH] chore: Use `rules` instead of `only` in GitLab CI/CD. (#269) --- .gitlab/ci/ci.yml | 6 +++--- .gitlab/ci/devcontainer.yml | 6 ++++-- .gitlab/ci/mr.yml | 4 ++-- .gitlab/ci/release.yml | 16 ++++++++-------- .../ci/ci.yml.jinja | 6 +++--- .../ci/devcontainer.yml | 6 ++++-- .../ci/mr.yml | 4 ++-- .../ci/release.yml | 16 ++++++++-------- 8 files changed, 34 insertions(+), 30 deletions(-) diff --git a/.gitlab/ci/ci.yml b/.gitlab/ci/ci.yml index b41ff8ad..c5e6205e 100644 --- a/.gitlab/ci/ci.yml +++ b/.gitlab/ci/ci.yml @@ -7,9 +7,6 @@ ci: coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/ image: ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION} interruptible: true - only: - - main - - merge_requests parallel: matrix: - PYTHON_VERSION: @@ -18,6 +15,9 @@ ci: - '3.10' - '3.11' - '3.12' + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: - env | sort - make dev diff --git a/.gitlab/ci/devcontainer.yml b/.gitlab/ci/devcontainer.yml index fd4e1e43..98a47ca0 100644 --- a/.gitlab/ci/devcontainer.yml +++ b/.gitlab/ci/devcontainer.yml @@ -1,8 +1,6 @@ devcontainer-prebuild: image: docker:latest interruptible: true - only: - - main parallel: matrix: - PYTHON_VERSION: @@ -11,6 +9,10 @@ devcontainer-prebuild: - '3.10' - '3.11' - '3.12' + rules: + - changes: + - .devcontainer/prebuild/**/* + if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH script: - apk add --update nodejs npm python3 make g++ - npm install -g @devcontainers/cli diff --git a/.gitlab/ci/mr.yml b/.gitlab/ci/mr.yml index 1062de6c..45a926d3 100644 --- a/.gitlab/ci/mr.yml +++ b/.gitlab/ci/mr.yml @@ -1,7 +1,7 @@ lint_title: interruptible: true - only: - - merge_requests + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: - | if ! echo "$CI_MERGE_REQUEST_TITLE" | grep -Pq '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?!?:\s.*'; then diff --git a/.gitlab/ci/release.yml b/.gitlab/ci/release.yml index b761e1ee..32b2054f 100644 --- a/.gitlab/ci/release.yml +++ b/.gitlab/ci/release.yml @@ -4,8 +4,8 @@ docs: - public - docs/changelog.md - release-notes.md - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort - make dev-docs @@ -15,8 +15,8 @@ docs: package: needs: - release - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort - make publish @@ -28,8 +28,8 @@ pages: needs: - release - docs - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort stage: release @@ -37,11 +37,11 @@ release: image: registry.gitlab.com/gitlab-org/release-cli:latest needs: - docs - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ release: description: release-notes.md tag_name: $CI_COMMIT_TAG + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort stage: release diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/ci.yml.jinja b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/ci.yml.jinja index 8f6d23eb..6a1c94b3 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/ci.yml.jinja +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/ci.yml.jinja @@ -8,9 +8,6 @@ ci: coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/ image: ${CI_REGISTRY_IMAGE}:dev-py${PYTHON_VERSION} interruptible: true - only: - - main - - merge_requests parallel: matrix: - PYTHON_VERSION: @@ -29,6 +26,9 @@ ci: [%- if version_between("3.12", min_py, max_py) %] - '3.12' [%- endif %] + rules: + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: - env | sort - make dev diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/devcontainer.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/devcontainer.yml index fd4e1e43..98a47ca0 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/devcontainer.yml +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/devcontainer.yml @@ -1,8 +1,6 @@ devcontainer-prebuild: image: docker:latest interruptible: true - only: - - main parallel: matrix: - PYTHON_VERSION: @@ -11,6 +9,10 @@ devcontainer-prebuild: - '3.10' - '3.11' - '3.12' + rules: + - changes: + - .devcontainer/prebuild/**/* + if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH script: - apk add --update nodejs npm python3 make g++ - npm install -g @devcontainers/cli diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/mr.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/mr.yml index 1062de6c..45a926d3 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/mr.yml +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/mr.yml @@ -1,7 +1,7 @@ lint_title: interruptible: true - only: - - merge_requests + rules: + - if: $CI_PIPELINE_SOURCE == 'merge_request_event' script: - | if ! echo "$CI_MERGE_REQUEST_TITLE" | grep -Pq '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(\w+\))?!?:\s.*'; then diff --git a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/release.yml b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/release.yml index b761e1ee..32b2054f 100644 --- a/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/release.yml +++ b/template/[% if repo_host_type == 'gitlab.com' or repo_host_type == 'gitlab-self-managed' %].gitlab[% endif %]/ci/release.yml @@ -4,8 +4,8 @@ docs: - public - docs/changelog.md - release-notes.md - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort - make dev-docs @@ -15,8 +15,8 @@ docs: package: needs: - release - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort - make publish @@ -28,8 +28,8 @@ pages: needs: - release - docs - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort stage: release @@ -37,11 +37,11 @@ release: image: registry.gitlab.com/gitlab-org/release-cli:latest needs: - docs - only: - - /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ release: description: release-notes.md tag_name: $CI_COMMIT_TAG + rules: + - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: - env | sort stage: release