首页 > 解决方案 > GitHub Workflows 输入参数的下拉列表

问题描述

我想为我的 GitHub 操作输入参数创建一个下拉列表。这应该有助于从下拉列表中选择一个值,就像选择分支的选项一样。

标签: github-actionsgithub-apibuilding-github-actions

解决方案


使用 时workflow_dispatch现在可以choice,booleanenvironment输入,而不仅仅是字符串。choice是一个下拉列表,boolean是一个复选框,environment类似choice但会自动填充在您的存储库设置中配置的所有环境。

这是使用新类型的示例工作流程:

name: CI

on:
  workflow_dispatch:
    inputs:
      environment:
        type: environment
        description: Select the environment
      boolean:
        type: boolean
        description: True or False
      choice:
        type: choice
        description: Make a choice
        options:
        - foo
        - bar
        - baz
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: greet
        run: | 
          echo "environment is ${{ github.event.inputs.environment }}"
          echo "boolean is ${{ github.event.inputs.boolean }}"
          echo "choice is ${{ github.event.inputs.choice }}"

工作流示例


推荐阅读