CI: port to rules (MR 4966)

Rules are the new and much more configurable way to handle conditionally
enabling jobs. Replace the old "only" keyword usage with equivalent
rules.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-03-25 23:37:41 +00:00 committed by Oliver Smith
parent 1526420d86
commit fb8851447b
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB

View file

@ -8,29 +8,24 @@ stages:
- lint - lint
- build - build
# defaults for "only" # This defines the rules for when a pipeline should run.
# We need to run the CI jobs in a "merge request specific context", if CI is workflow:
# running in a merge request. Otherwise the environment variable that holds the rules:
# merge request ID is not available. This means, we must set the "only" # Don't run branch pipeline if an MR is open (only the MR pipeline will run)
# variable accordingly - and if we only do it for one job, all other jobs will - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
# not get executed. So have the defaults here, and use them in all jobs that when: never
# should run on both the master branch, and in merge requests. # Run for merge requests
# https://docs.gitlab.com/ee/ci/merge_request_pipelines/index.html#excluding-certain-jobs - if: $CI_PIPELINE_SOURCE == "merge_request_event"
.only-default: &only-default # Run scheduled pipeline for autoupdate
only: - if: $CI_PIPELINE_SOURCE == "schedule"
- master
- merge_requests
- tags
# device documentation # device documentation
wiki: wiki:
stage: lint stage: lint
<<: *only-default rules:
only: - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
refs: changes:
- merge_requests - device/*/device-*/*
changes:
- device/*/device-*/*
script: script:
- .ci/lib/gitlab_prepare_ci.sh - .ci/lib/gitlab_prepare_ci.sh
- .ci/wiki.sh - .ci/wiki.sh
@ -38,14 +33,12 @@ wiki:
# testcases linting # testcases linting
ruff: ruff:
stage: lint stage: lint
<<: *only-default rules:
only: - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
refs: changes:
- merge_requests - .ci/*
changes: - .ci/*/*
- .ci/* - .gitlab-ci.yml
- .ci/*/*
- .gitlab-ci.yml
before_script: before_script:
- "echo 'https://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories" - "echo 'https://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories"
script: script:
@ -55,8 +48,9 @@ ruff:
# shellcheck and various grep checks # shellcheck and various grep checks
shellcheck-grep: shellcheck-grep:
stage: lint stage: lint
<<: *only-default
image: alpine:edge image: alpine:edge
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
script: script:
- .ci/lib/gitlab_prepare_ci.sh - .ci/lib/gitlab_prepare_ci.sh
- .ci/shellcheck.sh - .ci/shellcheck.sh
@ -65,8 +59,9 @@ shellcheck-grep:
editor-config: editor-config:
stage: lint stage: lint
<<: *only-default
image: alpine:edge image: alpine:edge
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
script: script:
- .ci/lib/gitlab_prepare_ci.sh - .ci/lib/gitlab_prepare_ci.sh
- .ci/ec.sh - .ci/ec.sh
@ -74,7 +69,8 @@ editor-config:
# aports checks (generic) # aports checks (generic)
pytest-commits: pytest-commits:
stage: lint stage: lint
<<: *only-default rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
script: script:
- .ci/lib/gitlab_prepare_ci.sh - .ci/lib/gitlab_prepare_ci.sh
- .ci/pytest.sh - .ci/pytest.sh
@ -90,23 +86,21 @@ pytest-commits:
# APKBUILD linting # APKBUILD linting
aport-lint: aport-lint:
stage: lint stage: lint
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
script: script:
- .ci/lib/gitlab_prepare_ci.sh - .ci/lib/gitlab_prepare_ci.sh
- .ci/apkbuild-lint.sh - .ci/apkbuild-lint.sh
only:
- merge_requests
allow_failure: true allow_failure: true
# kernel kconfig check # kernel kconfig check
kernel-kconfig: kernel-kconfig:
stage: lint stage: lint
only: rules:
refs: - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
- master changes:
- merge_requests - device/*/linux-*/config-*
changes: - main/linux-*/config-*
- device/*/linux-*/config-*
- main/linux-*/config-*
script: script:
- .ci/lib/gitlab_prepare_ci.sh - .ci/lib/gitlab_prepare_ci.sh
- .ci/kconfig.sh - .ci/kconfig.sh
@ -115,8 +109,8 @@ kernel-kconfig:
# (Checks for "Allow commits from members who can merge to the target branch") # (Checks for "Allow commits from members who can merge to the target branch")
mr-settings: mr-settings:
stage: lint stage: lint
only: rules:
- merge_requests - if: $CI_PIPELINE_SOURCE == "merge_request_event"
before_script: before_script:
- apk -q add python3 - apk -q add python3
script: script:
@ -126,7 +120,8 @@ mr-settings:
# build changed aports # build changed aports
.build: .build:
stage: build stage: build
<<: *only-default rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_REF_PROTECTED == "false"
before_script: before_script:
- .ci/lib/gitlab_prepare_ci.sh - .ci/lib/gitlab_prepare_ci.sh
after_script: after_script: