# if anchors
.if-ref-master: &if-ref-master
  if: '$CI_COMMIT_REF_NAME == "master"'

.if-tag-release-no_label: &if-tag-release-no_label
  if: '$CI_COMMIT_TAG =~ /^v\d+\.\d+(\.\d+)?($|-)/ && $BOT_TRIGGER_WITH_LABEL == null'

.if-protected: &if-protected
  if: '($CI_COMMIT_REF_NAME == "master" || $CI_COMMIT_BRANCH =~ /^release\/v/ || $CI_COMMIT_TAG =~ /^v\d+\.\d+(\.\d+)?($|-)/)'

.if-protected-no_label: &if-protected-no_label
  if: '($CI_COMMIT_REF_NAME == "master" || $CI_COMMIT_BRANCH =~ /^release\/v/ || $CI_COMMIT_TAG =~ /^v\d+\.\d+(\.\d+)?($|-)/) && $BOT_TRIGGER_WITH_LABEL == null'

.if-dev-push: &if-dev-push
  if: '$CI_COMMIT_REF_NAME != "master" && $CI_COMMIT_BRANCH !~ /^release\/v/ && $CI_COMMIT_TAG !~ /^v\d+\.\d+(\.\d+)?($|-)/ && ($CI_PIPELINE_SOURCE == "push" || $CI_PIPELINE_SOURCE == "merge_request_event")'

.if-schedule: &if-schedule
  if: '$CI_PIPELINE_SOURCE == "schedule"'

.if-trigger: &if-trigger
  if: '$CI_PIPELINE_SOURCE == "trigger"'

.if-label-regular_test: &if-label-regular_test
  if: '$BOT_LABEL_REGULAR_TEST'

.if-label-build: &if-label-build
  if: '$BOT_LABEL_BUILD'

.if-label-build_docs: &if-label-build_docs
  if: '$BOT_LABEL_BUILD_DOCS'

.if-label-integration_test: &if-label-integration_test
  if: '$BOT_LABEL_INTEGRATION_TEST'

.if-label-unit_test: &if-label-unit_test
  if: '$BOT_LABEL_UNIT_TEST'

.if-label-unit_test-32: &if-label-unit_test-32
  if: '$BOT_LABEL_UNIT_TEST_32'

.if-label-unit_test-s2: &if-label-unit_test-s2
  if: '$BOT_LABEL_UNIT_TEST_S2'

.if-label-unit_test-c3: &if-label-unit_test-c3
  if: '$BOT_LABEL_UNIT_TEST_C3'

.if-label-unit_test-all_labels: &if-label-unit_test-all_labels
  if: '$BOT_LABEL_UNIT_TEST || $BOT_LABEL_UNIT_TEST_32 || $BOT_LABEL_UNIT_TEST_S2 || $BOT_LABEL_UNIT_TEST_C3'

.if-label-weekend_test: &if-label-weekend_test
  if: '$BOT_LABEL_WEEKEND_TEST'

.if-label-example_test: &if-label-example_test
  if: '$BOT_LABEL_EXAMPLE_TEST'

.if-label-custom_test: &if-label-custom_test
  if: '$BOT_LABEL_CUSTOM_TEST'

.if-label-host_test: &if-label-host_test
  if: '$BOT_LABEL_HOST_TEST'

.if-label-fuzzer_test: &if-label-fuzzer_test
  if: '$BOT_LABEL_FUZZER_TEST'

.if-label-nvs_coverage: &if-label-nvs_coverage
  if: '$BOT_LABEL_NVS_COVERAGE'

.if-label-static_analysis: &if-label-static_analysis
  if: '$BOT_LABEL_STATIC_ANALYSIS || $BOT_LABEL_STATIC_ANALYSIS_ALL'

.if-label-iperf_stress_test: &if-label-iperf_stress_test
  if: '$BOT_LABEL_IPERF_STRESS_TEST'

.if-os-mac: &if-os-mac
  if: '$BOT_LABEL_MACOS_TEST'

# Rules templates
.rules:protected:
  rules:
    - <<: *if-protected

.rules:protected-no_label:
  rules:
    - <<: *if-protected-no_label

.rules:protected-schedule:
  rules:
    - <<: *if-protected
    - <<: *if-schedule

.rules:trigger:
  rules:
    - <<: *if-trigger

.rules:dev:
  rules:
    - <<: *if-trigger
    - <<: *if-dev-push

.rules:os:mac_os:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-os-mac

.rules:tag:release-no_label:
  rules:
    - <<: *if-tag-release-no_label

.rules:ref:master-schedule:
  rules:
    - <<: *if-ref-master
    - <<: *if-schedule

.rules:ref:master-schedule-always:
  rules:
    - <<: *if-ref-master
      when: always
    - <<: *if-schedule
      when: always

.rules:labels:static_analysis-only:
  rules:
    - <<: *if-label-static_analysis

.rules:labels:build:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-regular_test
    - <<: *if-label-build

.rules:labels:build_docs:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-build_docs

.rules:labels:build_docs-slim:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build_docs

.rules:labels:build_docs-preview:
  rules:
    - <<: *if-label-build_docs

.rules:labels:weekend_test-only:
  rules:
    - <<: *if-label-weekend_test

.rules:labels:iperf_stress_test-only:
  rules:
    - <<: *if-label-iperf_stress_test

.rules:labels:fuzzer_test-weekend_test-only:
  rules:
    - <<: *if-label-fuzzer_test
    - <<: *if-label-weekend_test

.rules:labels:nvs_coverage-only:
  rules:
    - <<: *if-label-nvs_coverage

.rules:labels:host_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-regular_test
    - <<: *if-label-host_test

.rules:tests:example_test-schedule:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-example_test
    - <<: *if-schedule

.rules:tests:custom_test-schedule:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-custom_test
    - <<: *if-schedule

.rules:tests:unit_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-unit_test-all_labels

.rules:tests:unit_test_32:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-unit_test
    - <<: *if-label-unit_test-32

.rules:tests:unit_test_s2:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-unit_test
    - <<: *if-label-unit_test-s2

.rules:tests:unit_test_c3:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-unit_test
    - <<: *if-label-unit_test-c3

.rules:tests:integration_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-integration_test

.rules:assign_test:target_test-integration_test-weekend_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-regular_test
    - <<: *if-label-example_test
    - <<: *if-label-custom_test
    - <<: *if-label-unit_test-all_labels
    - <<: *if-label-integration_test
    - <<: *if-label-weekend_test

.rules:build_tests:integration_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-integration_test

.rules:build_tests:weekend_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-weekend_test

.rules:build_tests:unit_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-unit_test-all_labels

.rules:build_tests:example_test-weekend_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-example_test
    - <<: *if-label-weekend_test

.rules:build_tests:custom_test-weekend_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-custom_test
    - <<: *if-label-weekend_test

.rules:build_tests:target_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-example_test
    - <<: *if-label-custom_test
    - <<: *if-label-unit_test-all_labels

.rules:build_tests:target_test-weekend_test:
  rules:
    - <<: *if-protected-no_label
    - <<: *if-label-build
    - <<: *if-label-regular_test
    - <<: *if-label-example_test
    - <<: *if-label-custom_test
    - <<: *if-label-unit_test-all_labels
    - <<: *if-label-weekend_test
