action.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. name: Run tests (ya make)
  2. description: Run tests using ya make
  3. inputs:
  4. build_target:
  5. required: false
  6. description: "build target"
  7. build_preset:
  8. required: true
  9. default: "relwithdebinfo"
  10. description: "relwithdebinfo, release-asan, release-tsan"
  11. test_size:
  12. required: false
  13. default: "small,medium,large"
  14. description: "small or small-medium or all"
  15. test_type:
  16. required: false
  17. default: "unittest,py3test,py2test,pytest"
  18. description: "run "
  19. test_threads:
  20. required: false
  21. default: "28"
  22. description: "Test threads count"
  23. link_threads:
  24. required: false
  25. default: "8"
  26. description: "link threads count"
  27. testman_token:
  28. required: false
  29. description: "test manager auth token"
  30. testman_url:
  31. required: false
  32. description: "test manager endpoint"
  33. testman_project_id:
  34. required: false
  35. description: "test manager project id"
  36. bazel_remote_uri:
  37. required: false
  38. description: "bazel-remote endpoint"
  39. cache_tests:
  40. required: false
  41. description: "Use cache for tests"
  42. runs:
  43. using: "composite"
  44. steps:
  45. - name: Init
  46. id: init
  47. shell: bash
  48. run: |
  49. echo "SHELLOPTS=xtrace" >> $GITHUB_ENV
  50. export TMP_DIR=$(pwd)/tmp
  51. echo "TMP_DIR=$TMP_DIR" >> $GITHUB_ENV
  52. echo "LOG_DIR=$TMP_DIR/logs" >> $GITHUB_ENV
  53. echo "OUT_DIR=$TMP_DIR/out" >> $GITHUB_ENV
  54. echo "ARTIFACTS_DIR=$TMP_DIR/artifacts" >> $GITHUB_ENV
  55. echo "JUNIT_REPORT_XML=$TMP_DIR/junit.xml" >> $GITHUB_ENV
  56. echo "TESTMO_TOKEN=${{ inputs.testman_token }}" >> $GITHUB_ENV
  57. echo "TESTMO_URL=${{ inputs.testman_url }}" >> $GITHUB_ENV
  58. echo "SUMMARY_LINKS=$(mktemp)" >> $GITHUB_ENV
  59. - name: prepare
  60. shell: bash
  61. run: |
  62. rm -rf $TMP_DIR $JUNIT_REPORT_XML
  63. mkdir -p $TMP_DIR $OUT_DIR $ARTIFACTS_DIR $LOG_DIR
  64. - name: Install Node required for Testmo CLI
  65. uses: actions/setup-node@v3
  66. with:
  67. node-version: 19
  68. - name: Install Testmo CLI
  69. shell: bash
  70. run: npm install -g @testmo/testmo-cli
  71. - name: Test history run create
  72. id: th
  73. if: inputs.testman_token
  74. shell: bash
  75. env:
  76. PR_NUMBER: ${{ github.event.number }}
  77. run: |
  78. RUN_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
  79. BRANCH_TAG="$GITHUB_REF_NAME"
  80. ARCH="${{ runner.arch == 'X64' && 'x86-64' || runner.arch == 'ARM64' && 'arm64' || 'unknown' }}"
  81. case "${{ inputs.build_preset }}" in
  82. relwithdebinfo)
  83. TESTMO_SOURCE="ya-${ARCH}"
  84. ;;
  85. release-asan)
  86. TESTMO_SOURCE="ya-${ARCH}-asan"
  87. ;;
  88. release-tsan)
  89. TESTMO_SOURCE="ya-${ARCH}-tsan"
  90. ;;
  91. *)
  92. echo "Invalid preset: ${{ inputs.build_preset }}"
  93. exit 1
  94. ;;
  95. esac
  96. case $GITHUB_EVENT_NAME in
  97. workflow_dispatch)
  98. TESTMO_RUN_NAME="${{ github.run_id }} manual"
  99. EXTRA_TAG="manual"
  100. ;;
  101. pull_request | pull_request_target)
  102. TESTMO_RUN_NAME="${{ github.run_id }} PR #${PR_NUMBER}"
  103. EXTRA_TAG="pr"
  104. BRANCH_TAG=""
  105. ;;
  106. schedule)
  107. TESTMO_RUN_NAME="${{ github.run_id }} schedule"
  108. EXTRA_TAG="schedule"
  109. ;;
  110. *)
  111. TESTMO_RUN_NAME="${{ github.run_id }}"
  112. EXTRA_TAG=""
  113. ;;
  114. esac
  115. testmo automation:resources:add-link --name build --url "$RUN_URL" --resources testmo.json
  116. testmo automation:resources:add-field --name git-sha --type string --value "${GITHUB_SHA:0:7}" --resources testmo.json
  117. RUN_ID=$(
  118. testmo automation:run:create --instance "$TESTMO_URL" --project-id ${{ inputs.testman_project_id }} \
  119. --name "$TESTMO_RUN_NAME" --source "$TESTMO_SOURCE" --resources testmo.json \
  120. --tags "$BRANCH_TAG" --tags "$EXTRA_TAG"
  121. )
  122. echo "runid=${RUN_ID}" >> $GITHUB_OUTPUT
  123. echo "TEST_HISTORY_URL=${TESTMO_URL}/automation/runs/view/${RUN_ID}" >> $GITHUB_ENV
  124. - name: Print test history link
  125. shell: bash
  126. run: |
  127. echo "10 [Test history](${TEST_HISTORY_URL})" >> $SUMMARY_LINKS
  128. - name: set environment variables required by some tests
  129. shell: bash
  130. run: |
  131. echo "PSQL_BINARY=/usr/bin/psql" >> $GITHUB_ENV
  132. - name: ya test
  133. shell: bash
  134. run: |
  135. extra_params=()
  136. # FIXME: copy-paste from build_ya
  137. case "${{ inputs.build_preset }}" in
  138. relwithdebinfo)
  139. build_type=relwithdebinfo
  140. ;;
  141. release-asan)
  142. build_type=release
  143. extra_params+=(--sanitize="address")
  144. extra_params+=(-DSKIP_JUNK -DUSE_EAT_MY_DATA -DDEBUGINFO_LINES_ONLY)
  145. ;;
  146. release-tsan)
  147. build_type=release
  148. extra_params+=(--sanitize="thread")
  149. extra_params+=(-DSKIP_JUNK -DUSE_EAT_MY_DATA -DDEBUGINFO_LINES_ONLY)
  150. ;;
  151. *)
  152. echo "Invalid preset: ${{ inputs.build_preset }}"
  153. exit 1
  154. ;;
  155. esac
  156. if [ ! -z "${{ inputs.build_target }}" ]; then
  157. extra_params+=(--target="${{ inputs.build_target }}")
  158. fi
  159. if [ ! -z "${{ inputs.bazel_remote_uri }}" ]; then
  160. extra_params+=(--bazel-remote-store)
  161. extra_params+=(--bazel-remote-base-uri "${{ inputs.bazel_remote_uri }}")
  162. fi
  163. if [ "${{ inputs.cache_tests }}" = "true" ]; then
  164. extra_params+=(--cache-tests)
  165. fi
  166. readarray -d ',' -t test_size < <(printf "%s" "${{ inputs.test_size }}")
  167. readarray -d ',' -t test_type < <(printf "%s" "${{ inputs.test_type }}")
  168. ./ya test -k --build "${build_type}" -D'BUILD_LANGUAGES=CPP PY3 PY2' \
  169. ${test_size[@]/#/--test-size=} ${test_type[@]/#/--test-type=} \
  170. --test-threads "${{ inputs.test_threads }}" --link-threads "${{ inputs.link_threads }}" \
  171. --cache-size 512G --do-not-output-stderrs -T \
  172. --stat --log-file "$LOG_DIR/ya_log.txt" --evlog-file "$LOG_DIR/ya_evlog.jsonl" \
  173. --canonization-backend=ydb-canondata.storage.yandexcloud.net \
  174. --junit "$JUNIT_REPORT_XML" --output "$OUT_DIR" "${extra_params[@]}" || (
  175. RC=$?
  176. if [[ $RC -ge 10 && $RC -le 14 ]]; then
  177. echo "ya test returned failed tests status, recovering.."
  178. else
  179. exit $RC
  180. fi
  181. )
  182. - name: postprocess junit report
  183. shell: bash
  184. run: |
  185. .github/scripts/tests/transform-ya-junit.py -i \
  186. --mu .github/config/muted_test.txt \
  187. --mf .github/config/muted_functest.txt \
  188. --ya-out "$OUT_DIR" \
  189. --log-url-prefix "$S3_URL_PREFIX/logs/" \
  190. --log-out-dir "$ARTIFACTS_DIR/logs/" \
  191. "$JUNIT_REPORT_XML"
  192. - name: write tests summary
  193. shell: bash
  194. env:
  195. GITHUB_TOKEN: ${{ github.token }}
  196. run: |
  197. mkdir $ARTIFACTS_DIR/summary/
  198. cat $SUMMARY_LINKS | python3 -c 'import sys; print(" | ".join([v for _, v in sorted([l.strip().split(" ", 1) for l in sys.stdin], key=lambda a: (int(a[0]), a))]))' >> $GITHUB_STEP_SUMMARY
  199. platform_name=$(uname | tr '[:upper:]' '[:lower:]')-$(arch)
  200. .github/scripts/tests/generate-summary.py \
  201. --summary-out-path $ARTIFACTS_DIR/summary/ \
  202. --summary-url-prefix $S3_URL_PREFIX/summary/ \
  203. --test-history-url $TEST_HISTORY_URL \
  204. --build-preset "${platform_name}-${{ inputs.build_preset }}" \
  205. "Tests" ya-test.html "$JUNIT_REPORT_XML"
  206. - name: Unit test history upload results
  207. if: inputs.testman_token
  208. shell: bash
  209. run: |
  210. testmo automation:run:submit-thread \
  211. --instance "$TESTMO_URL" --run-id ${{ steps.th.outputs.runid }} \
  212. --results "$JUNIT_REPORT_XML"
  213. - name: sync test results to s3
  214. if: always()
  215. shell: bash
  216. run: |
  217. echo "::group::s3-sync"
  218. s3cmd sync --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$ARTIFACTS_DIR/" "$S3_BUCKET_PATH/"
  219. echo "::endgroup::"
  220. - name: sync logs results to s3
  221. if: always()
  222. shell: bash
  223. run: |
  224. echo "::group::s3-sync"
  225. s3cmd sync --follow-symlinks --acl-private --no-progress --stats --no-check-md5 "$LOG_DIR/" "$S3_BUCKET_PATH/test_logs/"
  226. echo "::endgroup::"
  227. - name: Test history run complete
  228. if: always() && inputs.testman_token
  229. shell: bash
  230. run: |
  231. testmo automation:run:complete --instance "$TESTMO_URL" --run-id ${{ steps.th.outputs.runid }}
  232. - name: check test results
  233. shell: bash
  234. run: |
  235. .github/scripts/tests/fail-checker.py "$JUNIT_REPORT_XML"
  236. - name: show free space
  237. if: always()
  238. shell: bash
  239. run: df -h