From dc74460dd7de9e40980f236627df534de39bd358 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 11:22:08 +0200 Subject: [PATCH 1/9] update naming --- .github/workflows/test.yaml | 4 ++-- README.md | 6 +++--- action.yaml | 28 ++++++++++++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ed8c581..3c8e2f7 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,7 +46,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 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..1a943c0 100644 --- a/action.yaml +++ b/action.yaml @@ -3,13 +3,20 @@ 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. + 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. + site: + required: false default: datadoghq.com description: The Datadog site to upload the files to. files: @@ -48,6 +55,15 @@ 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 + else + echo "Inputs are valid." + 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 }} From 99d0c40849d0975147012478cd8f233800a43a13 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 11:31:01 +0200 Subject: [PATCH 2/9] add deprecation message --- action.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action.yaml b/action.yaml index 1a943c0..07491b5 100644 --- a/action.yaml +++ b/action.yaml @@ -5,6 +5,7 @@ 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. @@ -15,6 +16,7 @@ inputs: 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 From f1215ee946de1ca057b0241c05c82adcf28c9508 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 13:39:43 +0200 Subject: [PATCH 3/9] improve testing --- .github/workflows/test.yaml | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3c8e2f7..dff803b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,6 +5,7 @@ on: branches: - main - 'release/*' + - juan-fernandez/rename-inputs # to remove before merging schedule: - cron: '0 0 * * *' # Runs at midnight UTC every day @@ -46,11 +47,41 @@ jobs: - name: Upload reports using a glob pattern uses: ./ with: - api_key: ${{secrets.DD_API_KEY_CI_VISIBILITY}} + # 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" 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:bar @alpha:bravo @test.node.version:${{ matrix.version}}" + 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: ./ + 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: success() + run: echo "This step should not run" && exit 1 + - name: Check that previous step failed + if: failure() + run: echo "Previous step failed as expected" + \ No newline at end of file From d13dae1c202c3dde979bd2c4b2145830798ad7e5 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 14:13:34 +0200 Subject: [PATCH 4/9] go github From 71296d49e87ad0b450c2b841f30cca34a955fbae Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 14:17:21 +0200 Subject: [PATCH 5/9] better logic --- .github/workflows/test.yaml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index dff803b..0aeebfa 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -60,7 +60,7 @@ jobs: npm install @datadog/datadog-api-client node ./check-junit-upload.js env: - EXTRA_TAGS: "@foo:bar @alpha:bravo @test.node.version:${{ matrix.version}}" + 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 @@ -71,6 +71,7 @@ jobs: - uses: actions/checkout@v4 - name: Upload reports using a glob pattern uses: ./ + id: test_step with: logs: "true" files: '**/fixtures/**' @@ -79,9 +80,7 @@ jobs: tags: "foo:bar,alpha:bravo" continue-on-error: true - name: Check that previous step failed - if: success() - run: echo "This step should not run" && exit 1 - - name: Check that previous step failed - if: failure() - run: echo "Previous step failed as expected" - \ No newline at end of file + if: steps.test_step.outcome == 'success' + run: | + echo "The previous step did not fail as expected" + exit 1 From 9b07cf753f3229f61ce0fb004127d31f096ead9c Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 14:22:59 +0200 Subject: [PATCH 6/9] check that step fails --- .github/workflows/test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0aeebfa..5f5936f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -53,7 +53,7 @@ jobs: 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 }} - name: Check that test data can be queried run: | @@ -73,6 +73,7 @@ jobs: uses: ./ id: test_step with: + api-key: ${{secrets.DD_API_KEY_CI_VISIBILITY}} logs: "true" files: '**/fixtures/**' service: junit-upload-github-action-tests From a84dbc7dbf2cdfecfe64e330fcdfc744aa280024 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 14:24:17 +0200 Subject: [PATCH 7/9] now everything should pass --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5f5936f..fd3af92 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -73,7 +73,6 @@ jobs: uses: ./ id: test_step with: - api-key: ${{secrets.DD_API_KEY_CI_VISIBILITY}} logs: "true" files: '**/fixtures/**' service: junit-upload-github-action-tests From 2e48820319f743ab0ad5e28cafcf98a554dfc99b Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 14:25:42 +0200 Subject: [PATCH 8/9] remove branch run --- .github/workflows/test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fd3af92..6fdb0bb 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,7 +5,6 @@ on: branches: - main - 'release/*' - - juan-fernandez/rename-inputs # to remove before merging schedule: - cron: '0 0 * * *' # Runs at midnight UTC every day From 8df92e51c1f0ecb2ddd35e29772ff1e3ad157559 Mon Sep 17 00:00:00 2001 From: Juan Fernandez Date: Wed, 31 Jul 2024 14:27:25 +0200 Subject: [PATCH 9/9] remove inputs are valid echo --- action.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/action.yaml b/action.yaml index 07491b5..7901223 100644 --- a/action.yaml +++ b/action.yaml @@ -63,8 +63,6 @@ runs: 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 - else - echo "Inputs are valid." fi - name: Upload the JUnit files if: ${{ inputs.logs == 'true' }}