<commit_before>stages:
  - build
  - unit_test
  - test
  - test_report
  - deploy

before_script:
  # add gitlab ssh key
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - echo -n $GITLAB_KEY > ~/.ssh/id_rsa_base64
  - base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
  - chmod 600 ~/.ssh/id_rsa
  - echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

  # if testing master branch, use github wifi libs.
  # if testing other branches, use gitlab wifi libs (as maybe changes aren't merged to master yet)
  - test "${CI_BUILD_REF_NAME}" = "master" || sed -i "s%https://github.com/espressif/esp32-wifi-lib%ssh://git@gitlab.espressif.cn:27227/idf/esp32-wifi-lib%" .gitmodules
  # fetch all submodules
  - git submodule update --init --recursive

build_template_app:
  stage: build
  image: espressif/esp32-ci-env
  tags:
    - build

  variables:
    SDK_PATH: "$CI_PROJECT_DIR"
    IDF_PATH: "$CI_PROJECT_DIR"
    GIT_STRATEGY: clone

  script:
    - git clone https://github.com/espressif/esp-idf-template.git
    - cd esp-idf-template
    # Try to use the same branch name for esp-idf-template that we're
    # using on esp-idf. If it doesn't exist then just stick to the default
    # branch
    - git checkout ${CI_BUILD_REF_NAME} || echo "Using esp-idf-template default branch..."
    - make defconfig
    # Test debug build (default)
    - make all V=1
    # Now test release build
    - make clean
    - sed -i.bak -e's/CONFIG_OPTIMIZATION_LEVEL_DEBUG\=y/CONFIG_OPTIMIZATION_LEVEL_RELEASE=y/' sdkconfig
    - make defconfig
    - make all V=1
    # Check if there are any stray printf/ets_printf references in WiFi libs
    - cd ../components/esp32/lib
    - test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0
    - test $(xtensa-esp32-elf-nm *.a | grep -w ets_printf | wc -l) -eq 0


.build_gitlab: &build_template
  stage: build
  tags:
    - build
  image: espressif/esp32-ci-env

  variables:
    SDK_PATH: "$CI_PROJECT_DIR"
    IDF_PATH: "$CI_PROJECT_DIR"
    GIT_STRATEGY: clone

build_ssc:
  <<: *build_template
  artifacts:
    paths:
      - ./SSC/ssc_bin
    expire_in: 6 mos

  script:
    - git clone $GITLAB_SSH_SERVER/yinling/SSC.git
    - cd SSC
    - git checkout ${CI_BUILD_REF_NAME} || echo "Using SSC default branch..."
    - make defconfig
    - chmod +x gen_misc_ng.sh
    - ./gen_misc_ng.sh

