diff --git a/test/actions.github.com/envrc.example b/test/actions.github.com/envrc.example new file mode 100644 index 00000000..4feaa63c --- /dev/null +++ b/test/actions.github.com/envrc.example @@ -0,0 +1,3 @@ +export TARGET_ORG="org" +export TARGET_REPO="repo" + diff --git a/test/actions.github.com/helper.sh b/test/actions.github.com/helper.sh index 68963128..06dd8cbb 100644 --- a/test/actions.github.com/helper.sh +++ b/test/actions.github.com/helper.sh @@ -124,3 +124,39 @@ function print_results() { echo "All tests passed!" fi } + +function run_workflow() { + local workflow_file="$1" + + echo "Checking if the workflow file exists" + gh workflow view -R "${TARGET_ORG}/${TARGET_REPO}" "${workflow_file}" || return 1 + + echo "Getting run count before a new run" + local target_run_count=$(($(gh run list -R "${TARGET_ORG}/${TARGET_REPO}" --workflow "${workflow_file}" --limit 1 --jq '. | length') + 1)) + + local queue_time=$(date +%FT%TZ) + + echo "Running workflow ${workflow_file}" + gh workflow run -R "${TARGET_ORG}/${TARGET_REPO}" "${workflow_file}" --ref main -f arc_name="${SCALE_SET_NAME}" || return 1 + + echo "Waiting for run to start" + local count=0 + local run_id= + while true; do + if [[ "${count}" -ge 12 ]]; then + echo "Timeout waiting for run to start" + return 1 + fi + + run_id=$(gh run list -R "${TARGET_ORG}/${TARGET_REPO} --workflow ${workflow_file} --created ">${queue_time}" --json name,databaseId --jq '.[] | select(.name | contains("${SCALE_SET_NAME}"))'") + if [ -n "$run_id" ]; then + echo "Run found: $run_id" + break + fi + sleep 5 + count=$((count+1)) + done + + echo "Waiting for run to complete" + gh run watch "${run_id}" -R "${TARGET_ORG}/${TARGET_REPO}" --exit-status +}