-
Notifications
You must be signed in to change notification settings - Fork 31
138 lines (129 loc) · 5.42 KB
/
unit_test_report.yaml
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
name: Upload Unit Test Results
on:
# This workflow must be triggered via `workflow_run` to be able to access
# secrets, which is not possible from a workflow triggered by a PR in a fork.
workflow_run:
workflows:
- linux
# TODO: Temporary testing
- testing
# TODO: Download xml files from GCS
# - android
# - raspi
# TODO: Generate xml files
# - win32
# TODO: Get xml files from platforms
# - atv
# - ps
# - switch
# - xbox
types:
- completed
jobs:
unit-test-report:
permissions: {}
if: always()
runs-on: ubuntu-latest
name: Upload Unit Test Reports
steps:
- name: Download Unit Test Results
id: collect-report
uses: actions/github-script@v6
with:
script: |
// The `download-artifact` action can only access artifacts that
// were uploaded in the same workflow. Since it was not this
// workflow that uploaded the artifacts we must use rest api
// to download them.
// https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "unit-test-results"
});
if (matchArtifacts.length == 1) {
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifacts[0].id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/unit-test-results.zip`, Buffer.from(download.data));
} else {
core.setFailed(`Expected one artifact with name 'unit-test-results'. Found ${matchArtifacts.length}.`);
}
- name: Extract Archived Unit Test Results
run: unzip unit-test-results.zip -d unit-test-results
- name: Install node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Get Datadog CLI
shell: bash
# TODO: pin version (with checksum?)
run: npm install -g @datadog/datadog-ci
- name: Upload to Datadog
shell: bash
env:
DATADOG_API_KEY: ${{ secrets.DD_API_KEY }}
DATADOG_SITE: us5.datadoghq.com
DD_ENV: ci
DD_SERVICE: ${{ github.event.repository.name }}
# Need to populate git info via env vars as we don't have the repo to look at.
DD_GIT_REPOSITORY_URL: ${{ github.event.repository.git_url }}
DD_GIT_COMMIT_SHA: ${{ github.event.workflow_run.head_sha }}
DD_GIT_BRANCH: ${{ github.event.workflow_run.head_branch }}
DD_GIT_COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }}
DD_GIT_COMMIT_AUTHOR_NAME: ${{ github.event.workflow_run.head_commit.author.name }}
DD_GIT_COMMIT_AUTHOR_EMAIL: ${{ github.event.workflow_run.head_commit.author.email }}
DD_GIT_COMMIT_AUTHOR_DATE: ${{ github.event.workflow_run.head_commit.timestamp }}
DD_GIT_COMMIT_COMMITTER_NAME: ${{ github.event.workflow_run.head_commit.committer.name }}
DD_GIT_COMMIT_COMMITTER_EMAIL: ${{ github.event.workflow_run.head_commit.committer.email }}
DD_GIT_COMMIT_COMMITTER_DATE: ${{ github.event.workflow_run.head_commit.timestamp }}
run: |
# Loop over each platform, extract the tags and upload xml results.
# Unit test results are archived on the following format:
# ├── android-arm
# │ ├── <shards>
# │ │ └── <test result xmls>
# │ └── TAGS
# ├── linux-x64x11
# │ ├── <shards>
# │ │ └── <test result xmls>
# │ └── TAGS
# ├── raspi-2
# │ ├── <shards>
# │ │ └── <test result xmls>
# │ └── TAGS
# etc.
for dir in unit-test-results/*/; do
echo "Uploading $dir test report"
tags=`cat ${dir}TAGS`
datadog-ci junit upload \
--tags $tags \
$dir/**/*.xml
done
- name: Comment on PR on Failure
# TODO: Change to failure once tested.
if: success()
uses: actions/github-script@v6
with:
script: |
// Get url of this workflow run.
const actions_run = (await github.rest.actions.getWorkflowRun({
owner : context.repo.owner,
repo : context.repo.repo,
run_id : context.runId
})).data;
context.payload.workflow_run.pull_requests.forEach(pr => {
github.rest.issues.createComment({
issue_number: pr.number
owner: context.repo.owner,
repo: context.repo.repo,
body: `Failed to upload unit test results to DataDog. See ${actions_run.html_url} for details about the error.`
})
});