首页 > 解决方案 > GitHub 操作:运行 if

问题描述

我正在尝试为 GitHub Actions 设置自定义操作,目前这就是我所拥有的:

name: 'Install Dependencies'

inputs:
    os:
        description: 'The OS to fetch the dependencies for'
        required: True
    

runs:
    using: "composite"
    steps:
        - run: echo I am a test
          shell: bash
          if: startsWith(os, 'Linux')

我想要做的是最终拥有一堆不同的 shell 脚本,这些脚本专为特定操作系统完成工作,因此在我的操作中,我想根据os传递给它的参数选择适当的脚本。

当我调用如上所示的操作时,我得到Unexpected value 'if'. run所以我的问题是:如果满足条件,我怎样才能运行执行命令?

标签: github-actions

解决方案


最简单的选择可能是为您的脚本使用命名约定并使用操作系统的名称运行调用它们:

myscript.$(os).sh

推荐阅读