action.yml 12 KB

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