action.yml 10 KB

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