aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/test-results.yml
blob: 65071cd4cad1695f7c144b37dc9072cf8cb7a352 (plain)
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
name: Publish test results

on:
  workflow_run:
    workflows: ["CI"]
    types:
    - completed

jobs:
  publish-test-results:
    runs-on: ubuntu-latest
    if: github.event.workflow_run.conclusion != 'skipped'
    steps:
    - name: Download artifacts
      uses: actions/github-script@v3.1.0
      with:
        script: |
          var fs = require('fs');
          var artifacts = await github.actions.listWorkflowRunArtifacts({
             owner: context.repo.owner,
             repo: context.repo.repo,
             run_id: ${{github.event.workflow_run.id }},
          });
          var matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
            return artifact.name == 'tests.xml' || artifact.name == 'event.json'
          });
          var count = matchArtifacts.length;
          for (var i = 0; i < count; i++) {
            var matchArtifact = matchArtifacts[i];
            var download = await github.actions.downloadArtifact({
               owner: context.repo.owner,
               repo: context.repo.repo,
               artifact_id: matchArtifact.id,
               archive_format: 'zip',
            });
            var name = matchArtifact.name;
            var dest = name + '.zip'
            fs.writeFileSync('${{github.workspace}}/' + dest, Buffer.from(download.data));
            console.log("Downloaded", name, "as", dest);
          }
    - name: Extract test results
      run: unzip tests.xml.zip
    - name: Extract event payload
      run: unzip event.json.zip
    - name: Publish test results
      uses: EnricoMi/publish-unit-test-result-action@v1
      with:
        commit: ${{ github.event.workflow_run.head_sha }}
        event_file: event.json
        event_name: ${{ github.event.workflow_run.event }}
        files: tests.xml