build_esp_idf_tests:
  <<: *build_template
  artifacts:
    paths:
      - ./tools/unit-test-app/build/*.bin
      - ./tools/unit-test-app/build/*.elf
      - ./tools/unit-test-app/build/*.map
      - ./tools/unit-test-app/build/bootloader/*.bin
    expire_in: 6 mos

  script:
    - cd tools/unit-test-app
    - git checkout ${CI_BUILD_REF_NAME} || echo "Using default branch..."
    - make defconfig
    - make TESTS_ALL=1

build_examples:
  <<: *build_template
  artifacts:
    paths:
      - build_examples/*/*/build/*.bin
      - build_examples/*/*/build/*.elf
      - build_examples/*/*/build/*.map
      - build_examples/*/*/build/bootloader/*.bin
    expire_in: 6 mos

  script:
    # it's not possible to build 100% out-of-tree and have the "artifacts"
    # mechanism work, but this is the next best thing
    - mkdir build_examples
    - cd build_examples
    - ${IDF_PATH}/make/build_examples.sh

build_docs:
  stage: build
  image: espressif/esp32-ci-env
  tags:
    - build_docs
  script:
    - cd docs
    - doxygen
    # If not building master branch, and there are Doxygen warnings, print them and bail out
    - test "${CI_BUILD_REF_NAME}" = "master" || test $(cat doxygen-warning-log.txt | wc -l) -eq 0 || ( echo "Doxygen pass had some warnings:" && cat doxygen-warning-log.txt && false )
    - make html
  artifacts:
    paths:
      - docs/_build/html
    expire_in: 1 mos


test_nvs_on_host:
  stage: test
  image: espressif/esp32-ci-env
  tags:
    - nvs_host_test
  script:
    - cd components/nvs_flash/test_nvs_host
    - make test

test_build_system:
  stage: test
  image: espressif/esp32-ci-env
  tags:
    - build_test
  variables:
    IDF_PATH: "$CI_PROJECT_DIR"
  script:
    - ./make/test_build_system.sh

test_report:
  stage: test_report
  only:
    - master
    - triggers
  tags:
    - test_report
  variables:
    LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
    TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test"
    REPORT_PATH: "$CI_PROJECT_DIR/CI_Test_Report"
  artifacts:
    when: always
    paths:
      - $REPORT_PATH
      - $LOG_PATH
    expire_in: 12 mos
  script:
    # clone test bench
    - git clone $GITLAB_SSH_SERVER/yinling/auto_test_script.git
    - cd auto_test_script
    # generate report
    - python CITestReport.py -l $LOG_PATH -t $TEST_CASE_FILE_PATH -p $REPORT_PATH


push_master_to_github:
  before_script:
    - echo "Not setting up GitLab key, not fetching submodules"
  stage: deploy
  only:
    - master
  tags:
    - deploy
  when: on_success
  image: espressif/esp32-ci-env
  variables:
    GIT_STRATEGY: clone<commit_msg>generate test result and commit to CI-test-result:<commit_after>stages:
  - build
  - unit_test
  - test
  - test_report
  - deploy

before_script:
  # add gitlab ssh key
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - echo -n $GITLAB_KEY > ~/.ssh/id_rsa_base64
  - base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
  - chmod 600 ~/.ssh/id_rsa
  - echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

  # if testing master branch, use github wifi libs.
  # if testing other branches, use gitlab wifi libs (as maybe changes aren't merged to master yet)
  - test "${CI_BUILD_REF_NAME}" = "master" || sed -i "s%https://github.com/espressif/esp32-wifi-lib%ssh://git@gitlab.espressif.cn:27227/idf/esp32-wifi-lib%" .gitmodules
  # fetch all submodules
  - git submodule update --init --recursive

build_template_app:
  stage: build
  image: espressif/esp32-ci-env
  tags:
    - build

  variables:
    SDK_PATH: "$CI_PROJECT_DIR"
    IDF_PATH: "$CI_PROJECT_DIR"
    GIT_STRATEGY: clone

  script:
    - git clone https://github.com/espressif/esp-idf-template.git
    - cd esp-idf-template
    # Try to use the same branch name for esp-idf-template that we're
    # using on esp-idf. If it doesn't exist then just stick to the default
    # branch
    - git checkout ${CI_BUILD_REF_NAME} || echo "Using esp-idf-template default branch..."
    - make defconfig
    # Test debug build (default)
    - make all V=1
    # Now test release build
    - make clean
    - sed -i.bak -e's/CONFIG_OPTIMIZATION_LEVEL_DEBUG\=y/CONFIG_OPTIMIZATION_LEVEL_RELEASE=y/' sdkconfig
    - make defconfig
    - make all V=1
    # Check if there are any stray printf/ets_printf references in WiFi libs
    - cd ../components/esp32/lib
    - test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0
    - test $(xtensa-esp32-elf-nm *.a | grep -w ets_printf | wc -l) -eq 0


.build_gitlab: &build_template
  stage: build
  tags:
    - build
  image: espressif/esp32-ci-env

  variables:
    SDK_PATH: "$CI_PROJECT_DIR"
    IDF_PATH: "$CI_PROJECT_DIR"
    GIT_STRATEGY: clone

build_ssc:
  <<: *build_template
  artifacts:
    paths:
      - ./SSC/ssc_bin
    expire_in: 6 mos

  script:
    - git clone $GITLAB_SSH_SERVER/yinling/SSC.git
    - cd SSC
    - git checkout ${CI_BUILD_REF_NAME} || echo "Using SSC default branch..."
    - make defconfig
    - chmod +x gen_misc_ng.sh
    - ./gen_misc_ng.sh

build_esp_idf_tests:
  <<: *build_template
  artifacts:
    paths:
      - ./tools/unit-test-app/build/*.bin
      - ./tools/unit-test-app/build/*.elf
      - ./tools/unit-test-app/build/*.map
      - ./tools/unit-test-app/build/bootloader/*.bin
    expire_in: 6 mos

  script:
    - cd tools/unit-test-app
    - git checkout ${CI_BUILD_REF_NAME} || echo "Using default branch..."
    - make defconfig
    - make TESTS_ALL=1

build_examples:
  <<: *build_template
  artifacts:
    paths:
      - build_examples/*/*/build/*.bin
      - build_examples/*/*/build/*.elf
      - build_examples/*/*/build/*.map
      - build_examples/*/*/build/bootloader/*.bin
    expire_in: 6 mos

  script:
    # it's not possible to build 100% out-of-tree and have the "artifacts"
    # mechanism work, but this is the next best thing
    - mkdir build_examples
    - cd build_examples
    - ${IDF_PATH}/make/build_examples.sh

build_docs:
  stage: build
  image: espressif/esp32-ci-env
  tags:
    - build_docs
  script:
    - cd docs
    - doxygen
    # If not building master branch, and there are Doxygen warnings, print them and bail out
    - test "${CI_BUILD_REF_NAME}" = "master" || test $(cat doxygen-warning-log.txt | wc -l) -eq 0 || ( echo "Doxygen pass had some warnings:" && cat doxygen-warning-log.txt && false )
    - make html
  artifacts:
    paths:
      - docs/_build/html
    expire_in: 1 mos


test_nvs_on_host:
  stage: test
  image: espressif/esp32-ci-env
  tags:
    - nvs_host_test
  script:
    - cd components/nvs_flash/test_nvs_host
    - make test

test_build_system:
  stage: test
  image: espressif/esp32-ci-env
  tags:
    - build_test
  variables:
    IDF_PATH: "$CI_PROJECT_DIR"
  script:
    - ./make/test_build_system.sh

test_report:
  stage: test_report
  image: espressif/esp32-ci-env
  only:
    - master
    - triggers
  tags:
    - report
  variables:
    LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
    TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test"
    REPORT_PATH: "$CI_PROJECT_DIR/CI_Test_Report"
  artifacts:
    when: always
    paths:
      - $REPORT_PATH
      - $LOG_PATH
    expire_in: 12 mos
  script:
    # calc log path
    - VER_NUM=`git rev-list HEAD | wc -l | awk '{print $1}'`
    - SHA_ID=`echo $CI_BUILD_REF | cut -c 1-7`
    - REVISION="${VER_NUM}_${SHA_ID}"
    # replace / to _ in branch name
    - ESCAPED_BRANCH_NAME=`echo $CI_BUILD_REF_NAME | sed 's/\//___/g'`
    # result path and artifacts path
    - RESULT_PATH="$CI_PROJECT_NAME/$ESCAPED_BRANCH_NAME/$REVISION"
    - ARTIFACTS_PATH="$GITLAB_HTTP_SERVER/idf/esp-idf/builds/$CI_BUILD_ID/artifacts/browse/$CI_BUILD_REF"
    # clone test bench
    - git clone $GITLAB_SSH_SERVER/yinling/auto_test_script.git
    - cd auto_test_script
    # generate report
    - python CITestReport.py -l $LOG_PATH -t $TEST_CASE_FILE_PATH -p $REPORT_PATH -r $RESULT_PATH -a $ARTIFACTS_PATH || FAIL=True
    # commit to CI-test-result project
    - git clone $GITLAB_SSH_SERVER/qa/CI-test-result.git
    - rm -rf CI-test-result/RawData/$RESULT_PATH
    - cp -R $CI_PROJECT_NAME CI-test-result/RawData
    - cd CI-test-result
    # config git user
    - git config --global user.email "<EMAIL>"
    - git config --global user.name "ci-test-result"
    # commit test result
    - git add .
    - git commit . -m "update test result for $CI_PROJECT_NAME/$CI_BUILD_REF_NAME/$CI_BUILD_REF, pipeline ID $CI_PIPELINE_ID" || exit 0
    - git push origin master
    - test "${FAIL}" = "True" && exit 1

push_master_to_github:
  before_script:
    - echo "Not setting up GitLab key, not fetching submodules"
  stage: deploy
  only:
    - master
  tags:
    - deploy
  when: on_success
  image: espressif/esp32-ci-env
  variables:
    GIT_STRATEGY: clone
{'fraction_non_alphanumeric': 0.11691810344827586, 'fraction_numerical': 0.010326867816091954, 'mean_word_length': 2.665898617511521, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 12, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5235592', 'n_tokens_mistral': 4309, 'n_tokens_neox': 4087, 'n_words': 967}