diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9c3ccd15..d0b18664 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,9 +10,6 @@ on: jobs: test: - strategy: - matrix: - version: [14, 16, 18, 20, 22, 24, 25] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -24,17 +21,51 @@ jobs: files: '**/fixtures/**' service: junit-upload-github-action-tests env: ci - tags: "foo:bar,alpha:bravo,test.node.version:${{ matrix.version}}" - node-version: ${{ matrix.version}} + tags: "foo:bar,alpha:bravo" - 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}}" + EXTRA_TAGS: "@foo:bar @alpha:bravo" 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-legacy-version-syntax: + runs-on: ubuntu-latest + strategy: + matrix: + # Test backwards compatibility with legacy npm semver syntax + version: ["latest", "^5.0.0", "~5.0.0", ">=5.0.0", "5.x"] + steps: + - uses: actions/checkout@v4 + - name: Sanitize version for tag + id: sanitize + run: | + version="${{ matrix.version }}" + # Replace special characters with safe equivalents for tags + safe_version=$(echo "$version" | sed 's/\^/caret-/g; s/~/tilde-/g; s/>=/gte-/g; s/>/gt-/g; s/<=/lte-/g; s/> "$GITHUB_OUTPUT" + - name: Upload reports using legacy version syntax + uses: ./ + with: + api_key: ${{secrets.DD_API_KEY_CI_VISIBILITY}} + logs: "true" + files: '**/fixtures/**' + service: junit-upload-github-action-tests + env: ci + tags: "foo:legacy,alpha:legacy,version.syntax:${{ steps.sanitize.outputs.safe_version }}" + datadog-ci-version: ${{ matrix.version }} + - name: Check that test data can be queried + run: | + npm install @datadog/datadog-api-client + node ./check-junit-upload.js + env: + EXTRA_TAGS: "@foo:legacy @alpha:legacy @version.syntax:${{ steps.sanitize.outputs.safe_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-older-datadog-ci-version: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index 595c76f9..9238f6d7 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ # Datadog JUnitXML Upload Action -This action downloads the [datadog-ci](https://github.com/DataDog/datadog-ci) and uses it to upload JUnitXML files +This action installs a pre-built [datadog-ci](https://github.com/DataDog/datadog-ci) binary 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 set up another version already it will override it. - ## Usage ```yaml @@ -33,10 +30,9 @@ The action has the following options: | `auto-discovery` | Do a recursive search and automatic XML files discovery in the folders provided in `files` input (current folder if omitted). Search for filenames that match `*junit*.xml`, `*test*.xml`, `*TEST-*.xml`. | 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` | +| `datadog-ci-version` | Version of datadog-ci to install. Use a major version like `v5` to get the latest release within that major version, or a specific tag like `v5.6.0` to pin. Legacy npm semver syntax (`^`, `~`, `>=`, `latest`) is still supported but deprecated. | False | `v5` | | `extra-args` | Extra args to be passed to the datadog-ci junit upload command. | False | | diff --git a/action.yaml b/action.yaml index 5bf46826..3bd592a6 100644 --- a/action.yaml +++ b/action.yaml @@ -24,10 +24,6 @@ inputs: required: true description: Controls the maximum number of concurrent file uploads. default: "20" - node-version: - required: true - description: The node version used to install datadog-ci - default: "20" tags: required: false description: Datadog tags to associate with the uploaded test results. @@ -42,8 +38,8 @@ inputs: description: Set to "true" to enable forwarding content from XML reports as logs. datadog-ci-version: required: false - description: The version of the @datadog/datadog-ci package to use. It defaults to the latest release (`latest`). - default: "latest" + description: Version of datadog-ci to install. Use a major version like `v5` to get the latest release within that major version, or a specific tag like `v5.6.0` to pin. Legacy npm semver syntax (^, ~, >=, latest) is still supported but deprecated. + default: "v5" extra-args: default: "" description: Extra args to be passed to the datadog-ci cli. @@ -51,15 +47,24 @@ inputs: runs: using: "composite" steps: - - name: Install node - uses: actions/setup-node@v6 + # TODO: Remove this step in the next major version (v3.0.0) + # Users should migrate to GitHub release tag syntax: v5, v5.10.0, etc. + - name: Translate version format (backwards compatibility) + id: translate-version + shell: bash + run: | + translated_version=$("${GITHUB_ACTION_PATH}/scripts/translate-version.sh" "${{ inputs.datadog-ci-version }}") + echo "version=${translated_version}" >> "$GITHUB_OUTPUT" + + - name: Install datadog-ci + uses: DataDog/install-datadog-ci-github-action@7960c07e413c56665e12346b34eec80089a7260e # v1.0.2 with: - node-version: ${{ inputs.node-version }} + version: ${{ steps.translate-version.outputs.version }} - name: Upload the JUnit files shell: bash run: | - npx @datadog/datadog-ci@${{ inputs.datadog-ci-version}} junit upload \ + datadog-ci junit upload \ --max-concurrency ${{ inputs.concurrency }} \ ${{ inputs.logs == 'true' && '--logs' || '' }} \ ${{ inputs.auto-discovery == 'true' && '--auto-discovery' || '' }} \ diff --git a/scripts/translate-version.sh b/scripts/translate-version.sh new file mode 100755 index 00000000..d13f8e15 --- /dev/null +++ b/scripts/translate-version.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Translates legacy npm semver syntax to GitHub release tag format +# +# This script provides backwards compatibility for users still using npm-style +# version specifiers (^, ~, >=, latest, etc.) by translating them to equivalent +# GitHub release tags that the install action understands. +# +# TODO: Remove this script in the next major version (v3.0.0) +# Users should migrate to GitHub release tag syntax: v5, v5.10.0, etc. + +set -euo pipefail + +version="$1" + +# Translate legacy npm semver syntax to GitHub release tags +case "$version" in + latest) + echo "::warning::datadog-ci-version 'latest' is deprecated. Please use 'v5' or '5' instead. This will use 'v5'." >&2 + version="v5" + ;; + ^*|~*|'>='*|'<='*|'>'*|'<'*|*.x) + # Extract major version number from semver expressions + # Handles: ^5.10.0, ~5.10.0, >=5.10.0, >5.10.0, <6.0.0, <=5.10.0, 5.x + major=$(echo "$version" | grep -oE '[0-9]+' | head -1) + if [[ -n "$major" ]]; then + echo "::warning::npm semver syntax ('$version') is deprecated. Please use 'v${major}' or '${major}' instead. This will use 'v${major}'." >&2 + version="v${major}" + else + echo "::warning::Unable to parse version '$version'. Passing through as-is, but this may fail." >&2 + fi + ;; +esac + +echo "$version"