From d5ee92e89c89ab832cc4b9f5c8c070b5d58409f9 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Wed, 12 Mar 2025 15:45:36 +0100 Subject: [PATCH 1/4] Use reports auto-discovery by default. Make service input optional --- .gitignore | 1 + README.md | 38 +++++++++++++++++------------------ action.yaml | 57 +++++++++++++++++------------------------------------ 3 files changed, 38 insertions(+), 58 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/README.md b/README.md index cfad14a..0287c71 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Datadog JUnitXML Upload Actions 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. @@ -10,33 +10,33 @@ Note that if you have setup another version already it will override it. ```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 ``, ``, and `` is collected as logs. Logs from elements inside a `` 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 ``, ``, and `` is collected as logs. Logs from elements inside a `` 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 | | diff --git a/action.yaml b/action.yaml index 7901223..70fa516 100644 --- a/action.yaml +++ b/action.yaml @@ -2,21 +2,9 @@ name: "Datadog JUnitXML Upload" description: "Upload JUnitXML reports files to Datadog CI Visibility" 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 @@ -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. @@ -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. @@ -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 }} + DATADOG_API_KEY: ${{ inputs.api_key }} + DATADOG_SITE: ${{ inputs.site }} DD_ENV: ${{ inputs.env }} DD_TAGS: ${{ inputs.tags }} From 93e4d0eb5631827f37b408af9bd0c22b28007ddc Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Wed, 12 Mar 2025 16:22:47 +0100 Subject: [PATCH 2/4] Address review comments --- action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 70fa516..0161c86 100644 --- a/action.yaml +++ b/action.yaml @@ -68,7 +68,7 @@ runs: ${{ inputs.extra-args }} \ ${{ inputs.files }} env: - DATADOG_API_KEY: ${{ inputs.api_key }} - DATADOG_SITE: ${{ inputs.site }} + DD_API_KEY: ${{ inputs.api_key }} + DD_SITE: ${{ inputs.site }} DD_ENV: ${{ inputs.env }} DD_TAGS: ${{ inputs.tags }} From 7c7b2cbc1c579d85b6c71f9f0704c461aa6f0abb Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Wed, 12 Mar 2025 16:36:31 +0100 Subject: [PATCH 3/4] Minor docs update --- action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yaml b/action.yaml index 0161c86..27e649c 100644 --- a/action.yaml +++ b/action.yaml @@ -1,6 +1,6 @@ -# 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: true From 0daa68902092aca0508e78f457c133671b7a2a84 Mon Sep 17 00:00:00 2001 From: Nikita Tkachenko Date: Wed, 12 Mar 2025 16:37:52 +0100 Subject: [PATCH 4/4] Minor docs update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0287c71..08216c3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# 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 [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