aboutsummaryrefslogtreecommitdiffstats
path: root/.github/actions/test_ya/action.yml
blob: 8288d8fa03810d627afe59f28e33876b70722021 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Run tests (ya make)
description: Run tests using ya make
inputs:
  build_target:
    required: false
    description: "build target"
    
  sanitizer:
    required: false
    description: "sanitizer type (address, memory, thread, undefined, leak)"
    
  log_suffix:
    required: true
    description: "log suffix"
  test_threads:
    required: false
    default: "28"
    description: "Test threads count"

  testman_token:
    required: false
    description: "test manager auth token"
  testman_url:
    required: false
    description: "test manager endpoint"
  testman_project_id:
    required: false
    description: "test manager project id"
runs:
  using: "composite"
  steps:
    - name: Init
      id: init
      shell: bash
      run: |
        echo "SHELLOPTS=xtrace" >> $GITHUB_ENV
        export TMP_DIR=$(pwd)/tmp
        echo "TMP_DIR=$TMP_DIR" >> $GITHUB_ENV
        echo "LOG_DIR=$TMP_DIR/logs" >> $GITHUB_ENV
        echo "OUT_DIR=$TMP_DIR/out" >> $GITHUB_ENV
        echo "ARTIFACTS_DIR=$TMP_DIR/artifacts" >> $GITHUB_ENV
        echo "JUNIT_REPORT_XML=$TMP_DIR/junit.xml" >> $GITHUB_ENV
        echo "TESTMO_TOKEN=${{ inputs.testman_token }}" >> $GITHUB_ENV
        echo "TESTMO_URL=${{ inputs.testman_url }}" >> $GITHUB_ENV
        echo "SUMMARY_LINKS=$(mktemp)" >> $GITHUB_ENV
    
    - name: prepare
      shell: bash
      run: |
        rm -rf $TMP_DIR $JUNIT_REPORT_XML
        mkdir -p $TMP_DIR $OUT_DIR $ARTIFACTS_DIR $LOG_DIR
    
    - name: Install Node required for Testmo CLI
      uses: actions/setup-node@v3
      with:
        node-version: 19
    
    - name: Install Testmo CLI
      shell: bash
      run: npm install -g @testmo/testmo-cli
    - name: Test history run create
      id: th
      if: inputs.testman_token
      shell: bash
      env:
        PR_NUMBER: ${{ github.event.number }}
      run: |
        RUN_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
        BRANCH_TAG="$GITHUB_REF_NAME"
        TESTMO_SOURCE="${{ inputs.log_suffix }}"
        TESTMO_SOURCE="${TESTMO_SOURCE/_/-}"
        
        case $GITHUB_EVENT_NAME in
        workflow_dispatch)
         TESTMO_RUN_NAME="${{ github.run_id }} manual"
         EXTRA_TAG="manual"
         ;;
        pull_request | pull_request_target)
         TESTMO_RUN_NAME="${{ github.run_id }} PR #${PR_NUMBER}"
         EXTRA_TAG="pr"
         BRANCH_TAG=""
         ;;
        schedule)
         TESTMO_RUN_NAME="${{ github.run_id }} schedule"
         EXTRA_TAG="schedule"
         ;;
        *)
         TESTMO_RUN_NAME="${{ github.run_id }}"
         EXTRA_TAG=""
         ;;
        esac
        
        testmo automation:resources:add-link --name build --url "$RUN_URL" --resources testmo.json
        testmo automation:resources:add-field --name git-sha --type string --value "${GITHUB_SHA:0:7}" --resources testmo.json
        testmo automation:run:create --instance "$TESTMO_URL" --project-id "${{ inputs.testman_project_id }}" --name "$TESTMO_RUN_NAME" \
          --source "$TESTMO_SOURCE" --resources testmo.json \
          --tags "$BRANCH_TAG" --tags "$EXTRA_TAG"  | \
        echo "runid=$(cat)" >> $GITHUB_OUTPUT

    - name: Print test history link
      shell: bash
      run: |
        echo "10 [Test history](${TESTMO_URL}/automation/runs/view/${{steps.th.outputs.runid}})" >> $SUMMARY_LINKS

    - name: set environment variables required by some tests
      shell: bash
      run: |
        echo "PSQL_BINARY=/usr/bin/psql" >> $GITHUB_ENV

    - name: ya test
      shell: bash
      run: |
        extra_params=()

        if [ ! -z "${{ inputs.build_target }}" ]; then
          extra_params+=(--target="${{ inputs.build_target }}")
        fi

        if [ ! -z "${{ inputs.sanitizer }}" ] && [ "${{ inputs.sanitizer }}" != "none" ]; then
          extra_params+=(--sanitize="${{ inputs.sanitizer }}")
        fi

        ./ya test -A --build relwithdebinfo -D'BUILD_LANGUAGES=CPP PY3' --test-threads "${{ inputs.test_threads }}" \
          --regular-tests --do-not-output-stderrs -T \
          --stat --log-file "$LOG_DIR/ya_log.txt" --evlog-file "$LOG_DIR/ya_evlog.jsonl" \
          --dump-graph --dump-graph-to-file "$LOG_DIR/ya_graph.json" \
          --junit "$JUNIT_REPORT_XML" --output "$OUT_DIR" "${extra_params[@]}" || (
            RC=$?
            if [ $RC == 10 ]; then
              echo "ya test returned failed tests status, recovering.."
            else
              exit $RC
            fi
        )

    - name: postprocess junit report
      shell: bash
      run: |
        .github/scripts/tests/transform-ya-junit.py -i \
          --mu .github/config/muted_test.txt \
          --mf .github/config/muted_functest.txt \
          --ya-out "$OUT_DIR" \
          --log-url-prefix "$S3_URL_PREFIX/logs/" \
          --log-out-dir "$ARTIFACTS_DIR/logs/" \
          "$JUNIT_REPORT_XML"

    - name: write tests summary
      if: always()
      shell: bash
      env:
        GITHUB_TOKEN: ${{ github.token }}
      run: |
        
        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
        
        mkdir $ARTIFACTS_DIR/summary/
        
        .github/scripts/tests/generate-summary.py \
        --summary-out-path $ARTIFACTS_DIR/summary/ \
        --summary-url-prefix $S3_URL_PREFIX/summary/ \
        "Tests" ya-test.html "$JUNIT_REPORT_XML"


    - name: Unit test history upload results
      if: always() && inputs.testman_token
      shell: bash
      run: |
        testmo automation:run:submit-thread \
          --instance "$TESTMO_URL" --run-id ${{ steps.th.outputs.runid }} \
          --results "$JUNIT_REPORT_XML"

    - name: sync test results to s3
      if: always()
      shell: bash
      run: |
        echo "::group::s3-sync"
        s3cmd sync --follow-symlinks --acl-public --no-progress --stats --no-check-md5 "$ARTIFACTS_DIR/" "$S3_BUCKET_PATH/"
        echo "::endgroup::"

    - name: sync logs results to s3
      if: always()
      shell: bash
      run: |
        echo "::group::s3-sync"
        s3cmd sync --follow-symlinks --acl-private --no-progress --stats --no-check-md5 "$LOG_DIR/" "$S3_BUCKET_PATH/test_logs/"
        echo "::endgroup::"


    - name: Test history run complete
      if: always() && inputs.testman_token
      shell: bash
      run: |
        testmo automation:run:complete --instance "$TESTMO_URL" --run-id ${{ steps.th.outputs.runid }}

    - name: check test results
      shell: bash
      run: |
        .github/scripts/tests/fail-checker.py "$JUNIT_REPORT_XML"