From ecd60819cb02c4edf909ee25fc42df370b2de805 Mon Sep 17 00:00:00 2001 From: vitaly4n <48485947+vitaly4n@users.noreply.github.com> Date: Mon, 16 Sep 2024 21:09:54 +0300 Subject: [PATCH] Alpha fixes (#3) * clear 'test create' args composer output * make curl fail on error * add test-infos-file output parameter --------- Co-authored-by: github-actions[bot] --- README.md | 2 ++ _impl/_compose_test_create_args.sh | 5 +---- _impl/_functions.sh | 14 +++++++------- _impl/test_run.sh | 16 ++++++++++------ test-single-run/action.yml | 17 ++++++++++++----- test-suite/action.yml | 20 ++++++++++++++------ 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 896539d..0adc08a 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ A list of directories containing `test-config.yaml` test configuration files sho |Output|Description| |------|-----------| |`test-ids`|IDs of performed tests.| +|`test-infos-file`|File containing a JSON array of objects with information about performed tests.| |`test-infos`|JSON array of objects with information about performed tests.| |`execution-report-file`|Path to generated .md execution report file.| |`checks-report-file`|Path to generated .md checks report file.| @@ -257,6 +258,7 @@ A directory containing `test-config.yaml` test configuration file should be prov |Output|Description| |------|-----------| |`test-id`|ID of performed test.| +|`test-info-file`|File containing a JSON object with information about performed test.| |`test-info`|JSON object with information about performed test.| |`report-file`|Path to generated .md report file.| |`artifacts-dir`|Action artifacts directory. If needed, save it using actions/upload_artifacts.| diff --git a/_impl/_compose_test_create_args.sh b/_impl/_compose_test_create_args.sh index ba662ab..1542451 100755 --- a/_impl/_compose_test_create_args.sh +++ b/_impl/_compose_test_create_args.sh @@ -187,7 +187,4 @@ if [[ -n ${_artifacts_bucket} ]]; then _ARGS+=(--artifacts-output-bucket "${_artifacts_bucket}") fi -( - IFS=$'\t' - echo "${ARGS[*]}" -) +printf '%s\0' "${ARGS[@]}" diff --git a/_impl/_functions.sh b/_impl/_functions.sh index 5cbd89e..baf45a7 100755 --- a/_impl/_functions.sh +++ b/_impl/_functions.sh @@ -160,13 +160,13 @@ function _log_outs() { local _level=0 fi - if [[ -n "$YC_SECRET_OUTPUT" ]]; then - _stdout='***SECRET***' - fi - _logv "$_level" "Command $1 finished with status $_rc:" _logv "$_level" " stderr: $_stderr" - _logv "$_level" " stdout: $_stdout" + if [[ -n "$YC_SECRET_OUTPUT" ]]; then + _logv "$_level" " stdout: ***SECRET***" + else + _logv "$_level" " stdout: $_stdout" + fi printf '%s' "$_stdout" 2>/dev/null return ${_rc} @@ -229,7 +229,7 @@ function yc_s3_upload { local -r token=${VAR_TOKEN:-$(yc_get_token)} local -r auth_h="X-YaCloud-SubjectToken: $token" - curl -L -H "$auth_h" --upload-file - "$VAR_OBJECT_STORAGE_URL/$bucket/$bucket_path" \ + curl --fail -L -H "$auth_h" --upload-file - "$VAR_OBJECT_STORAGE_URL/$bucket/$bucket_path" \ 2>/dev/null \ <"$file" @@ -247,7 +247,7 @@ function yc_s3_delete { local -r token=${VAR_TOKEN:-$(yc_get_token)} local -r auth_h="X-YaCloud-SubjectToken: $token" - curl -L -H "$auth_h" -X DELETE "$VAR_OBJECT_STORAGE_URL/$bucket/$bucket_path" \ + curl --fail -L -H "$auth_h" -X DELETE "$VAR_OBJECT_STORAGE_URL/$bucket/$bucket_path" \ 2>/dev/null return $? diff --git a/_impl/test_run.sh b/_impl/test_run.sh index ae14420..2285815 100755 --- a/_impl/test_run.sh +++ b/_impl/test_run.sh @@ -194,14 +194,18 @@ if [[ -n $VAR_ARTIFACTS_BUCKET ]]; then _composer_args+=(--artifacts-bucket "${VAR_ARTIFACTS_BUCKET}") fi -if ! _composer_output=$(run_script "$_SCRIPT_DIR/_compose_test_create_args.sh" "${_composer_args[@]}"); then - _log "Failed: output=$_composer_output" -fi +function _call_composer() { + if ! run_script "$_SCRIPT_DIR/_compose_test_create_args.sh" "${_composer_args[@]}"; then + _log "Failed to compose arguments" + fi +} +_logv 1 "Composer arguments:" _test_create_args=() -IFS=$'\t' read -d '' -ra _test_create_args <<<"$_composer_output" || true - -_logv 1 "Composed: ${_test_create_args[*]}" +while IFS= read -d '' -r _arg; do + _logv 1 " arg: $_arg" + _test_create_args+=("$_arg") +done < <(_call_composer) # ---------------------------------------------------------------------------- # # Run the test # diff --git a/test-single-run/action.yml b/test-single-run/action.yml index 750ff8a..989c283 100644 --- a/test-single-run/action.yml +++ b/test-single-run/action.yml @@ -91,6 +91,11 @@ outputs: description: |- ID of performed test. + test-info-file: + value: ${{ steps.output-info.outputs.res-file }} + description: |- + File containing a JSON object with information about performed test. + test-info: value: ${{ steps.output-info.outputs.res }} description: |- @@ -168,14 +173,16 @@ runs: if: always() shell: bash run: | - if [[ -z "${{ steps.output-id.outputs.res }}" ]]; then - echo "res='{}'" >> "$GITHUB_OUTPUT" - exit 0 - fi + RES_FILE="${{ steps.make-artifacts-dir.outputs.res }}/test-info.json" + echo "{}" > "$RES_FILE" + echo "res-file=$RES_FILE" >> "$GITHUB_OUTPUT" + if [[ -n "${{ steps.output-id.outputs.res }}" ]]; then + yc loadtesting test get "${{ steps.output-id.outputs.res }}" --format json > "$RES_FILE" + fi { echo 'res<> "$GITHUB_OUTPUT" diff --git a/test-suite/action.yml b/test-suite/action.yml index 60e0152..673733b 100644 --- a/test-suite/action.yml +++ b/test-suite/action.yml @@ -89,6 +89,11 @@ outputs: description: |- IDs of performed tests. + test-infos-file: + value: ${{ steps.output-infos.outputs.res-file }} + description: |- + File containing a JSON array of objects with information about performed tests. + test-infos: value: ${{ steps.output-infos.outputs.res }} description: |- @@ -183,16 +188,19 @@ runs: if: always() shell: bash run: | - if [[ -z "${{ steps.output-ids.outputs.res }}" ]]; then - echo "res='[]'" >> "$GITHUB_OUTPUT" - exit 0 + RES_FILE="${{ steps.make-artifacts-dir.outputs.res }}/test-infos.json" + echo "[]" > "$RES_FILE" + echo "res-file=$RES_FILE" >> "$GITHUB_OUTPUT" + + if [[ -n "${{ steps.output-ids.outputs.res }}" ]]; then + echo "${{ steps.output-ids.outputs.res }}" \ + | xargs -n1 yc --format json loadtesting test get \ + | jq --slurp > "$RES_FILE" fi - _ARGS=() - read -d '' -ra _ARGS <<< "${{ steps.output-ids.outputs.res }}" || true { echo 'res<> "$GITHUB_OUTPUT"