Upload Unit Test Results #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Upload Unit Test Results | |
on: | |
workflow_run: | |
workflows: | |
- evergreen | |
- linux | |
- win32 | |
types: | |
- completed | |
# TODO(b/293508740): Report failed workflow runs back to triggering PR. | |
jobs: | |
unit-test-report: | |
permissions: | |
pull-requests: write | |
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' }} | |
runs-on: ubuntu-latest | |
name: Upload Unit Test Reports | |
steps: | |
- name: Download '${{ github.event.workflow_run.name }}' Unit Test Results | |
# 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 | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const name = context.payload.workflow_run.name; | |
const url = context.payload.workflow_run.html_url; | |
console.log(`Downloading artifacts from ${url}`) | |
context.payload.workflow_run.pull_requests.forEach(pr => { | |
console.log(`Pull request: ${context.payload.repository.html_url}/pull/${pr.number}`); | |
}); | |
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'); | |
const path = `${process.env.GITHUB_WORKSPACE}/unit-test-results.zip`; | |
fs.writeFileSync(path, 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: Get Datadog CLI | |
shell: bash | |
env: | |
DD_VERSION: 'v2.18.0' | |
DD_SHA256SUM: 'adbe9b3a41faaf0b1d9702ba256cf8fa9e474c0cc8216f25e5b489c53d6f0a70 datadog-ci' | |
run: | | |
set -e | |
download_url="https://github.com/DataDog/datadog-ci/releases/download/${DD_VERSION}/datadog-ci_linux-x64" | |
curl -L --fail $download_url --output datadog-ci | |
echo ${DD_SHA256SUM} | sha256sum --check | |
chmod +x datadog-ci | |
- name: Upload to Datadog | |
# Unit test results are archived on the following format: | |
# ├── <platform> | |
# │ ├── <shards> | |
# │ │ └── <test result xmls> | |
# │ └── TAGS | |
# ├── <platform> | |
# │ ├── <shards> | |
# │ │ └── <test result xmls> | |
# │ └── TAGS | |
# etc. | |
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. | |
for dir in unit-test-results/*/; do | |
echo "Uploading $dir test report" | |
export DD_TAGS=`cat ${dir}TAGS` | |
./datadog-ci junit upload \ | |
$dir/**/*.xml | |
done |