action.yml 11 KB

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