Github操作的输出为空

问题描述

我正在创建我的第一个GitHub动作,但我不知道为什么输出为空。

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

我已经在GitHub Marketplace上发布了该操作,我正在尝试使用它/从另一个这样的存储库中对其进行测试:

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/github-run-tests-action@v1.3.0.0.3
        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 }}"

查看构建中的日志。我可以看到我的操作已成功调用,API请求开始,可以看到输出已打印出来,直到带有 :: set-output 的部分为止。

我的Github动作生成的输出为空。

build output

由于我一直在努力使它在过去的2天中一直有效,因此我对此非常感谢。

根据我的阅读,应该可以使用.sh文件中的:: set-output,就像这个人在article中所做的一样。

解决方法

您只是设置操作最后一步的输出,而不是操作的输出。

您必须使用步骤的输出(根据https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-composite-run-steps-actions)设置操作输出的value

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...