diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ed8c581..6fdb0bb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -19,7 +19,7 @@ jobs: - name: Upload reports using a glob pattern uses: ./ with: - api-key: ${{secrets.DD_API_KEY_CI_VISIBILITY}} + api_key: ${{secrets.DD_API_KEY_CI_VISIBILITY}} logs: "true" files: '**/fixtures/**' service: junit-upload-github-action-tests @@ -46,11 +46,40 @@ jobs: - name: Upload reports using a glob pattern uses: ./ with: + # should still work with api-key as input api-key: ${{secrets.DD_API_KEY_CI_VISIBILITY}} logs: "true" files: '**/fixtures/**' service: junit-upload-github-action-tests env: ci - tags: "foo:bar,alpha:bravo" + tags: "foo:previous,alpha:previous" datadog-ci-version: ${{ env.SECOND_LATEST_VERSION }} - \ No newline at end of file + - name: Check that test data can be queried + run: | + npm install @datadog/datadog-api-client + node ./check-junit-upload.js + env: + EXTRA_TAGS: "@foo:previous @alpha:previous" + DD_API_KEY: ${{ secrets.DD_API_KEY_CI_VISIBILITY }} + DD_APP_KEY: ${{ secrets.DD_APP_KEY_CI_VISIBILITY }} + DD_SERVICE: junit-upload-github-action-tests + + test-should-complain-about-missing-api-key: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Upload reports using a glob pattern + uses: ./ + id: test_step + with: + logs: "true" + files: '**/fixtures/**' + service: junit-upload-github-action-tests + env: ci + tags: "foo:bar,alpha:bravo" + continue-on-error: true + - name: Check that previous step failed + if: steps.test_step.outcome == 'success' + run: | + echo "The previous step did not fail as expected" + exit 1 diff --git a/README.md b/README.md index d2e1b51..281959d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ jobs: - run: make tests - uses: datadog/junit-upload-github-action@v1 with: - api-key: ${{ secrets.DD_API_KEY }} + api_key: ${{ secrets.DD_API_KEY }} service: my-app files: ./reports/ ``` @@ -29,9 +29,9 @@ The action has the following options: | Name | Description | Required | Default | | ---- | ----------- | -------- | ------- | -| `api-key` | Datadog API key to use to upload the junit files. | True | | +| `api_key` | Datadog API key to use to upload the junit files. | True | | | `service` | Service name to use with the uploaded test results. | True | | -| `datadog-site` | The Datadog site to upload the files to. | True | `datadoghq.com` | +| `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` | diff --git a/action.yaml b/action.yaml index c26028a..7901223 100644 --- a/action.yaml +++ b/action.yaml @@ -3,13 +3,22 @@ name: "Datadog JUnitXML Upload" description: "Upload JUnitXML reports files to Datadog CI Visibility" inputs: api-key: - required: true + 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: true + required: false + default: datadoghq.com + description: (Deprecated) The Datadog site to upload the files to. + deprecationMessage: "This input is deprecated. Use `site` instead." + site: + required: false default: datadoghq.com description: The Datadog site to upload the files to. files: @@ -48,6 +57,13 @@ 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 @@ -59,8 +75,8 @@ runs: ${{ inputs.extra-args }} \ ${{ inputs.files }} env: - DATADOG_API_KEY: ${{ inputs.api-key }} - DATADOG_SITE: ${{ inputs.datadog-site }} + 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 @@ -73,7 +89,7 @@ runs: ${{ inputs.extra-args }} \ ${{ inputs.files }} env: - DATADOG_API_KEY: ${{ inputs.api-key }} - DATADOG_SITE: ${{ inputs.datadog-site }} + 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 }}