Output from GitHub action is empty

12.9k views Asked by At

I'm creating my first GitHub action and I can't figure out why the output is empty.

action.yml

name: "Run Endtest functional tests"
description: "Register a deployment event with Endtest and run the functional tests"
branding:
  icon: play-circle
  color: white
inputs:
  app_id:
    description: 'The Endtest App ID for your account. You can get it from the https://endtest.io/settings page.'
    required: true
  app_code:
    description: 'The Endtest App Code for your account. You can get it from the https://endtest.io/settings page.'
    required: true
  api_request:
    description: 'The Endtest API request for starting the test execution.'
    required: true
  number_of_loops:
    description: 'The number of times the API request for fetching the results will be sent once every 30 seconds.'
    required: true

outputs:
  test_suite_name:
    description: "The name of the test suite"
  configuration:
    description: "The configuration of the machine or mobile device on which the test was executed"
  test_cases:
    description: "The number of test cases"
  passed:
    description: "The number of assertions that have passed"
  failed:
    description: "The number of assertions that have failed"
  errors:
    description: "The number of errors that have been encountered"
  start_time:
    description: "The timestamp for the start of the test execution."
  end_time:
    description: "The timestamp for the end of the test execution."
  #detailed_logs:
    #description: "The detailed logs for the test execution"
  #screenshots_and_video:
    #description: "The URLs for the screenshts and video recordings of the test execution"

runs:
  using: "composite"
  steps:
    - run: sudo apt-get install jq
      shell: bash 
    - run: sudo chmod +x ${{ github.action_path }}/test.sh
      shell: bash 
    - run: echo "${{ inputs.api_request }}"
      shell: bash 
    - run: ${{ github.action_path }}/test.sh ${{ inputs.app_id }} ${{ inputs.app_code }} "${{ inputs.api_request }}" ${{ inputs.number_of_loops }} 
      shell: bash

test.sh

#!/bin/bash
set -e
hash=$(curl -X GET --header "Accept: */*" "${3}")
for run in {1.."${4}"}
do
  sleep 30
  result=$(curl -X GET --header "Accept: */*" "https://endtest.io/api.php?action=getResults&appId=${1}&appCode=${2}&hash=${hash}&format=json")
  if [ "$result" == "Test is still running." ]
  then
    status=$result
    # Don't print anything
  elif [ "$result" == "Processing video recording." ]
  then
    status=$result
    # Don't print anything
  elif [ "$result" == "Stopping." ]
  then
    status=$result
  elif [ "$result" == "Erred." ]
  then
    status=$result
    echo $status
  elif [ "$result" == "" ]
  then
    status=$result
    # Don't print anything
  else
     testsuitename=$( echo "$result" | jq '.test_suite_name' )
     configuration=$( echo "$result" | jq '.configuration' )
     testcases=$( echo "$result" | jq '.test_cases' )
     passed=$( echo "$result" | jq '.passed' )
     failed=$( echo "$result" | jq '.failed' )
     errors=$( echo "$result" | jq '.errors' )
     #detailedlogs=$( echo "$result" | jq '.detailed_logs' )
     #screenshotsandvideo=$( echo "$result" | jq '.screenshots_and_video' )
     starttime=$( echo "$result" | jq '.start_time' )
     endtime=$( echo "$result" | jq '.end_time' )   
     
     echo $testsuitename
     echo $configuration
     echo $testcases
     echo $passed
     echo $failed
     echo $errors
     echo $starttime
     echo $endtime
     
     echo "::set-output name=test_suite_name::$testsuitename"
     echo "::set-output name=configuration::$configuration"
     echo "::set-output name=test_cases::$testcases"
     echo "::set-output name=passed::$passed"
     echo "::set-output name=failed::$failed"
     echo "::set-output name=errors::$errors"
     echo "::set-output name=start_time::$starttime"
     echo "::set-output name=end_time::$endtime"
     #echo "::set-output name=detailed_logs::$detailedlogs"
     #echo "::set-output name=screenshots_and_video::$screenshotsandvideo"
     exit 0
  fi
done
exit

I've published that action on the GitHub Marketplace and I'm trying to use it / test it from another repository like this:

main.yml

name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Run a one-line script
        run: echo Hello, world!
        
      - name: Run Endtest functional tests
        id: endtest_functional_tests
        uses: endtest-technologies/[email protected]
        with:
          app_id: "85205402"
          app_code: "79973826"
          api_request: "https://endtest.io/api.php?action=runTestSuite&appId=85205402&appCode=79973826&testSuite=106877&selectedPlatform=windows&selectedOs=a&selectedBrowser=chrome&selectedResolution=d&selectedLocation=sanfrancisco&selectedCases=491130&writtenAdditionalNotes="
          number_of_loops: 6
          
      - name: Get the test suite name output
        run: echo "${{ steps.endtest_functional_tests.outputs.test_suite_name }}"
        
      - name: Get the configuration output
        run: echo "${{ steps.endtest_functional_tests.outputs.configuration }}"

      
      - name: Get multiple outputs
        run: |
          echo "${{ steps.endtest_functional_tests.outputs.test_suite_name }}"
          echo "${{ steps.endtest_functional_tests.outputs.configuration }}"

Looking at the logs from the build. I can see that my action is successfully called, the API request starts, I can see the output which is printed out until the part with ::set-output.

And the outputs generated by my GitHub action are empty.

build output

I would really appreciate some help on this one, since I've been trying to make it work for the last 2 days.

From what I read, it should be possible to use the ::set-output from a .sh file, like this person did in this article.

1

There are 1 answers

0
riQQ On BEST ANSWER

You're just setting the outputs of the last step of your action but not the action's outputs.

You have to set the value of your action's outputs using the output of the step (as per https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-composite-actions).

name: "Run Endtest functional tests"
description: "Register a deployment event with Endtest and run the functional tests"
branding:
  icon: play-circle
  color: white
inputs:
  [...]
outputs:
  test_suite_name:
    description: "The name of the test suite"
    value: ${{ steps.run-script.outputs.test_suite_name }}
  [...]

runs:
  using: "composite"
  steps:
    - run: sudo apt-get install jq
      shell: bash 
    - run: sudo chmod +x ${{ github.action_path }}/test.sh
      shell: bash 
    - run: echo "${{ inputs.api_request }}"
      shell: bash 
    - run: ${{ github.action_path }}/test.sh ${{ inputs.app_id }} ${{ inputs.app_code }} "${{ inputs.api_request }}" ${{ inputs.number_of_loops }} 
      shell: bash
      id: run-script