stages: - build - target_test - deploy variables: # System environment ESP_DOCS_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.3:1-1" ESP_DOCS_PATH: "$CI_PROJECT_DIR" TEST_DIR: "$CI_PROJECT_DIR" # GitLab-CI environment GET_SOURCES_ATTEMPTS: "10" ARTIFACT_DOWNLOAD_ATTEMPTS: "10" GIT_SUBMODULE_STRATEGY: none # Define a matrix for IDF versions and their corresponding targets .options_list: # versions: # IDF_VER: ["latest", "v5.3", "v5.2", "v5.0"] markers: TEST_MARKER: - "tcp" - "serial" - "generic" # - "tcp_p4" # - "serial_p4" .setup_idf_tools: &setup_idf_tools | tools/idf_tools.py --non-interactive install && eval "$(tools/idf_tools.py --non-interactive export)" || exit 1 .add_gh_key_remote: &add_gh_key_remote | command -v ssh-agent >/dev/null || exit 1 eval $(ssh-agent -s) printf '%s\n' "${GH_PUSH_KEY}" | tr -d '\r' | ssh-add - > /dev/null mkdir -p ~/.ssh && chmod 700 ~/.ssh [[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config || ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts git remote remove github || true git remote add github ${GH_PUSH_REPO} after_script: # Just for cleaning space, no other causes - git clean -ffdx .build_template: stage: build tags: - build variables: SIZE_INFO_LOCATION: "${TEST_DIR}/size_info.txt" IDF_CCACHE_ENABLE: "1" after_script: # Show ccache statistics if enabled globally - test "$CI_CCACHE_STATS" == 1 && test -n "$(which ccache)" && ccache --show-stats || true dependencies: [] .before_script_build_jobs: before_script: - pip install idf-component-manager --upgrade - pip install "idf_build_apps~=1.0.1" .check_idf_ver: &check_idf_ver | export IDF_PATH=$(find /opt -type d -name "*idf*" \ \( -exec test -f '{}/tools/idf.py' \; -and -exec test -f '{}/tools/idf_tools.py' \; \ \) -print -quit) if [ -z "${IDF_PATH}" ];then echo "IDF version is not found." else cd ${IDF_PATH} export IDF_DESCRIBE=$(git describe) export IDF_VERSION=${IDF_DESCRIBE%-*} echo "$IDF_VERSION" >> $TEST_DIR/idf_version_info.txt echo "ESP-IDF: $IDF_VERSION" fi # Note: this script builds the folder against all targets and then deletes # all other artifacts except the esp32 to decrease the size of artifacs (may cause failures) .build_cur_folder: &build_cur_folder | echo "Build job ${CI_JOB_NAME}, folder: ${PWD##*/}, targets: ${TEST_TARGETS}" python -m idf_build_apps build -v -p . \ --recursive \ --target all \ --default-build-targets ${TEST_TARGETS} \ --config "sdkconfig.ci.*=" --build-dir "build_@t_@w" \ --check-warnings \ --ignore-warning-file ../tools/ignore_build_warnings.txt \ --collect-size-info $SIZE_INFO_LOCATION \ --manifest-rootpath . \ --manifest-file .build-test-rules.yml \ --parallel-count ${CI_NODE_TOTAL:-1} \ --parallel-index ${CI_NODE_INDEX:-1} echo "delete build folders:" $(find . -type d -regex '^\./.*build_esp32[a-z]+[0-9]+[_a-z]*' -print -exec rm -rf {} +) ls -lh > test_dir_${PWD##*/}.txt # This template gets expanded multiple times, once for every IDF version. # IDF version is specified by setting the espressif/idf image tag. # # TEST_TARGETS sets the list of IDF_TARGET values to build the test for. # It should contain only the targets with optimized assembly implementations. # .build_pytest_template: stage: build extends: - .build_template - .before_script_build_jobs script: # The script below will build all test applications defined in environment variable $TEST_TARGETS - *check_idf_ver # This is workaround to build library under esp-idf v4.4 - pip install idf-component-manager --upgrade - cd ${TEST_DIR}/test_apps - *build_cur_folder - cd ${TEST_DIR}/examples - export TEST_TARGETS="esp32" # override to build only on esp32 target to decrease build time - *build_cur_folder variables: TEST_TARGETS: "esp32" artifacts: name: artifacts_${CI_JOB_NAME} paths: - "**/build*/size.json" - "**/build*/build.log" - "**/build*/build_log.txt" - "**/build*/*.bin" - "**/build*/*.elf" - "**/build*/*.map" - "**/build*/flasher_args.json" - "**/build*/flash_project_args" - "**/build*/config/sdkconfig.json" - "**/build*/bootloader/*.bin" - "**/build*/partition_table/*.bin" - "**/idf_version_info.txt" - "**/test_dir*.txt" - $SIZE_INFO_LOCATION when: always expire_in: 3 weeks build_idf_latest: extends: .build_pytest_template image: espressif/idf:latest variables: TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c5 esp32c6 esp32h2" build_idf_v5.3: extends: .build_pytest_template image: espressif/idf:release-v5.3 variables: TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2" build_idf_v5.2: extends: .build_pytest_template image: espressif/idf:release-v5.2 variables: TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3" build_idf_v5.0: extends: .build_pytest_template image: espressif/idf:release-v5.0 variables: TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3" .target_test_template: stage: target_test timeout: 1 hour variables: GIT_DEPTH: 1 SUBMODULES_TO_FETCH: "none" cache: # Usually do not need submodule-cache in target_test - key: pip-cache paths: - .cache/pip policy: pull .before_script_pytest_jobs: before_script: # Install or upgrade pytest-embedded to perform test cases - pip install -r ${TEST_DIR}/tools/test_requirements.txt # Upgrade the packages (workaround for esp-idf v5.0) - pip install --only-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf --upgrade .test_cur_folder: &test_cur_folder | export IDF_VER=$(cat ${TEST_DIR}/idf_version_info.txt) echo "Start test job: ${CI_JOB_NAME}, version: ${IDF_VER%-*}, folder: ${PWD##*/}" python -m pytest --junit-xml=${TEST_DIR}/${PWD##*/}/results_${IDF_VER%-*}_${PWD##*/}.xml --target=${IDF_TARGET} -m multi_dut_modbus_${TEST_MARKER} ls -lh > test_dir_${PWD##*/}.txt .test_template: image: "$CI_DOCKER_REGISTRY/target-test-env-v5.3:1" stage: target_test extends: - .before_script_pytest_jobs tags: - multi_dut_modbus_${TEST_MARKER} variables: IDF_TARGET: "esp32" # the only esp32 runners are available for now script: - cd ${TEST_DIR}/test_apps/ - *test_cur_folder - cd ${TEST_DIR}/examples/ - *test_cur_folder artifacts: name: artifacts_${CI_JOB_NAME} paths: - "${TEST_DIR}/**/*.log" - "${TEST_DIR}/**/*.xml" - "${TEST_DIR}/**/results_*.xml" - "${TEST_DIR}/**/pytest_embedded_log/" - "${TEST_DIR}/**/test_dir*.txt" - "${TEST_DIR}/**/idf_version_info.txt" - "${TEST_DIR}/**/log.html" - "${TEST_DIR}/**/report.html" - "${TEST_DIR}/**/*.pcap" reports: junit: ${TEST_DIR}/results_${IDF_VER%-*}.xml when: always expire_in: 1 week target_test_latest: stage: target_test image: "$CI_DOCKER_REGISTRY/target-test-env-v5.4:1" extends: .test_template parallel: matrix: - !reference [.options_list, markers] needs: job: build_idf_latest artifacts: true after_script: [] target_test_v5.3: stage: target_test image: "$CI_DOCKER_REGISTRY/target-test-env-v5.3:1" extends: .test_template parallel: matrix: - !reference [.options_list, markers] needs: job: build_idf_v5.3 artifacts: true after_script: [] target_test_v5.2: stage: target_test image: "$CI_DOCKER_REGISTRY/target-test-env-v5.2:2" extends: .test_template parallel: matrix: - !reference [.options_list, markers] needs: job: build_idf_v5.2 artifacts: true after_script: [] target_test_v5.0: stage: target_test image: "$CI_DOCKER_REGISTRY/target-test-env-v5.0:3" extends: .test_template parallel: matrix: - !reference [.options_list, markers] needs: job: build_idf_v5.0 artifacts: true after_script: [] build_docs: stage: build image: $ESP_DOCS_ENV_IMAGE tags: - build_docs artifacts: when: always paths: - docs/_build/*/*/*.txt - docs/_build/*/*/html/* expire_in: 4 days # No cleaning when the artifacts after_script: [] script: - cd docs - pip install -r requirements.txt - ./generate_docs .deploy_docs_template: stage: deploy image: $ESP_DOCS_ENV_IMAGE tags: - deploy_docs needs: - build_docs only: changes: - "docs/**/*" script: - source ${CI_PROJECT_DIR}/docs/utils.sh - add_doc_server_ssh_keys $DOCS_DEPLOY_PRIVATEKEY $DOCS_DEPLOY_SERVER $DOCS_DEPLOY_SERVER_USER - export GIT_VER=$(git describe --always) - export GIT_TAGS=$(git fetch --tags; git tag -l;) - echo "Deploy ${PWD##*/}, ${DOCS_BUILD_DIR}, Ref name; ${CI_COMMIT_REF_NAME}" - echo "Version; ${GIT_VER}, tags; ${GIT_TAGS}" - pip install -r ${CI_PROJECT_DIR}/docs/requirements.txt - deploy-docs deploy_docs_preview: extends: - .deploy_docs_template except: refs: - main variables: TYPE: "preview" DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/" DOCS_DEPLOY_PRIVATEKEY: "$DOCS_PREVIEW_PRIVATEKEY" DOCS_DEPLOY_SERVER: "$DOCS_PREVIEW_SERVER" DOCS_DEPLOY_SERVER_USER: "$DOCS_PREVIEW_SERVER_USER" DOCS_DEPLOY_PATH: "$DOCS_PREVIEW_PATH" DOCS_DEPLOY_URL_BASE: "$DOCS_PREVIEW_URL_BASE" deploy_docs_production: extends: - .deploy_docs_template only: refs: - main variables: TYPE: "production" DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/" DOCS_DEPLOY_PRIVATEKEY: "$DOCS_PROD_DEPLOY_KEY" DOCS_DEPLOY_SERVER: "$DOCS_PROD_SERVER" DOCS_DEPLOY_SERVER_USER: "$DOCS_PROD_SERVER_USER" DOCS_DEPLOY_PATH: "$DOCS_PROD_PATH" DOCS_DEPLOY_URL_BASE: "https://docs.espressif.com/projects/esp-modbus" upload_to_component_manager: stage: deploy image: python:3.10-alpine tags: - deploy rules: - if: '$CI_COMMIT_BRANCH == "main"' # the main branch is a component release branch for v2 - if: '$FORCE_PUSH_COMPONENT == "1"' when: manual allow_failure: true script: - pip install idf-component-manager - export IDF_COMPONENT_API_TOKEN=${ESP_MODBUS_API_KEY} - export COMP_VERSION=$(grep 'version:' idf_component.yml | head -n 1 | awk '{print $2}' | tr -d '"') - compote component upload --namespace=espressif --name=esp-modbus --allow-existing --version=${COMP_VERSION}