From 9bab604724460aef598a8fc75ddaec0f29bba3f4 Mon Sep 17 00:00:00 2001 From: Manan Gupta <35839558+GuptaManan100@users.noreply.github.com> Date: Wed, 10 Apr 2024 10:59:44 +0530 Subject: [PATCH] Run launchable in unit race (#15686) Signed-off-by: Manan Gupta --- .github/workflows/unit_race.yml | 44 ++++++++++++++++++++++++++++++++- tools/unit_test_race.sh | 4 +-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit_race.yml b/.github/workflows/unit_race.yml index 34f7c1453ec..1e177872160 100644 --- a/.github/workflows/unit_race.yml +++ b/.github/workflows/unit_race.yml @@ -6,6 +6,11 @@ concurrency: permissions: read-all +env: + LAUNCHABLE_ORGANIZATION: "vitess" + LAUNCHABLE_WORKSPACE: "vitess-app" + GITHUB_PR_HEAD_SHA: "${{ github.event.pull_request.head.sha }}" + jobs: build: @@ -28,6 +33,13 @@ jobs: fi echo Skip ${skip} echo "skip-workflow=${skip}" >> $GITHUB_OUTPUT + + PR_DATA=$(curl \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}") + draft=$(echo "$PR_DATA" | jq .draft -r) + echo "is_draft=${draft}" >> $GITHUB_OUTPUT - name: Check out code if: steps.skip-workflow.outputs.skip-workflow == 'false' @@ -59,6 +71,10 @@ jobs: with: go-version: 1.22.2 + - name: Set up python + if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.unit_tests == 'true' + uses: actions/setup-python@v5 + - name: Tune the OS if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.unit_tests == 'true' run: | @@ -85,12 +101,27 @@ jobs: go mod download go install golang.org/x/tools/cmd/goimports@latest + + # install JUnit report formatter + go install github.com/vitessio/go-junit-report@HEAD - name: Run make tools if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.unit_tests == 'true' run: | make tools + - name: Setup launchable dependencies + if: steps.skip-workflow.outputs.is_draft == 'false' && steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.unit_tests == 'true' && github.base_ref == 'main' + run: | + # Get Launchable CLI installed. If you can, make it a part of the builder image to speed things up + pip3 install --user launchable~=1.0 > /dev/null + + # verify that launchable setup is all correct. + launchable verify || true + + # Tell Launchable about the build you are producing and testing + launchable record build --name "$GITHUB_RUN_ID" --no-commit-collection --source . + - name: unit_race if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.unit_tests == 'true' timeout-minutes: 45 @@ -100,4 +131,15 @@ jobs: export VTDATAROOT="/tmp/" export NOVTADMINBUILD=1 - eatmydata -- make unit_test_race + eatmydata -- make unit_test_race | tee -a output.txt | go-junit-report -set-exit-code > report.xml + + - name: Print test output and Record test result in launchable if PR is not a draft + if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.unit_tests == 'true' && always() + run: | + if [[ "${{steps.skip-workflow.outputs.is_draft}}" == "false" ]]; then + # send recorded tests to launchable + launchable record tests --build "$GITHUB_RUN_ID" go-test . || true + fi + + # print test output + cat output.txt \ No newline at end of file diff --git a/tools/unit_test_race.sh b/tools/unit_test_race.sh index 4cec1f365a9..b1c59e9ea2e 100755 --- a/tools/unit_test_race.sh +++ b/tools/unit_test_race.sh @@ -36,7 +36,7 @@ all_except_flaky_tests=$(echo "$packages_with_tests" | grep -vE ".+ .+_flaky_tes flaky_tests=$(echo "$packages_with_tests" | grep -E ".+ .+_flaky_test\.go" | cut -d" " -f1) # Run non-flaky tests. -echo "$all_except_flaky_tests" | xargs go test $VT_GO_PARALLEL -race -count=1 +echo "$all_except_flaky_tests" | xargs go test $VT_GO_PARALLEL -v -race -count=1 if [ $? -ne 0 ]; then echo "ERROR: Go unit tests failed. See above for errors." echo @@ -52,7 +52,7 @@ for pkg in $flaky_tests; do max_attempts=3 attempt=1 # Set a timeout because some tests may deadlock when they flake. - until go test -timeout 2m $VT_GO_PARALLEL $pkg -race -count=1; do + until go test -timeout 2m $VT_GO_PARALLEL $pkg -v -race -count=1; do echo "FAILED (try $attempt/$max_attempts) in $pkg (return code $?). See above for errors." if [ $((++attempt)) -gt $max_attempts ]; then echo "ERROR: Flaky Go unit tests in package $pkg failed too often (after $max_attempts retries). Please reduce the flakiness."