include:
  - "task-templates.yml"
  - project: 'redhat/centos-stream/ci-cd/osci-pipelines'
    file: 'rog/gitlabci-prototype.yaml'
    ref: 'main'

workflow:
  rules:
    - if: '($CI_MERGE_REQUEST_PROJECT_PATH =~ /^redhat.centos-stream/ || $CI_PROJECT_PATH =~ /^redhat.centos-stream/) &&
          $CI_PIPELINE_SOURCE == "merge_request_event" &&
          (
            $CI_PROJECT_NAME =~ /^(libkcapi|osci-internal-test-package|python-rpm-generators|python-rpm-macros|python-idna|python-pip|python3|python3.9|python3.11|python3.12|pyproject-rpm-macros)$/ ||
            ($CI_PROJECT_NAME =~ /^(cyrus-imapd|dnsconfd|docbook-dtds|docbook-style-dsssl|docbook-style-xsl|docbook5-schemas|frr|gd|gdbm|gnupg2|httpd|iprutils|kernel|libassuan|libecpg|libcupsfilters|libgcrypt|libgpg-error|libksba|libppd|libxcrypt|linuxptp|meson|rsync|wireshark|nodejs22|nodejs-nodemon|nodejs-packaging|npth|opensc|perl-DBD-MariaDB
|perl-DBD-MySQL|perl-Term-Table|pcsc-lite|pcsc-lite-ccid|pinentry|postgresql16-pgvector|ruby|rust-rpm-sequoia|star|tokyocabinet|valkey)$/ && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "c10s")
          )'
      # FUTURE: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(c8s|c9s|c10s)$/  for everything ^^^
      # Right now, the python packages owners asked for onboarding to every stream, hence them being in the first section
      variables:
        RHEL_OR_STREAM: 'centos-stream'
    - if: '($CI_MERGE_REQUEST_PROJECT_PATH =~ /^redhat.rhel/ || $CI_PROJECT_PATH =~ /^redhat.rhel/) &&
           $CI_PIPELINE_SOURCE == "merge_request_event" &&
           $CI_PROJECT_NAME =~ /^(osci-internal-test-package|some-other-package)$/ &&
           $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^rhel-\d+(\.\d+){0,2}(-main)?$/'
      variables:
        RHEL_OR_STREAM: 'rhel'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_ID == $CI_MERGE_REQUEST_PROJECT_ID'
      variables:
        PIPELINE_TYPE: 'internal'
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_PROJECT_ID != $CI_MERGE_REQUEST_PROJECT_ID'
      variables:
        PIPELINE_TYPE: 'external'
    - if: '$CI_PIPELINE_SOURCE == "push"'

.exclude_rog_components: &exclude_rog_components
  - if: '$RHEL_OR_STREAM'
    when: never

check-access:
  image: alpine:latest
  script:
    - |
      >&2 cat << EOF
      The user that initiated this pipeline does not have permissions to
      execute code within the Red Hat intranet. Please ask the Red Hat
      package maintainer to trigger the pipeline for you by clicking on
      the "Run pipeline" button on the "Pipelines" tab of the merge
      request.
      EOF
      exit 1
  rules:
    - *exclude_rog_components
    - if: '$PIPELINE_TYPE == "external"'

check-tickets:
  extends: .check-tickets
  rules:
    - *exclude_rog_components
    - if: '$PIPELINE_TYPE == "internal"'

value_of_rhel:
  stage: prep
  script:
    - echo "RHEL_OR_STREAM=$RHEL_OR_STREAM"
    - echo "PIPELINE_TYPE=$PIPELINE_TYPE"
    - echo "CI_PROJECT_NAME=$CI_PROJECT_NAME"
