From 860de518ccbc3ab7c7dd5e4056f0e46812ef0575 Mon Sep 17 00:00:00 2001 From: David Kirov Date: Tue, 17 Dec 2024 15:08:52 +0100 Subject: [PATCH] Add option for e2e env vars in workflow --- .github/workflows/pr.yml | 3 +-- .github/workflows/test-target.yml | 35 +++++++++++++++++++------------ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 618c96527dc952..863e267d0e0925 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -43,7 +43,6 @@ jobs: repo: "core" standard: true pytest-args: "-s -k test_fips_inactive_e2e" - fips-mode: false traces-artifact-name: traces-tls-linux-no-fips test-results-name: test-tls-linux-no-fips agent-image: "datadog/agent-dev:main-fips" @@ -59,10 +58,10 @@ jobs: repo: "core" standard: true pytest-args: "-s -k test_fips_active_e2e" - fips-mode: true traces-artifact-name: traces-tls-linux-fips test-results-name: test-tls-linux-fips agent-image: "datadog/agent-dev:main-fips" + e2e-env-vars: "{'GOFIPS':'1'}" secrets: inherit test-tls-windows: diff --git a/.github/workflows/test-target.yml b/.github/workflows/test-target.yml index 175465dec45a54..4aa4eb5289a62c 100644 --- a/.github/workflows/test-target.yml +++ b/.github/workflows/test-target.yml @@ -89,11 +89,11 @@ on: required: false type: string default: "" - fips-mode: - description: "Should the agent be run in FIPS mode for e2e tests" + e2e-env-vars: + description: "Key-value pairs of environment variables for the Agent container." required: false - type: boolean - default: false + type: string + default: "{}" defaults: run: @@ -122,6 +122,7 @@ jobs: # Capture traces for a separate job to do the submission TRACE_CAPTURE_BASE_DIR: "trace-captures" TRACE_CAPTURE_LOG: "trace-captures/output.log" + E2E_ENV_VARS: "" steps: @@ -133,6 +134,14 @@ jobs: echo "TEST_RESULTS_DIR=$TEST_RESULTS_BASE_DIR/$JOB_NAME" >> $GITHUB_ENV echo "TRACE_CAPTURE_FILE=$TRACE_CAPTURE_BASE_DIR/$JOB_NAME" >> $GITHUB_ENV + - name: + run: | + for key in $(echo '${{ toJSON(fromJSON(inputs.e2e-env-vars)) }}' | jq -r 'keys[]'); do + value=$(echo '${{ toJSON(fromJSON(inputs.e2e-env-vars)) }}' | jq -r --arg k "$key" '.[$k]') + E2E_ENV_VARS+="-e ${key}=${value} " + done + echo "E2E_ENV_VARS=$E2E_ENV_VARS" >> $GITHUB_ENV + - name: Set up Windows if: runner.os == 'Windows' run: |- @@ -279,7 +288,7 @@ jobs: # by default if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then set +e # Disable immediate exit - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --base --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} + ddev env test ${{ env.E2E_ENV_VARS }} --base --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} exit_code=$? if [ $exit_code -eq 5 ]; then # Flaky test count can be zero, this is done to avoid pipeline failure @@ -290,7 +299,7 @@ jobs: fi elif [ '${{ inputs.pytest-args }}' = '-m "not flaky"' ]; then set +e # Disable immediate exit - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --base --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} + ddev env test ${{ env.E2E_ENV_VARS }} --base --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} exit_code=$? if [ $exit_code -eq 5 ]; then # Flaky test count can be zero, this is done to avoid pipeline failure @@ -300,7 +309,7 @@ jobs: exit $exit_code fi else - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --base --new-env --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- all {0}', inputs.pytest-args) || '' }} + ddev env test ${{ env.E2E_ENV_VARS }} --base --new-env --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- all {0}', inputs.pytest-args) || '' }} fi - name: Run E2E tests @@ -317,7 +326,7 @@ jobs: # by default if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then set +e # Disable immediate exit - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} + ddev env test ${{ env.E2E_ENV_VARS }} --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} exit_code=$? if [ $exit_code -eq 5 ]; then # Flaky test count can be zero, this is done to avoid pipeline failure @@ -328,7 +337,7 @@ jobs: fi elif [ '${{ inputs.pytest-args }}' = '-m "not flaky"' ]; then set +e # Disable immediate exit - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} + ddev env test ${{ env.E2E_ENV_VARS }} --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} exit_code=$? if [ $exit_code -eq 5 ]; then # Flaky test count can be zero, this is done to avoid pipeline failure @@ -338,7 +347,7 @@ jobs: exit $exit_code fi else - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --new-env --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- all {0}', inputs.pytest-args) || '' }} + ddev env test ${{ env.E2E_ENV_VARS }} --new-env --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- all {0}', inputs.pytest-args) || '' }} fi - name: Run benchmarks @@ -364,7 +373,7 @@ jobs: # by default if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then set +e # Disable immediate exit - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --base --new-env --junit ${{ inputs.target }}:latest -- all ${{ inputs.pytest-args }} + ddev env test ${{ env.E2E_ENV_VARS }} --base --new-env --junit ${{ inputs.target }}:latest -- all ${{ inputs.pytest-args }} exit_code=$? if [ $exit_code -eq 5 ]; then # Flaky test count can be zero, this is done to avoid pipeline failure @@ -375,7 +384,7 @@ jobs: fi elif [ '${{ inputs.pytest-args }}' = '-m "not flaky"' ]; then set +e # Disable immediate exit - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --base --new-env --junit ${{ inputs.target }}:latest -- all ${{ inputs.pytest-args }} + ddev env test ${{ env.E2E_ENV_VARS }} --base --new-env --junit ${{ inputs.target }}:latest -- all ${{ inputs.pytest-args }} exit_code=$? if [ $exit_code -eq 5 ]; then # Flaky test count can be zero, this is done to avoid pipeline failure @@ -385,7 +394,7 @@ jobs: exit $exit_code fi else - ddev env test -e GOFIPS=${{ inputs.fips-mode && '1' || '0' }} --base --new-env --junit ${{ inputs.target }}:latest ${{ inputs.pytest-args != '' && format('-- all {0}', inputs.pytest-args) || '' }} + ddev env test ${{ env.E2E_ENV_VARS }} --base --new-env --junit ${{ inputs.target }}:latest ${{ inputs.pytest-args != '' && format('-- all {0}', inputs.pytest-args) || '' }} fi - name: View trace log