-
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 creation and use of testmo resource files
- Loading branch information
Showing
3 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,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 |
57 changes: 57 additions & 0 deletions
57
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,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 | ||
) |
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