variables:
  GIT_STRATEGY: "clone"
  BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/
  INSTALL_PREFIX: "/opt/tsg/tfe"
  TESTING_VERSION_BUILD: 0
  BUILD_IMAGE_CENTOS7: "git.mesalab.cn:7443/mesa_platform/build-env:master"
  BUILD_IMAGE_CENTOS8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux"

stages:
  - build
  - envelope
  - upload

.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
  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
    - dnf --enablerepo=powertools install -y clang
    - dnf --enablerepo=powertools install -y llvm
    - dnf --enablerepo=powertools install -y libbpf-devel
    - dnf --enablerepo=powertools install -y liburing-devel
    - ./ci/travis.sh
  tags:
    - share

###############################################################################
# compile use image: build-env:master
###############################################################################

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

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

develop_build_debug_for_centos7:
  extends: .build_by_travis_for_centos7
  variables:
    TESTING_VERSION_BUILD: 1
    #UPLOAD_SYMBOL_FILES: 1
    BUILD_TYPE: Debug
    # ASAN_OPTION: ADDRESS
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-testing-x86_64.el7
    PULP3_DIST_NAME: tfe-testing-x86_64.el7
  artifacts:
    name: "tfe-develop-$CI_COMMIT_REF_NAME-debug"
    paths:
      - build/*.rpm
  only:
    - /^develop-.*$/i
    - /^release-.*$/i

develop_build_release_for_centos7:
  extends: .build_by_travis_for_centos7
  variables:
    TESTING_VERSION_BUILD: 1
    #UPLOAD_SYMBOL_FILES: 1
    # ASAN_OPTION: ADDRESS
    BUILD_TYPE: RelWithDebInfo
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-testing-x86_64.el7
    PULP3_DIST_NAME: tfe-testing-x86_64.el7
  artifacts:
    name: "tfe-develop-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - /^develop-.*$/i
    - /^release-.*$/i

release_build_debug_for_centos7:
  variables:
    #UPLOAD_SYMBOL_FILES: 1
    BUILD_TYPE: Debug
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-stable-x86_64.el7
    PULP3_DIST_NAME: tfe-stable-x86_64.el7
  extends: .build_by_travis_for_centos7
  artifacts:
    name: "tfe-install-$CI_COMMIT_REF_NAME-debug"
    paths:
    - build/*.rpm
  only:
    - tags

release_build_release_for_centos7:
  variables:
    BUILD_TYPE: RelWithDebInfo
    #UPLOAD_SYMBOL_FILES: 1
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-stable-x86_64.el7
    PULP3_DIST_NAME: tfe-stable-x86_64.el7
  extends: .build_by_travis_for_centos7
  artifacts:
    name: "tfe-install-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - tags

###############################################################################
# compile use image: build-env:rockylinux
###############################################################################

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

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

develop_build_debug_for_centos8:
  extends: .build_by_travis_for_centos8
  variables:
    TESTING_VERSION_BUILD: 1
    #UPLOAD_SYMBOL_FILES: 1
    BUILD_TYPE: Debug
    # ASAN_OPTION: ADDRESS
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-testing-x86_64.el8
    PULP3_DIST_NAME: tfe-testing-x86_64.el8
  artifacts:
    name: "tfe-develop-$CI_COMMIT_REF_NAME-debug"
    paths:
      - build/*.rpm
  only:
    - /^develop-.*$/i
    - /^release-.*$/i

develop_build_release_for_centos8:
  extends: .build_by_travis_for_centos8
  variables:
    TESTING_VERSION_BUILD: 1
    #UPLOAD_SYMBOL_FILES: 1
    # ASAN_OPTION: ADDRESS
    BUILD_TYPE: RelWithDebInfo
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-testing-x86_64.el8
    PULP3_DIST_NAME: tfe-testing-x86_64.el8
  artifacts:
    name: "tfe-develop-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - /^develop-.*$/i
    - /^release-.*$/i

release_build_debug_for_centos8:
  variables:
    #UPLOAD_SYMBOL_FILES: 1
    BUILD_TYPE: Debug
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-stable-x86_64.el8
    PULP3_DIST_NAME: tfe-stable-x86_64.el8
  extends: .build_by_travis_for_centos8
  artifacts:
    name: "tfe-install-$CI_COMMIT_REF_NAME-debug"
    paths:
      - build/*.rpm
  only:
    - tags

release_build_release_for_centos8:
  variables:
    BUILD_TYPE: RelWithDebInfo
    #UPLOAD_SYMBOL_FILES: 1
    PACKAGE: 1
    PULP3_REPO_NAME: tfe-stable-x86_64.el8
    PULP3_DIST_NAME: tfe-stable-x86_64.el8
  extends: .build_by_travis_for_centos8
  artifacts:
    name: "tfe-install-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*.rpm
  only:
    - tags

###############################################################################
# envelope and upload
###############################################################################

envelope_rpm:
  stage: envelope
  image: $BUILD_IMAGE_CENTOS7
  variables:
    FEATURE_ID: 100
    APP_NAME_IN_RPM_SPEC: tfe
  script:
    - chmod +x ./ci/envelope_rpm.sh
    - ./ci/envelope_rpm.sh
  artifacts:
    name: "tfe-pr-$CI_COMMIT_REF_NAME-release"
    paths:
      - build/*-pr-*.rpm
  tags:
    - envelope
  only:
    - tags
 
upload_enveloped_rpm:
  stage: upload
  image: $BUILD_IMAGE_CENTOS7
  variables:
    PULP3_REPO_NAME_EL7: tfe-stable-x86_64.el7
    PULP3_DIST_NAME_EL7: tfe-stable-x86_64.el7
    PULP3_REPO_NAME_EL8: tfe-stable-x86_64.el8
    PULP3_DIST_NAME_EL8: tfe-stable-x86_64.el8
  script:
    - chmod +x ./ci/upload_enveloped_rpm.sh
    - ./ci/upload_enveloped_rpm.sh
  tags:
    - share
  only:
    - tags