GitHub操作的输出为空

4
我正在创建我的第一个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

我真的很感激在这件事上得到一些帮助,因为我已经试图让它工作了两天了。
从我所读的内容来看,应该可以像这个人在这篇文章中所做的那样,从一个.sh文件中使用::set-output。

1
那个庞大的 if ... elif ... else 在长大后想成为一个 case 语句。反复调用 jq 处理小字符串的方式看起来也需要重构,但我无法迅速确定具体的方法。 - tripleee
@tripleee 说得对。那段代码需要进行重构。你有关于为什么 ::set-output 在我的情况下似乎不起作用的任何想法吗? - John Winchester
1个回答

7

您只是在设置操作的最后一步的输出,但没有设置操作的输出。

您需要使用步骤的输出(根据https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-composite-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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接