action.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. name: Run tests (ya make)
  2. description: Run test targets listed in repository root ya.make (to be created previously)
  3. inputs:
  4. build_target:
  5. required: true
  6. build_preset:
  7. required: true
  8. default: "relwithdebinfo"
  9. description: "relwithdebinfo, release-asan, release-tsan"
  10. test_type:
  11. required: false
  12. type: string
  13. default: ""
  14. description: "run only specific test types (or all by default)"
  15. test_size:
  16. required: false
  17. default: "small,medium,large"
  18. description: "small or small-medium or all"
  19. test_threads:
  20. required: false
  21. default: "56"
  22. description: "Test threads count"
  23. link_threads:
  24. required: false
  25. default: "12"
  26. description: "link threads count"
  27. additional_ya_make_args:
  28. type: string
  29. default: ""
  30. testman_token:
  31. required: false
  32. description: "test manager auth token"
  33. testman_url:
  34. required: false
  35. description: "test manager endpoint"
  36. testman_project_id:
  37. required: false
  38. description: "test manager project id"
  39. runs:
  40. using: "composite"
  41. steps:
  42. - name: Init
  43. id: init
  44. shell: bash
  45. run: |
  46. export TMP_DIR=$(pwd)/tmp
  47. export LOG_DIR=$TMP_DIR/logs
  48. echo "TMP_DIR=$TMP_DIR" >> $GITHUB_ENV
  49. echo "LOG_DIR=$LOG_DIR" >> $GITHUB_ENV
  50. echo "OUT_DIR=$TMP_DIR/out" >> $GITHUB_ENV
  51. echo "ARTIFACTS_DIR=$TMP_DIR/artifacts" >> $GITHUB_ENV
  52. echo "TEST_ARTIFACTS_DIR=$TMP_DIR/test_artifacts" >> $GITHUB_ENV
  53. echo "REPORTS_ARTIFACTS_DIR=$TMP_DIR/artifacts/test_reports" >> $GITHUB_ENV
  54. echo "JUNIT_REPORT_XML=$TMP_DIR/junit.xml" >> $GITHUB_ENV
  55. echo "JUNIT_REPORT_PARTS=$TMP_DIR/junit-split" >> $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. echo "GITHUB_TOKEN=${{ github.token }}" >> $GITHUB_ENV
  60. echo "BUILD_PRESET=${{ inputs.build_preset }}" >> $GITHUB_ENV
  61. echo "YA_TEST_LOG_FILENAME=$LOG_DIR/ya_test.log" >> $GITHUB_ENV
  62. echo "YA_TEST_LOG_URL=$S3_URL_PREFIX/test_logs/ya_test.log" >> $GITHUB_ENV
  63. echo "S3_LOG_BUCKET_PATH=$S3_BUCKET_PATH/test_logs" >> $GITHUB_ENV
  64. - name: prepare
  65. shell: bash
  66. run: |
  67. set -x
  68. rm -rf $TMP_DIR $JUNIT_REPORT_XML $JUNIT_REPORT_PARTS $REPORTS_ARTIFACTS_DIR
  69. mkdir -p $TMP_DIR $OUT_DIR $ARTIFACTS_DIR $TEST_ARTIFACTS_DIR $LOG_DIR $JUNIT_REPORT_PARTS $REPORTS_ARTIFACTS_DIR
  70. - name: Install Node required for Testmo CLI
  71. uses: actions/setup-node@v3
  72. with:
  73. node-version: 19
  74. - name: Install Testmo CLI
  75. shell: bash
  76. run: npm install -g @testmo/testmo-cli
  77. - name: Upload tests result to testmo
  78. id: th
  79. if: inputs.testman_token
  80. shell: bash
  81. env:
  82. PR_NUMBER: ${{ github.event.number }}
  83. run: |
  84. set -x
  85. RUN_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
  86. BRANCH_TAG="$GITHUB_REF_NAME"
  87. ARCH="${{ runner.arch == 'X64' && 'x86-64' || runner.arch == 'ARM64' && 'arm64' || 'unknown' }}"
  88. case "$BUILD_PRESET" in
  89. relwithdebinfo)
  90. TESTMO_SOURCE="ya-${ARCH}"
  91. ;;
  92. debug)
  93. TESTMO_SOURCE="ya-${ARCH}-debug"
  94. ;;
  95. release-*)
  96. TESTMO_SOURCE="ya-${ARCH}-${BUILD_PRESET/release-/}"
  97. ;;
  98. *)
  99. echo "Invalid preset: $BUILD_PRESET"
  100. exit 1
  101. ;;
  102. esac
  103. case $GITHUB_EVENT_NAME in
  104. workflow_dispatch)
  105. TESTMO_RUN_NAME="${{ github.run_id }} manual"
  106. EXTRA_TAG="manual"
  107. ;;
  108. pull_request | pull_request_target)
  109. TESTMO_RUN_NAME="${{ github.run_id }} PR #${PR_NUMBER}"
  110. EXTRA_TAG="pr"
  111. BRANCH_TAG=""
  112. ;;
  113. schedule)
  114. TESTMO_RUN_NAME="${{ github.run_id }} schedule"
  115. EXTRA_TAG="schedule"
  116. ;;
  117. push)
  118. TESTMO_RUN_NAME="${{ github.run_id }} POST"
  119. EXTRA_TAG="post-commit"
  120. ;;
  121. *)
  122. TESTMO_RUN_NAME="${{ github.run_id }}"
  123. EXTRA_TAG=""
  124. ;;
  125. esac
  126. testmo automation:resources:add-link --name build --url "$RUN_URL" --resources testmo.json
  127. testmo automation:resources:add-field --name git-sha --type string --value "${GITHUB_SHA:0:7}" --resources testmo.json
  128. RUN_ID=$(
  129. testmo automation:run:create --instance "$TESTMO_URL" --project-id ${{ inputs.testman_project_id }} \
  130. --name "$TESTMO_RUN_NAME" --source "$TESTMO_SOURCE" --resources testmo.json \
  131. --tags "$BRANCH_TAG" --tags "$EXTRA_TAG"
  132. )
  133. echo "runid=${RUN_ID}" >> $GITHUB_OUTPUT
  134. echo "TEST_HISTORY_URL=${TESTMO_URL}/automation/runs/view/${RUN_ID}" >> $GITHUB_ENV
  135. - name: Print test history link
  136. shell: bash
  137. if: inputs.testman_token
  138. run: |
  139. echo "10 [Test history](${TEST_HISTORY_URL})" >> $SUMMARY_LINKS
  140. - name: set environment variables required by some tests
  141. shell: bash
  142. run: |
  143. echo "PSQL_BINARY=/usr/bin/psql" >> $GITHUB_ENV
  144. - name: ya test
  145. shell: bash
  146. run: |
  147. set -x
  148. readarray -d ',' -t test_size < <(printf "%s" "${{ inputs.test_size }}")
  149. readarray -d ',' -t test_type < <(printf "%s" "${{ inputs.test_type }}")
  150. params=(
  151. -T -k
  152. ${test_size[@]/#/--test-size=} ${test_type[@]/#/--test-type=}
  153. --cache-size 512G --do-not-output-stderrs
  154. --stat
  155. --test-threads "${{ inputs.test_threads }}" --link-threads "${{ inputs.link_threads }}"
  156. )
  157. # FIXME: copy-paste from build_ya
  158. case "$BUILD_PRESET" in
  159. debug)
  160. params+=(--build "debug")
  161. ;;
  162. relwithdebinfo)
  163. params+=(--build "relwithdebinfo")
  164. ;;
  165. release-asan)
  166. params+=(
  167. --build "release" --sanitize="address"
  168. -DSKIP_JUNK -DUSE_EAT_MY_DATA -DDEBUGINFO_LINES_ONLY
  169. )
  170. ;;
  171. release-tsan)
  172. params+=(
  173. --build "release" --sanitize="thread"
  174. -DSKIP_JUNK -DUSE_EAT_MY_DATA -DDEBUGINFO_LINES_ONLY
  175. )
  176. ;;
  177. release-msan)
  178. params+=(
  179. --build "release" --sanitize="memory"
  180. -DSKIP_JUNK -DUSE_EAT_MY_DATA -DDEBUGINFO_LINES_ONLY
  181. )
  182. ;;
  183. *)
  184. echo "Invalid preset: $BUILD_PRESET"
  185. exit 1
  186. ;;
  187. esac
  188. if [ ! -z "${{ inputs.additional_ya_make_args }}" ]; then
  189. params+=(${{ inputs.additional_ya_make_args }})
  190. fi
  191. # Also build targets which are not in tests' dependencies
  192. params+=(--no-strip-idle-build-results)
  193. echo "::debug::get version"
  194. ./ya --version
  195. echo "Tests are running..." | .github/scripts/tests/comment-pr.py
  196. ./ya test ${{ inputs.build_target }} "${params[@]}" \
  197. --stat --log-file "$YA_TEST_LOG_FILENAME" -DCONSISTENT_DEBUG \
  198. --no-dir-outputs \
  199. --junit "$JUNIT_REPORT_XML" --output "$OUT_DIR" || (
  200. RC=$?
  201. if [ $RC -ne 0 ]; then
  202. echo "10 [Test run log]($YA_TEST_LOG_URL)" >> $SUMMARY_LINKS
  203. echo "ya test returned $RC, check existence $JUNIT_REPORT_XML"
  204. if [ -s "$JUNIT_REPORT_XML" ]; then
  205. echo "$JUNIT_REPORT_XML exists"
  206. ls -la "$JUNIT_REPORT_XML"
  207. else
  208. echo "$JUNIT_REPORT_XML doesn't exist or has zero size"
  209. ls -la "$JUNIT_REPORT_XML" || true
  210. exit $RC
  211. fi
  212. fi
  213. )
  214. - name: archive unitest reports (orig)
  215. shell: bash
  216. run: |
  217. gzip -c $JUNIT_REPORT_XML > $REPORTS_ARTIFACTS_DIR/orig_junit.xml.gz
  218. - name: postprocess junit report
  219. shell: bash
  220. run: |
  221. set -x
  222. .github/scripts/tests/transform-ya-junit.py -i \
  223. -m .github/config/muted_ya.txt \
  224. --ya-out "$OUT_DIR" \
  225. --log-url-prefix "$S3_URL_PREFIX/logs/" \
  226. --log-out-dir "$ARTIFACTS_DIR/logs/" \
  227. --test-stuff-out "$TEST_ARTIFACTS_DIR/" \
  228. --test-stuff-prefix "$S3_TEST_ARTIFACTS_URL_PREFIX/" \
  229. "$JUNIT_REPORT_XML"
  230. .github/scripts/tests/split-junit.py -o "$JUNIT_REPORT_PARTS" "$JUNIT_REPORT_XML"
  231. - name: archive unitest reports (transformed)
  232. shell: bash
  233. run: |
  234. tar -C $JUNIT_REPORT_PARTS/.. -czf $REPORTS_ARTIFACTS_DIR/junit_parts.xml.tar.gz $(basename $JUNIT_REPORT_PARTS)
  235. - name: Unit test history upload results
  236. if: inputs.testman_token
  237. shell: bash
  238. run: |
  239. set -x
  240. PROXY_ADDR=127.0.0.1:8888
  241. openssl req -x509 -newkey rsa:2048 \
  242. -keyout $TMP_DIR/key.pem -out $TMP_DIR/cert.pem \
  243. -sha256 -days 1 -nodes -subj "/CN=127.0.0.1"
  244. ./ydb/ci/testmo-proxy/testmo-proxy.py -l $PROXY_ADDR \
  245. --cert-file "$TMP_DIR/cert.pem" \
  246. --cert-key "$TMP_DIR/key.pem" \
  247. --target-timeout 3,10 \
  248. --max-request-time 55 \
  249. "$TESTMO_URL" &
  250. proxy_pid=$!
  251. NODE_TLS_REJECT_UNAUTHORIZED=0 testmo automation:run:submit-thread \
  252. --instance "https://$PROXY_ADDR" --run-id "${{ steps.th.outputs.runid }}" \
  253. --results "$JUNIT_REPORT_PARTS/*.xml"
  254. kill $proxy_pid
  255. - name: Test history run complete
  256. if: always() && inputs.testman_token
  257. shell: bash
  258. run: |
  259. testmo automation:run:complete --instance "$TESTMO_URL" --run-id ${{ steps.th.outputs.runid }}
  260. - name: sync logs results to s3
  261. if: always()
  262. shell: bash
  263. run: |
  264. set -x
  265. echo "::group::s3-sync"
  266. s3cmd sync --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$LOG_DIR/" "$S3_LOG_BUCKET_PATH/"
  267. echo "::endgroup::"
  268. - name: write tests summary
  269. shell: bash
  270. if: always()
  271. run: |
  272. set -x
  273. mkdir $ARTIFACTS_DIR/summary/
  274. 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
  275. .github/scripts/tests/generate-summary.py \
  276. --summary-out-path $ARTIFACTS_DIR/summary/ \
  277. --summary-url-prefix $S3_URL_PREFIX/summary/ \
  278. --test-history-url $TEST_HISTORY_URL \
  279. --test-log-url="$YA_TEST_LOG_URL" \
  280. --build-preset "$BUILD_PRESET" \
  281. --status-report-file statusrep.txt \
  282. "Tests" ya-test.html "$JUNIT_REPORT_XML"
  283. teststatus=$(cat statusrep.txt)
  284. if [[ $teststatus == "success" ]];then
  285. testmessage="The check has been completed successfully"
  286. else
  287. testmessage="The check has been failed"
  288. fi
  289. curl -L -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{github.token}}" -H "X-GitHub-Api-Version: 2022-11-28" \
  290. https://api.github.com/repos/${{github.repository}}/statuses/${{github.event.pull_request.head.sha}} \
  291. -d '{"state":"'$teststatus'","description":"'"$testmessage"'","context":"test_${{inputs.build_preset}}"}'
  292. - name: sync test results to s3
  293. if: always()
  294. shell: bash
  295. run: |
  296. set -x
  297. echo "::group::s3-sync"
  298. s3cmd sync -r --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$ARTIFACTS_DIR/" "$S3_BUCKET_PATH/"
  299. s3cmd sync -r --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$TEST_ARTIFACTS_DIR/" "$S3_TEST_ARTIFACTS_BUCKET_PATH/"
  300. echo "::endgroup::"
  301. - name: check test results
  302. shell: bash
  303. run: |
  304. .github/scripts/tests/fail-checker.py "$JUNIT_REPORT_XML"
  305. - name: show free space
  306. if: always()
  307. shell: bash
  308. run: df -h