GitHub action 中如何获取输入参数值?

2021-06-13 23:44:36 +08:00
 alanhe421
name: 'Repo Star Count'
description: 'Get count of Github repository stars'
inputs:
  repoPath:
    description: 'Repository Path'
    required: false
    default: ${{github.repository}}
outputs:
  stars:
    description: "Repo Stars"
    value: ${{ steps.repo-stars.outputs.stars }}
runs:
  using: composite
  steps:
    - id: repo-stars
      run: |
        STARS=`curl -s 'https://api.github.com/repos/${{env.INPUT_REPOPATH}}?page=$i&per_page=100' | jq .stargazers_count`
        echo "::set-output name=stars::$STARS"
      shell: bash
branding:
  icon: 'award'
  color: 'green'

代码如上,获取的 INPUT_REPOPATH 为空,按照官网所说为环境变量-INPUT_参数名字进行获取,但是却没拿到,姿势不对?

1580 次点击
所在节点    程序员
2 条回复
alanhe421
2021-06-13 23:56:08 +08:00
解决了,但是按照官方的说法没有解决,说的是 env 也可以取到。。BUT,不行。

${{ inputs.repoPath }} 可以取到值。
Rhilip
2021-06-14 09:54:37 +08:00
应该是不用写 env. 这个 prefix 的,直接 "$INPUT_FOO" 这种写法,
因为 ${{ env.foo }} 这种写法是给挂在 envs: 下面的变量准备的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/783260

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX