Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
# Datadog JUnitXML Upload Actions
# Datadog JUnitXML Upload Action

This action downloads the [datadog-ci](https://github.com/DataDog/datadog-ci) and uses it to upload JUnitXML files
to the [CI Visibility product](https://docs.datadoghq.com/continuous_integration/).
to the [Test Optimization product](https://docs.datadoghq.com/tests/).

This action sets up node and requires node `>=14`. You can configure a specific version of node to use.
Note that if you have setup another version already it will override it.
Note that if you have set up another version already it will override it.

## Usage

```yaml
name: Test Code
on: [push]
on: [ push ]
jobs:
test:
steps:
- uses: actions/checkout@v3
- run: make tests
- uses: datadog/junit-upload-github-action@v1
- uses: datadog/junit-upload-github-action@v2
with:
api_key: ${{ secrets.DD_API_KEY }}
service: my-app
files: ./reports/
api_key: ${{ secrets.DD_API_KEY }}
```

## Inputs

The action has the following options:

| Name | Description | Required | Default |
| ---- | ----------- | -------- | ------- |
| `api_key` | Datadog API key to use to upload the junit files. | True | |
| `service` | Service name to use with the uploaded test results. | True | |
| `site` | The Datadog site to upload the files to. | True | `datadoghq.com` |
| `files` | Path to file or folder containing XML files to upload | True | `.` |
| `concurrency` | Controls the maximum number of concurrent file uploads | True | `20` |
| `node-version` | The node version to use to install the datadog-ci. It must be `>=14` | True | `20` |
| `tags` | Optional extra tags to add to the tests formatted as a comma separated list of tags. Example: `foo:bar,data:dog` | False | |
| `env` | Optional environment to add to the tests | False | |
| `logs` | When set to "true" enables forwarding content from the XML reports as Logs. The content inside `<system-out>`, `<system-err>`, and `<failure>` is collected as logs. Logs from elements inside a `<testcase>` are automatically connected to the test. | False | |
| `datadog-ci-version` | Optionally pin the @datadog/datadog-ci version. | False | `latest` |
| `extra-args` | Extra args to be passed to the datadog-ci junit upload command.| False | |
| Name | Description | Required | Default |
|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|-----------------|
| `api_key` | Datadog API key to use to upload the junit files. | True | |
| `site` | The Datadog site to upload the files to. | False | `datadoghq.com` |
| `files` | Path to file or folder containing XML files to upload | False | `.` |
| `auto-discovery` | Do a recursive search and automatic XML files discovery in the folders provided in `files` input (current folder if omitted). | False | `true` |
| `ignored-paths` | A comma-separated list of paths that are ignored when junit files auto-discovery is done. Glob patterns are supported. | False | |
| `concurrency` | Controls the maximum number of concurrent file uploads | False | `20` |
| `node-version` | The node version to use to install the datadog-ci. It must be `>=14` | False | `20` |
| `tags` | Optional extra tags to add to the tests formatted as a comma separated list of tags. Example: `foo:bar,data:dog` | False | |
| `service` | Service name to use with the uploaded test results. | False | |
| `env` | Optional environment to add to the tests | False | |
| `logs` | When set to "true" enables forwarding content from the XML reports as Logs. The content inside `<system-out>`, `<system-err>`, and `<failure>` is collected as logs. Logs from elements inside a `<testcase>` are automatically connected to the test. | False | |
| `datadog-ci-version` | Optionally pin the @datadog/datadog-ci version. | False | `latest` |
| `extra-args` | Extra args to be passed to the datadog-ci junit upload command. | False | |
61 changes: 20 additions & 41 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
# Composite action to upload junit test result files to Datadog CI Visibility
# Composite action to upload junit test result files to Datadog Test Optimization
name: "Datadog JUnitXML Upload"
description: "Upload JUnitXML reports files to Datadog CI Visibility"
description: "Upload JUnitXML reports files to Datadog Test Optimization"
inputs:
api-key:
required: false
description: (Deprecated) Datadog API key to use to upload the junit files.
deprecationMessage: "This input is deprecated. Use `api_key` instead."
api_key:
required: false
description: Datadog API key to use to upload the junit files.
service:
required: true
description: Service name to use with the uploaded test results.
datadog-site:
required: false
default: datadoghq.com
description: (Deprecated) The Datadog site to upload the files to.
deprecationMessage: "This input is deprecated. Use `site` instead."
description: Datadog API key to use to upload the junit files.
site:
required: false
default: datadoghq.com
Expand All @@ -25,6 +13,13 @@ inputs:
required: true
description: JUnit files to upload.
default: .
auto-discovery:
required: true
description: Do a recursive search and automatic junit files discovery in the folders provided in `files` input (current folder if omitted).
default: 'true'
ignored-paths:
required: false
description: A comma-separated list of paths that are ignored when junit files auto-discovery is done. Glob patterns are supported
concurrency:
required: true
description: Controls the maximum number of concurrent file uploads.
Expand All @@ -36,6 +31,9 @@ inputs:
tags:
required: false
description: Datadog tags to associate with the uploaded test results.
service:
required: false
description: Service name to use with the uploaded test results.
env:
required: false
description: Datadog env to use for the tests.
Expand All @@ -57,39 +55,20 @@ runs:
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- name: Check if input values are correct
shell: bash
run: |
if [ -z "${{ inputs.api_key }}" ] && [ -z "${{ inputs.api-key }}" ]; then
echo "Error: Both api_key and api-key are undefined. At least one must be defined."
exit 1
fi
- name: Upload the JUnit files
if: ${{ inputs.logs == 'true' }}
shell: bash
run: |
npx @datadog/datadog-ci@${{ inputs.datadog-ci-version}} junit upload \
--service ${{ inputs.service }} \
--logs \
--max-concurrency ${{ inputs.concurrency }} \
${{ inputs.extra-args }} \
${{ inputs.files }}
env:
DATADOG_API_KEY: ${{ inputs.api_key != '' && inputs.api_key || inputs.api-key }}
DATADOG_SITE: ${{ inputs.site != '' && inputs.site || inputs.datadog-site }}
DD_ENV: ${{ inputs.env }}
DD_TAGS: ${{ inputs.tags }}

- name: Upload the JUnit files
if: ${{ inputs.logs != 'true' }}
shell: bash
run: |
npx @datadog/datadog-ci@${{ inputs.datadog-ci-version}} junit upload \
--service ${{ inputs.service }} \
--max-concurrency ${{ inputs.concurrency }} \
${{ inputs.logs == 'true' && '--logs' || '' }} \
${{ inputs.auto-discovery == 'true' && '--auto-discovery' || '' }} \
${{ inputs.ignored-paths != '' && format('--ignored-paths {0}', inputs.ignored-paths) || '' }} \
${{ inputs.service != '' && format('--service {0}', inputs.service) || '' }} \
${{ inputs.extra-args }} \
${{ inputs.files }}
env:
DATADOG_API_KEY: ${{ inputs.api_key != '' && inputs.api_key || inputs.api-key }}
DATADOG_SITE: ${{ inputs.site != '' && inputs.site || inputs.datadog-site }}
DD_API_KEY: ${{ inputs.api_key }}
DD_SITE: ${{ inputs.site }}
DD_ENV: ${{ inputs.env }}
DD_TAGS: ${{ inputs.tags }}