-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support creating TestMo "resource" files (#32)
* support creation and use of testmo resource files * pass testmo command as list of strings * redefine testmo_args as list * still use shell=True * skip shell=True, but ignore ruff S603 * ruff style updates * Keep shell=True after all * and skip the ruff error * properly reference thread_resources * include some useful debugging output and don't capture_output from subprocess so that it ended up in stdout/stderr for debugging. * block quality check flag on debugging print statement * add more debugging statements * minor fixes to debug * more debug statements * try quoting attribute values for add-field * only double quotes * set testmo token when calling add-field * remove some debugging lines and minimize subprocess call * fix quality check fail * fix quality check fail * remove token input
- Loading branch information
Showing
4 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
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 its 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 '$RESOURCES_FILE'" | ||
compose_testmo_resources_file.py \ | ||
--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 }} |
46 changes: 46 additions & 0 deletions
46
actions/testmo-create-resources/compose_testmo_resources_file.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#! /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 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="absolute path for where to generate the file,", | ||
type=str) | ||
|
||
args = args_parser.parse_args() | ||
fields = json.loads(args.resources_json) | ||
|
||
for field in fields: | ||
testmo_args = [ | ||
"--resources", f"{args.destination}", | ||
"--name", f"{field}", | ||
"--type", "string", | ||
"--value", f"{fields[field]}" | ||
] | ||
testmo_command = ["npx", "testmo", "automation:resources:add-field"] | ||
full_command = testmo_command + testmo_args | ||
|
||
# run the command and raise any exceptions | ||
subprocess.run(full_command, check=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters