Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support creating TestMo "resource" files #32

Merged
merged 22 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions actions/testmo-create-resources/action.yml
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 actions/testmo-create-resources/compose_testmo_resources_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /usr/bin/env python
andy-neuma marked this conversation as resolved.
Show resolved Hide resolved

# 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)
17 changes: 14 additions & 3 deletions actions/testmo-run-submit-thread/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.thread_resources }}" ]]; then
thread_resources=${{ inputs.thread_resources }}
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"
Expand Down
1 change: 1 addition & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ignore = [
"ISC001",
"TCH002",
"PLW1514", # allow Path.open without encoding
"S603"# https://github.com/astral-sh/ruff/issues/4045
derekk-nm marked this conversation as resolved.
Show resolved Hide resolved
]
select = [
# Rules reference: https://docs.astral.sh/ruff/rules/
Expand Down