name: 'executable-monitor' description: 'Runs and executable until a termination line is hit or a timeout occurs. Reports if the executable completed successfully or failed.' inputs: exe-path: description: 'Path to the executable to run.' required: true log-dir: description: 'Path to directory to store logs.' required: false default: "" success-line: description: 'Line of output from executable indicating success.' required: false default: "" timeout-seconds: description: 'Maximum amount of time to run the executable. Default is 600.' required: false default: 300 retry-attempts: description: 'Number of times to re-launch the binary to check for success.' required: false default: 0 success-exit-code: description: 'Exit status that indicates that the executable completed successfully. Required if --success-line is not used.' required: false default: "" runs: using: "composite" steps: - name: Install Dependencies run: | # Install Dependencies echo "::group::Install Dependencies" pip install -r $GITHUB_ACTION_PATH/requirements.txt echo "::endgroup::" if [ "$?" = "0" ]; then echo -e "\033[32;3mInstalled all dependencies\033[0m" exit 0 else echo -e "\033[32;31mDependencies Install failed...\033[0m" exit 1 fi shell: bash - name: Run Executable with Monitoring run: | # Run Executable with Monitoring echo "::group::Argument Parsing" optArgs=" " # Make sure we have an exit condition to look for if [ "${{ inputs.success-exit-code }}" = "" ] && [ "${{ inputs.success-line }}" = "" ]; then echo "::endgroup::" echo -e "\033[32;31mDid not supply an input of success-line or success-exit-code to search for\033[0m" exit 1 fi # Check if an exit code was provided if [ "${{ inputs.success-exit-code }}" != "" ]; then optArgs="--success-exit-code=${{ inputs.success-exit-code }} $optArgs" echo "Adding --success-exit-code=${{ inputs.success-exit-code }} to the call" fi # Check for log directory/if a log file should be created if [ "${{ inputs.log-dir }}" != "" ]; then optArgs="--log-dir=${{ inputs.log-dir}} $optArgs" echo "Adding --log-dir=${{ inputs.log-dir}} to the call" fi # Check for retry attempts if [ "${{ inputs.retry-attempts }}" != "" ]; then optArgs="--retry-attempts=${{ inputs.retry-attempts }} $optArgs" echo "Adding --retry-attempts=${{ inputs.retry-attempts }} to the call" fi # Check if a success line was provided. Converting the github input to a bash variable # Will cause it to tokenize on spaces when passed into python # So just only add the success line if it exits. # set +e so if the run fails we can capture that and print custom error message set +e if [ "${{ inputs.success-line }}" != "" ]; then successLineArgs="--success-line=\"${{ inputs.success-line}}\" $optArgs" echo "Adding --success-line=${{ inputs.success-line}} to the call" echo "::endgroup::" echo -e "\033[1;33mRunning Command: python3 $GITHUB_ACTION_PATH/executable-monitor.py --exe-path=${{ inputs.exe-path }} --timeout-seconds=${{ inputs.timeout-seconds }} --success-line="${{ inputs.success-line }}" $optArgs \033[0m" echo "::group::Executable Output" python3 $GITHUB_ACTION_PATH/executable-monitor.py --exe-path=${{ inputs.exe-path }} --timeout-seconds=${{ inputs.timeout-seconds }} $optArgs --success-line="${{ inputs.success-line}}" else echo "::endgroup::" echo -e "\033[1;33mRunning Command: python3 $GITHUB_ACTION_PATH/executable-monitor.py --exe-path=${{ inputs.exe-path }} --timeout-seconds=${{ inputs.timeout-seconds }} $optArgs \033[0m" echo "::group::Executable Output" python3 $GITHUB_ACTION_PATH/executable-monitor.py --exe-path=${{ inputs.exe-path }} --timeout-seconds=${{ inputs.timeout-seconds }} $optArgs fi # Store status as the echo group will overwrite it exitStatus=$? echo "::endgroup::" if [ "$exitStatus" = "0" ]; then echo -e "\033[32;3mValid exit status found\033[0m" exit 0 else echo -e "\033[32;31mDid not find a valid exit condition\033[0m" set -e exit 1 fi shell: bash