|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + target: |
| 5 | + required: true |
| 6 | + type: string |
| 7 | + secrets: |
| 8 | + GITHUB_TOKEN: |
| 9 | + required: true |
| 10 | + |
| 11 | +name: 'Workflow Analysis' |
| 12 | + |
| 13 | +jobs: |
| 14 | + report-test-flakes: |
| 15 | + name: 'Report test flakes' |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: write |
| 20 | + steps: |
| 21 | + - uses: actions/download-artifact@v3 |
| 22 | + - name: Parse test results |
| 23 | + run: | |
| 24 | + RESULTS_PATH="./test-results-${{ inputs.target }}/test-results.log" |
| 25 | +
|
| 26 | + csplit -q "$RESULTS_PATH" %^------------% |
| 27 | +
|
| 28 | + if [[ -f "./xx00" ]]; then |
| 29 | + SUMMARY=`tail ./xx00 -n+2` |
| 30 | +
|
| 31 | + if [[ "$SUMMARY" =~ 'FLAKY' ]]; then |
| 32 | + # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings |
| 33 | + { |
| 34 | + echo "summary<<EOF" |
| 35 | + echo "$SUMMARY" |
| 36 | + echo "EOF" |
| 37 | + } >> $GITHUB_OUTPUT |
| 38 | + fi |
| 39 | + fi |
| 40 | + - name: Report flakes |
| 41 | + uses: actions/github-script@v6 |
| 42 | + with: |
| 43 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + script: | |
| 45 | + const { data: comments } = await github.rest.issues.listComments({ |
| 46 | + owner: context.repo.owner, |
| 47 | + repo: context.repo.repo, |
| 48 | + issue_number: context.issue.number, |
| 49 | + }); |
| 50 | +
|
| 51 | + const flakeyTestsHeader = 'Test flake analysis: ${{ inputs.target }}'; |
| 52 | + const existingComment = comments.find(comment => { |
| 53 | + return comment.user.type === 'Bot' && comment.body.includes(flakeyTestsHeader) |
| 54 | + }); |
| 55 | +
|
| 56 | + let body; |
| 57 | +
|
| 58 | + if (${{ steps['Parse test results'].outputs.summary }}) { |
| 59 | + body = `${flakeyTestsHeader} |
| 60 | +
|
| 61 | + \`\`\`shell |
| 62 | + ${{ steps['Parse test results'].outputs.summary }} |
| 63 | + \`\`\` |
| 64 | + `; |
| 65 | + } else { |
| 66 | + body = `${flakeyTestsHeader} |
| 67 | +
|
| 68 | + No flakes detected! |
| 69 | + `; |
| 70 | + } |
| 71 | +
|
| 72 | + if (existingComment) { |
| 73 | + github.rest.issues.updateComment({ |
| 74 | + owner: context.repo.owner, |
| 75 | + repo: context.repo.repo, |
| 76 | + comment_id: existingComment.id, |
| 77 | + body |
| 78 | + }) |
| 79 | + } else { |
| 80 | + github.rest.issues.createComment({ |
| 81 | + issue_number: context.issue.number, |
| 82 | + owner: context.repo.owner, |
| 83 | + repo: context.repo.repo, |
| 84 | + body |
| 85 | + }) |
| 86 | + } |
0 commit comments