如何在 GitHub 动作作业中创建下拉菜单

How to create a dropdown in a GitHub action job

我的作业需要接收来自用户的 2 个输入参数。 这些参数的有效值由单独的脚本定义。这些值可以更改(无法对它们进行硬编码)所以我想在作业为 运行 时动态填充列表。选择器应根据允许用户 select 的脚本结果进行更新,然后实际作业才应 运行 并将这些值作为作业的输入

问题是如何提供这样的下拉菜单

自 2021 年 11 月起,input 类型实际上可以是 choice 列表。

GitHub Actions: Input types for manual workflows

You can now specify input types for manually triggered workflows allowing you to provide a better experience to users of your workflow.
In addition to the default string type, we now support choice, boolean, and environment.

name: Mixed inputs

on:
  workflow_dispatch:
    inputs:
      name:
        type: choice
        description: Who to greet
        options: 
        - monalisa
        - cschleiden
      message:
        required: true
      use-emoji:
        type: boolean
        description: Include  emojis
      environment:
        type: environment

jobs:
  greet:
    runs-on: ubuntu-latest

    steps:
    - name: Send greeting
      run: echo "${{ github.event.inputs.message }} ${{ fromJSON('["", ""]')[github.event.inputs.use-emoji == 'true'] }} ${{ github.event.inputs.name }}"

这将提供一个下拉菜单。

问题仍然存在:您能否将选项列表作为变量传递给您的 input choice 字段?

你应该,如果你能填充 inputs context, through another job (computing your list), and calling your choice job, passing the list through jobs.<job_id>.with / jobs.<job_id>.with.<input_id>