From 2698d99bee93889705cdb1908168dd66b2e06edb Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Wed, 25 Sep 2024 12:05:43 +0000 Subject: [PATCH 01/21] support creation and use of testmo resource files --- actions/testmo-create-resources/action.yml | 24 ++++++++ .../compose_testmo_resources_file.py | 57 +++++++++++++++++++ actions/testmo-run-submit-thread/action.yml | 17 +++++- 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 actions/testmo-create-resources/action.yml create mode 100755 actions/testmo-create-resources/compose_testmo_resources_file.py diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml new file mode 100644 index 0000000..c5d8b2b --- /dev/null +++ b/actions/testmo-create-resources/action.yml @@ -0,0 +1,24 @@ +name: create testmo resources +description: 'create a TestMo resource .json file' +inputs: + resources_file: + description: "file name where the resources will be stored" + required: true + resources_json: + description: "stringified JSON associative array of resource fields to add. Each field's key is the name of the field, and it's value is the value of the field." + default: "" + required: false +runs: + using: "composite" + steps: + - name: add actions path to PATH + shell: bash + run: echo "${{ github.action_path }}" >> $GITHUB_PATH + + - name: compose TESTMO resources file + run: | + echo "composing TESTMO resources file ${{ inputs.resources_file }} ..." + compose_testmo_resources_file.py \ + --resources_json '${{ inputs.resources_json }}' \ + --destination "${{ inputs.resources_file }}" + shell: bash diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py new file mode 100755 index 0000000..55c2cb8 --- /dev/null +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -0,0 +1,57 @@ +#! /usr/bin/env python + +# Script to create a TestMo "resources" file containing a specified +# set of fields. The fields are passed in as JSON with the key being the name +# of the field, and it's value being the value of the field. +# Warning; only "string" type fields are supported here. +# see these references for details about the use of TestMo resources files: +# https://docs.testmo.com/docs/automation/reference#submitting-threads-for-runs +# https://docs.testmo.com/docs/automation/reference#adding-fields-links-and-artifacts + +import argparse +import json +import pathlib +import subprocess + +if __name__ == "__main__": + + # command line arguments + args_parser = argparse.ArgumentParser() + + args_parser.add_argument( + "-j", + "--resources_json", + help="string version of JSON identifying resource fields", + type=str) + + args_parser.add_argument( + "-d", + "--destination", + help="filepath relative to REPO root to generate the file," + " default 'testmo_resources.json'.", + default='testmo_resources.json', + type=str) + + args = args_parser.parse_args() + fields = json.loads(args.resources_json) + + for field in fields: + testmo_args = { + "resources": args.destination, + "name": field, + "type": "string", + "value": fields[field] + } + testmo_command = "npx testmo automation:resources:add-field " + \ + " ".join([f"--{k} {v}" + for k, v in testmo_args.items()]) + + # run the command and raise any exceptions + result = subprocess.run( + testmo_command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True, + cwd=pathlib.Path.cwd(), + shell=True + ) diff --git a/actions/testmo-run-submit-thread/action.yml b/actions/testmo-run-submit-thread/action.yml index 03c80e3..044016f 100644 --- a/actions/testmo-run-submit-thread/action.yml +++ b/actions/testmo-run-submit-thread/action.yml @@ -15,6 +15,10 @@ inputs: results: description: directory of JUnit '*.xml' formatted result files required: true + thread_resources: + description: "JSON file with TestMo resources to attach to this thread" + default: "" + required: false step_status: description: status of reported step required: true @@ -48,14 +52,21 @@ runs: # submit results SUCCESS=0 - if [ ${REPORT} -eq 1 ]; then + if [[ ${REPORT} -eq 1 ]]; then echo "submitting results to TESTMO run ..." - # not checking testmo_url and token as this should be - # called between "create" and "complete" + ## not checking testmo_url and token as this should be + ## called between "create" and "complete" + if [[ -f "${{ inputs.resources_file }}" ]]; then + thread_resources=${{ inputs.resources_file }} + else + echo '{}' > thread_resources.json + thread_resources=thread_resources.json + fi npx testmo automation:run:submit-thread \ --instance ${TESTMO_URL} \ --run-id ${TESTMO_RUN_ID} \ --results ${RESULTS} \ + --thread-resources ${thread_resources} \ -- step-status.sh "${{ inputs.step_status }}" || SUCCESS=$? fi echo "status=${SUCCESS}" >> "$GITHUB_OUTPUT" From 41f9bbfd71f2b03f7f509f3106707ef6c370d192 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Wed, 25 Sep 2024 16:15:52 +0000 Subject: [PATCH 02/21] pass testmo command as list of strings --- .../compose_testmo_resources_file.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index 55c2cb8..a448ef1 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -42,16 +42,13 @@ "type": "string", "value": fields[field] } - testmo_command = "npx testmo automation:resources:add-field " + \ - " ".join([f"--{k} {v}" - for k, v in testmo_args.items()]) + testmo_command = (["npx", "testmo", "automation:resources:add-field"] + + [f"--{k} {v}" for k, v in testmo_args.items()]) # run the command and raise any exceptions result = subprocess.run( testmo_command, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + capture_output=True, check=True, - cwd=pathlib.Path.cwd(), - shell=True + cwd=pathlib.Path.cwd() ) From f7c21766097f9088a6a645ad624929446d5f694b Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Wed, 25 Sep 2024 18:13:53 +0000 Subject: [PATCH 03/21] redefine testmo_args as list --- .../compose_testmo_resources_file.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index a448ef1..bb99ff5 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -36,18 +36,17 @@ fields = json.loads(args.resources_json) for field in fields: - testmo_args = { - "resources": args.destination, - "name": field, - "type": "string", - "value": fields[field] - } - testmo_command = (["npx", "testmo", "automation:resources:add-field"] + - [f"--{k} {v}" for k, v in testmo_args.items()]) + testmo_args = [ + "--resources", args.destination, + "--name", field, + "--type", "string", + "--value", fields[field] + ] + testmo_command = ["npx", "testmo", "automation:resources:add-field"] # run the command and raise any exceptions result = subprocess.run( - testmo_command, + testmo_command + testmo_args, capture_output=True, check=True, cwd=pathlib.Path.cwd() From ce42b09e6b706eb3fe153f0fb478625dddf44d07 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Wed, 25 Sep 2024 18:18:21 +0000 Subject: [PATCH 04/21] still use shell=True --- .../testmo-create-resources/compose_testmo_resources_file.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index bb99ff5..a41da26 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -29,7 +29,7 @@ "--destination", help="filepath relative to REPO root to generate the file," " default 'testmo_resources.json'.", - default='testmo_resources.json', + default="testmo_resources.json", type=str) args = args_parser.parse_args() @@ -49,5 +49,6 @@ testmo_command + testmo_args, capture_output=True, check=True, - cwd=pathlib.Path.cwd() + cwd=pathlib.Path.cwd(), + shell=True ) From 8647e4443629c02e6b065f7c449af03c0f25ac4b Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Wed, 25 Sep 2024 18:31:08 +0000 Subject: [PATCH 05/21] skip shell=True, but ignore ruff S603 --- .../testmo-create-resources/compose_testmo_resources_file.py | 3 +-- ruff.toml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index a41da26..8f945a5 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -49,6 +49,5 @@ testmo_command + testmo_args, capture_output=True, check=True, - cwd=pathlib.Path.cwd(), - shell=True + cwd=pathlib.Path.cwd() ) diff --git a/ruff.toml b/ruff.toml index c7a04fc..c19bdeb 100644 --- a/ruff.toml +++ b/ruff.toml @@ -14,6 +14,7 @@ ignore = [ "ISC001", "TCH002", "PLW1514", # allow Path.open without encoding + "S603"# https://github.com/astral-sh/ruff/issues/4045 ] select = [ # Rules reference: https://docs.astral.sh/ruff/rules/ From 340245cfdc5adf8e68bd36e221235bc7a2005130 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Thu, 26 Sep 2024 17:29:39 +0000 Subject: [PATCH 06/21] ruff style updates --- actions/testmo-create-resources/action.yml | 14 +++++++++----- actions/testmo-run-submit-thread/action.yml | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index c5d8b2b..d96decf 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -1,15 +1,19 @@ +--- name: create testmo resources -description: 'create a TestMo resource .json file' +description: create a TestMo resource .json file + inputs: resources_file: - description: "file name where the resources will be stored" + description: file name where the resources will be stored required: true resources_json: - description: "stringified JSON associative array of resource fields to add. Each field's key is the name of the field, and it's value is the value of the field." - default: "" + description: stringified JSON associative array of resource fields to add. Each field's + key is the name of the field, and it's value is the value of the field. + default: '' required: false + runs: - using: "composite" + using: composite steps: - name: add actions path to PATH shell: bash diff --git a/actions/testmo-run-submit-thread/action.yml b/actions/testmo-run-submit-thread/action.yml index 044016f..0591ef9 100644 --- a/actions/testmo-run-submit-thread/action.yml +++ b/actions/testmo-run-submit-thread/action.yml @@ -16,8 +16,8 @@ inputs: description: directory of JUnit '*.xml' formatted result files required: true thread_resources: - description: "JSON file with TestMo resources to attach to this thread" - default: "" + description: JSON file with TestMo resources to attach to this thread + default: '' required: false step_status: description: status of reported step From fee3dadff674079a747921475279ef08917b4bfb Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Thu, 26 Sep 2024 19:26:38 +0000 Subject: [PATCH 07/21] Keep shell=True after all --- .../testmo-create-resources/compose_testmo_resources_file.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index 8f945a5..a41da26 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -49,5 +49,6 @@ testmo_command + testmo_args, capture_output=True, check=True, - cwd=pathlib.Path.cwd() + cwd=pathlib.Path.cwd(), + shell=True ) From 72066177bb73301773f0781bb63d54e3641cc8b5 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Thu, 26 Sep 2024 19:31:56 +0000 Subject: [PATCH 08/21] and skip the ruff error --- .../testmo-create-resources/compose_testmo_resources_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index a41da26..e284f64 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -45,7 +45,7 @@ testmo_command = ["npx", "testmo", "automation:resources:add-field"] # run the command and raise any exceptions - result = subprocess.run( + result = subprocess.run( # noqa: S602 testmo_command + testmo_args, capture_output=True, check=True, From c3cf2dce0c83e2a6084eeb41460b9e19ed30daac Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 13:51:41 +0000 Subject: [PATCH 09/21] properly reference thread_resources --- actions/testmo-run-submit-thread/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/testmo-run-submit-thread/action.yml b/actions/testmo-run-submit-thread/action.yml index 0591ef9..f84d7ab 100644 --- a/actions/testmo-run-submit-thread/action.yml +++ b/actions/testmo-run-submit-thread/action.yml @@ -56,8 +56,8 @@ runs: echo "submitting results to TESTMO run ..." ## not checking testmo_url and token as this should be ## called between "create" and "complete" - if [[ -f "${{ inputs.resources_file }}" ]]; then - thread_resources=${{ inputs.resources_file }} + if [[ -f "${{ inputs.thread_resources }}" ]]; then + thread_resources=${{ inputs.thread_resources }} else echo '{}' > thread_resources.json thread_resources=thread_resources.json From ae8e709d89eac23440de226e3d5ba21b938c306f Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 14:54:43 +0000 Subject: [PATCH 10/21] include some useful debugging output and don't capture_output from subprocess so that it ended up in stdout/stderr for debugging. --- actions/testmo-create-resources/action.yml | 2 ++ .../testmo-create-resources/compose_testmo_resources_file.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index d96decf..4f987d9 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -25,4 +25,6 @@ runs: compose_testmo_resources_file.py \ --resources_json '${{ inputs.resources_json }}' \ --destination "${{ inputs.resources_file }}" + echo "resource file ${{ inputs.resources_json }} contents:\n" + cat "${{ inputs.resources_file }}\n" shell: bash diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index e284f64..706ccbb 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -32,6 +32,7 @@ default="testmo_resources.json", type=str) + print(f"cwd: {pathlib.Path.cwd()}") args = args_parser.parse_args() fields = json.loads(args.resources_json) @@ -45,9 +46,8 @@ testmo_command = ["npx", "testmo", "automation:resources:add-field"] # run the command and raise any exceptions - result = subprocess.run( # noqa: S602 + subprocess.run( # noqa: S602 testmo_command + testmo_args, - capture_output=True, check=True, cwd=pathlib.Path.cwd(), shell=True From cd840cdbf534f3b42e6a0214dfb5b6e79e707320 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 15:04:39 +0000 Subject: [PATCH 11/21] block quality check flag on debugging print statement --- .../testmo-create-resources/compose_testmo_resources_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index 706ccbb..c743684 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -32,7 +32,7 @@ default="testmo_resources.json", type=str) - print(f"cwd: {pathlib.Path.cwd()}") + print(f"cwd: {pathlib.Path.cwd()}") # noqa: T201 args = args_parser.parse_args() fields = json.loads(args.resources_json) From d8ad39f7cc0b89334b95e72ac2c287bd075e9fed Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 16:17:21 +0000 Subject: [PATCH 12/21] add more debugging statements --- .../compose_testmo_resources_file.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index c743684..0ddbff4 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -27,9 +27,7 @@ args_parser.add_argument( "-d", "--destination", - help="filepath relative to REPO root to generate the file," - " default 'testmo_resources.json'.", - default="testmo_resources.json", + help="absolute path for where to generate the file,", type=str) print(f"cwd: {pathlib.Path.cwd()}") # noqa: T201 @@ -52,3 +50,6 @@ cwd=pathlib.Path.cwd(), shell=True ) + + print(f"destination: {args.destination}") # noqa: T201 + print(f"exists: {pathlib.Path(args.destination).exists()}") # noqa: T201 From 3742889f03d50a4113531e37677a097bb8607f3f Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 16:34:59 +0000 Subject: [PATCH 13/21] minor fixes to debug --- actions/testmo-create-resources/action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index 4f987d9..64f038d 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -22,9 +22,10 @@ runs: - name: compose TESTMO resources file run: | echo "composing TESTMO resources file ${{ inputs.resources_file }} ..." + echo "CWD: $(pwd)" compose_testmo_resources_file.py \ --resources_json '${{ inputs.resources_json }}' \ --destination "${{ inputs.resources_file }}" - echo "resource file ${{ inputs.resources_json }} contents:\n" - cat "${{ inputs.resources_file }}\n" + echo "resource file ${{ inputs.resources_json }} contents:" + cat "${{ inputs.resources_file }}" shell: bash From da80280355cc2dbb82061fe800f70f5d0cbe257c Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 17:22:52 +0000 Subject: [PATCH 14/21] more debug statements --- actions/testmo-create-resources/action.yml | 4 +++- .../testmo-create-resources/compose_testmo_resources_file.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index 64f038d..bb3480f 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -22,10 +22,12 @@ runs: - name: compose TESTMO resources file run: | echo "composing TESTMO resources file ${{ inputs.resources_file }} ..." - echo "CWD: $(pwd)" + echo "shell CWD: $(pwd)" + ls -A compose_testmo_resources_file.py \ --resources_json '${{ inputs.resources_json }}' \ --destination "${{ inputs.resources_file }}" + ls -A echo "resource file ${{ inputs.resources_json }} contents:" cat "${{ inputs.resources_file }}" shell: bash diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index 0ddbff4..6155437 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -11,6 +11,7 @@ import argparse import json import pathlib +import shlex import subprocess if __name__ == "__main__": @@ -42,10 +43,12 @@ "--value", fields[field] ] testmo_command = ["npx", "testmo", "automation:resources:add-field"] + full_command = testmo_command + testmo_args + print(f"running command: {shlex.join(full_command)}") # noqa: T201 # run the command and raise any exceptions subprocess.run( # noqa: S602 - testmo_command + testmo_args, + full_command, check=True, cwd=pathlib.Path.cwd(), shell=True From c169df91c037716804a1c37456cdecb191a083de Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 18:17:39 +0000 Subject: [PATCH 15/21] try quoting attribute values for add-field --- .../compose_testmo_resources_file.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index 6155437..e087060 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -37,10 +37,10 @@ for field in fields: testmo_args = [ - "--resources", args.destination, - "--name", field, + "--resources", f'"{args.destination}"', + "--name", f'"{field}"', "--type", "string", - "--value", fields[field] + "--value", f'"{fields[field]}"' ] testmo_command = ["npx", "testmo", "automation:resources:add-field"] full_command = testmo_command + testmo_args From 6a1b88d0e2bfc6d4bfbc627286a6009b043c1d65 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 18:50:02 +0000 Subject: [PATCH 16/21] only double quotes --- .../compose_testmo_resources_file.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index e087060..a33f78a 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -37,10 +37,10 @@ for field in fields: testmo_args = [ - "--resources", f'"{args.destination}"', - "--name", f'"{field}"', + "--resources", f"{args.destination}", + "--name", f"{field}", "--type", "string", - "--value", f'"{fields[field]}"' + "--value", f"{fields[field]}" ] testmo_command = ["npx", "testmo", "automation:resources:add-field"] full_command = testmo_command + testmo_args From 5f6698702f478bc9cec29812fe3688a5d1e47e6b Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Fri, 27 Sep 2024 21:18:15 +0000 Subject: [PATCH 17/21] set testmo token when calling add-field --- actions/testmo-create-resources/action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index bb3480f..7d5e60e 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -3,6 +3,9 @@ name: create testmo resources description: create a TestMo resource .json file inputs: + testmo_token: + description: testmo token + required: true resources_file: description: file name where the resources will be stored required: true @@ -30,4 +33,6 @@ runs: ls -A echo "resource file ${{ inputs.resources_json }} contents:" cat "${{ inputs.resources_file }}" + env: + TESTMO_TOKEN: ${{ inputs.testmo_token }} shell: bash From 4b6da103f5aa259ed242cc812b95ce5061dcace2 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Mon, 30 Sep 2024 11:39:20 +0000 Subject: [PATCH 18/21] remove some debugging lines and minimize subprocess call --- actions/testmo-create-resources/action.yml | 25 +++++++++---------- .../compose_testmo_resources_file.py | 14 +---------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index 7d5e60e..32802be 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -1,6 +1,6 @@ --- name: create testmo resources -description: create a TestMo resource .json file +description: create a Testmo resource .json file inputs: testmo_token: @@ -11,7 +11,7 @@ inputs: required: true resources_json: description: stringified JSON associative array of resource fields to add. Each field's - key is the name of the field, and it's value is the value of the field. + key is the name of the field, and its value is the value of the field. default: '' required: false @@ -22,17 +22,16 @@ runs: shell: bash run: echo "${{ github.action_path }}" >> $GITHUB_PATH - - name: compose TESTMO resources file + - name: compose Testmo resources file run: | - echo "composing TESTMO resources file ${{ inputs.resources_file }} ..." - echo "shell CWD: $(pwd)" - ls -A + echo "composing Testmo resources file ${{ inputs.resources_file }} ..." compose_testmo_resources_file.py \ - --resources_json '${{ inputs.resources_json }}' \ - --destination "${{ inputs.resources_file }}" - ls -A - echo "resource file ${{ inputs.resources_json }} contents:" - cat "${{ inputs.resources_file }}" - env: - TESTMO_TOKEN: ${{ inputs.testmo_token }} + --resources_json "$RESOURCES_JSON" \ + --destination "$RESOURCES_FILE" + + echo "resources file contents:" + cat "$RESOURCES_FILE" shell: bash + env: + RESOURCES_FILE: ${{ inputs.resources_file }} + RESOURCES_JSON: ${{ inputs.resources_json }} diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index a33f78a..b9805b8 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -10,8 +10,6 @@ import argparse import json -import pathlib -import shlex import subprocess if __name__ == "__main__": @@ -31,7 +29,6 @@ help="absolute path for where to generate the file,", type=str) - print(f"cwd: {pathlib.Path.cwd()}") # noqa: T201 args = args_parser.parse_args() fields = json.loads(args.resources_json) @@ -44,15 +41,6 @@ ] testmo_command = ["npx", "testmo", "automation:resources:add-field"] full_command = testmo_command + testmo_args - print(f"running command: {shlex.join(full_command)}") # noqa: T201 # run the command and raise any exceptions - subprocess.run( # noqa: S602 - full_command, - check=True, - cwd=pathlib.Path.cwd(), - shell=True - ) - - print(f"destination: {args.destination}") # noqa: T201 - print(f"exists: {pathlib.Path(args.destination).exists()}") # noqa: T201 + subprocess.run(full_command, check=True) \ No newline at end of file From ef74d9fc2ab36a392ea11a078f9e54a4a39935df Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Mon, 30 Sep 2024 11:42:19 +0000 Subject: [PATCH 19/21] fix quality check fail --- .../testmo-create-resources/compose_testmo_resources_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/testmo-create-resources/compose_testmo_resources_file.py b/actions/testmo-create-resources/compose_testmo_resources_file.py index b9805b8..e7e01bf 100755 --- a/actions/testmo-create-resources/compose_testmo_resources_file.py +++ b/actions/testmo-create-resources/compose_testmo_resources_file.py @@ -43,4 +43,4 @@ full_command = testmo_command + testmo_args # run the command and raise any exceptions - subprocess.run(full_command, check=True) \ No newline at end of file + subprocess.run(full_command, check=True) From 58e53529b83287942ee3dde9a4e98e76c21c06c9 Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Mon, 30 Sep 2024 11:52:23 +0000 Subject: [PATCH 20/21] fix quality check fail --- actions/testmo-create-resources/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index 32802be..792cd59 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -28,7 +28,7 @@ runs: compose_testmo_resources_file.py \ --resources_json "$RESOURCES_JSON" \ --destination "$RESOURCES_FILE" - + echo "resources file contents:" cat "$RESOURCES_FILE" shell: bash From ec2093fdfe222e48080151a7a3d3d7668f63441d Mon Sep 17 00:00:00 2001 From: derekk-nm Date: Mon, 30 Sep 2024 12:00:58 +0000 Subject: [PATCH 21/21] remove token input --- actions/testmo-create-resources/action.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/actions/testmo-create-resources/action.yml b/actions/testmo-create-resources/action.yml index 792cd59..3dfda83 100644 --- a/actions/testmo-create-resources/action.yml +++ b/actions/testmo-create-resources/action.yml @@ -3,9 +3,6 @@ name: create testmo resources description: create a Testmo resource .json file inputs: - testmo_token: - description: testmo token - required: true resources_file: description: file name where the resources will be stored required: true @@ -24,7 +21,7 @@ runs: - name: compose Testmo resources file run: | - echo "composing Testmo resources file ${{ inputs.resources_file }} ..." + echo "composing Testmo resources file '$RESOURCES_FILE'" compose_testmo_resources_file.py \ --resources_json "$RESOURCES_JSON" \ --destination "$RESOURCES_FILE"