variables:
  GIT_STRATEGY: "clone"
  BUILD_IMAGE_CENTOS7: "git.mesalab.cn:7443/mesa_platform/build-env:master"
  BUILD_IMAGE_CENTOS8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux"
  BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
  INSTALL_DEPENDENCY_LIBRARY: framework_env openssl-devel libasan libfieldstat3-devel

stages:
- build

.build_before_script:
  before_script:
  - mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/
  - ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
  - cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH
  - chmod +x ./ci/travis.sh
  - yum makecache
  - yum install -y elfutils-libelf-devel


.build_by_travis_for_centos7:
  stage: build
  image: $BUILD_IMAGE_CENTOS7
  extends: .build_before_script
  script:
    - yum install -y libmnl-devel
    - yum install -y libnfnetlink-devel
    - ./ci/travis.sh
      - cd build
  tags:
  - share

.build_by_travis_for_centos8:
  stage: build
  image: $BUILD_IMAGE_CENTOS8
  extends: .build_before_script
  script:
    - dnf --enablerepo=powertools install -y libmnl-devel
    - dnf --enablerepo=powertools install -y libnfnetlink-devel
    - ./ci/travis.sh
  tags:
    - share

branch_build_debug_for_centos7:
  stage: build
  extends: .build_by_travis_for_centos7
  variables:
    BUILD_TYPE: Debug
  except:
    - /^develop.*$/i
    - /^master.*$/i
    - tags

branch_build_release_for_centos7:
  stage: build
  variables:
    BUILD_TYPE: RelWithDebInfo
  extends: .build_by_travis_for_centos7
  except:
    - /^develop.*$/i
    - /^master.*$/i
    - tags

develop_build_debug_for_centos7:
  stage: build
  extends: .build_by_travis_for_centos7
  variables:
    BUILD_TYPE: Debug
    PACKAGE: 1
    UPLOAD: 1
    ASAN_OPTION: ADDRESS
    TESTING_VERSION_BUILD: 1
    PULP3_REPO_NAME: framework-testing-x86_64.el7
    PULP3_DIST_NAME: framework-testing-x86_64.el7
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-debug"
    paths:
      - build/*.rpm
  only:
    - /^develop.*$/i
    - /^master.*$/i

develop_build_release_for_centos7:
  stage: build
  extends: .build_by_travis_for_centos7
  variables:
    BUILD_TYPE: RelWithDebInfo
    PACKAGE: 1
    UPLOAD: 1
    TESTING_VERSION_BUILD: 1
    PULP3_REPO_NAME: framework-testing-x86_64.el7
    PULP3_DIST_NAME: framework-testing-x86_64.el7
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - /^develop.*$/i
    - /^master.*$/i

release_build_debug_for_centos7:
  stage: build
  variables:
    BUILD_TYPE: Debug
    PACKAGE: 1
    UPLOAD: 1
    PULP3_REPO_NAME: framework-stable-x86_64.el7
    PULP3_DIST_NAME: framework-stable-x86_64.el7
  extends: .build_by_travis_for_centos7
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-debug"
    paths:
      - build/*.rpm
  only:
    - tags

release_build_release_for_centos7:
  stage: build
  variables:
    BUILD_TYPE: RelWithDebInfo
    PACKAGE: 1
    UPLOAD: 1
    UPLOAD_SYMBOL_FILES: 1
    SYMBOL_TARGET: libmaat4
    PULP3_REPO_NAME: framework-stable-x86_64.el7
    PULP3_DIST_NAME: framework-stable-x86_64.el7
  extends: .build_by_travis_for_centos7
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - tags

branch_build_debug_for_centos8:
  stage: build
  extends: .build_by_travis_for_centos8
  variables:
    BUILD_TYPE: Debug
  except:
    - /^develop.*$/i
    - /^master.*$/i
    - tags

branch_build_release_for_centos8:
  stage: build
  variables:
    BUILD_TYPE: RelWithDebInfo
  extends: .build_by_travis_for_centos8
  except:
    - /^develop.*$/i
    - /^master.*$/i
    - tags

develop_build_debug_for_centos8:
  stage: build
  extends: .build_by_travis_for_centos8
  variables:
    BUILD_TYPE: Debug
    PACKAGE: 1
    UPLOAD: 1
    ASAN_OPTION: ADDRESS
    TESTING_VERSION_BUILD: 1
    PULP3_REPO_NAME: framework-testing-x86_64.el8
    PULP3_DIST_NAME: framework-testing-x86_64.el8
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-debug"
    paths:
      - build/*.rpm
  only:
    - /^develop.*$/i
    - /^master.*$/i

develop_build_release_for_centos8:
  stage: build
  extends: .build_by_travis_for_centos8
  variables:
    BUILD_TYPE: RelWithDebInfo
    PACKAGE: 1
    UPLOAD: 1
    TESTING_VERSION_BUILD: 1
    PULP3_REPO_NAME: framework-testing-x86_64.el8
    PULP3_DIST_NAME: framework-testing-x86_64.el8
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - /^develop.*$/i
    - /^master.*$/i

release_build_debug_for_centos8:
  stage: build
  variables:
    BUILD_TYPE: Debug
    PACKAGE: 1
    UPLOAD: 1
    PULP3_REPO_NAME: framework-stable-x86_64.el8
    PULP3_DIST_NAME: framework-stable-x86_64.el8
  extends: .build_by_travis_for_centos8
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-debug"
    paths:
      - build/*.rpm
  only:
    - tags

release_build_release_for_centos8:
  stage: build
  variables:
    BUILD_TYPE: RelWithDebInfo
    PACKAGE: 1
    UPLOAD: 1
    UPLOAD_SYMBOL_FILES: 1
    SYMBOL_TARGET: libmaat4
    PULP3_REPO_NAME: framework-stable-x86_64.el8
    PULP3_DIST_NAME: framework-stable-x86_64.el8
  extends: .build_by_travis_for_centos8
  artifacts:
    name: "maat4-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - tags
