GitHub Actions子文件夹Composite Action配置报错:缺失shell属性
问题:Composite Action执行报错"Required property is missing: shell"怎么解决?
我在配置Composite Action时,将action.yml放在了仓库的.github/actions/release子文件夹中,然后从另一个仓库调用该Action,使用的Workflow代码如下:
name: "Terraform" on: pull_request: types: [closed] branches: - 'main' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: terraform: name: 'Terraform' runs-on: ubuntu-latest steps: - name: Check out code uses: actions/checkout@v3 - name: checkout composite action uses: actions/checkout@v3 with: repository: ppratheesh/terraform-exercise path: ./github-shared-workflows - name: release action uses: ./github-shared-workflows/.github/actions/release with: RELEASE_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
执行时出现以下报错:
Error: /home/runner/work/terraform-ec2/terraform-ec2/./github-shared-workflows/.github/actions/release/action.yml (Line: 24, Col: 9): Required property is missing: shell Error: /home/runner/work/terraform-ec2/terraform-ec2/./github-shared-workflows/.github/actions/release/action.yml (Line: 28, Col: 9): Required property is missing: shell Error: /home/runner/work/terraform-ec2/terraform-ec2/./github-shared-workflows/.github/actions/release/action.yml (Line: 24, Col: 9): Required property is missing: shell
解决方法
报错的核心原因是Composite Action的action.yml文件中,所有带有run字段的步骤必须显式指定shell属性——这和普通Workflow不同,普通Workflow会自动使用默认shell,但Composite Action没有这个默认值。
你需要修改目标仓库里的.github/actions/release/action.yml文件:
- 定位报错提示的第24、28行对应的
run步骤 - 给每个包含
run命令的步骤添加shell配置(可根据需求选择bash、pwsh等类型)
示例修改:
原步骤(错误写法):
steps: - name: 执行发布脚本 run: | echo "开始构建发布包" # 其他发布逻辑
修改后(正确写法):
steps: - name: 执行发布脚本 run: | echo "开始构建发布包" # 其他发布逻辑 shell: bash
确保所有带run字段的步骤都添加了shell属性,保存后重新运行Workflow即可解决报错。
内容的提问来源于stack exchange,提问作者Pratheesh
相关产品推荐
相关产品推荐

