GitHub Actions:必需属性缺失:shell。

28

介绍

我目前正在创建一个复合 GitHub Actions,用于构建Java项目的JavaDoc,并自动将其发布到GitHub Page上的静态页面。

问题

但是当我尝试运行时,我遇到了这个错误:

Current runner version: '2.287.1'
Operating System
Virtual Environment
Virtual Environment Provisioner
GITHUB_TOKEN Permissions
Secret source: Actions
Prepare workflow directory
Prepare all required actions
Getting action download info
Download action repository 'MathieuSoysal/Javadoc-publisher.yml@v2.0.2' (SHA:878c07f835dd9bcbb8800090d109c91b0f0d4581)
Error: MathieuSoysal/Javadoc-publisher.yml/v2.0.2/action.yml (Line: 29, Col: 5): Required property is missing: shell
Error: MathieuSoysal/Javadoc-publisher.yml/v2.0.2/action.yml (Line: 29, Col: 5): Required property is missing: shell
Error: GitHub.DistributedTask.ObjectTemplating.TemplateValidationException: The template is not valid. MathieuSoysal/Javadoc-publisher.yml/v2.0.2/action.yml (Line: 29, Col: 5): Required property is missing: shell
   at GitHub.DistributedTask.ObjectTemplating.TemplateValidationErrors.Check()
   at GitHub.Runner.Worker.ActionManifestManager.ConvertRuns(IExecutionContext executionContext, TemplateContext templateContext, TemplateToken inputsToken, String fileRelativePath, MappingToken outputs)
   at GitHub.Runner.Worker.ActionManifestManager.Load(IExecutionContext executionContext, String manifestFile)
Error: Fail to load MathieuSoysal/Javadoc-publisher.yml/v2.0.2/action.yml

受影响的代码:

name: Deploy Javadoc
description: 'Automatically  generate your Javadoc from your maven project and deploy it with GitHub Page on javadoc branch.'
branding:
  icon: 'book-open'
  color: 'white'
inputs:
  java-version:  # version of java
    description: 'Java version inside your project'
    required: true
    default: '17'
  GITHUB_TOKEN: # GitHub Token
    description: 'The GitHub token the GitHub repository'
    required: true
  javadoc-branch: # branch where the javadoc is hosted
    description: 'Branch where the javadoc is hosted'
    required: true
    default: javadoc
 
runs:
  using: "composite"
  steps:
  - uses: actions/checkout@v2
    with:
      fetch-depth: 0
  - uses: actions/setup-java@v2
    with:
      java-version: ${{ inputs.java-version }}
      distribution: 'adopt'
  - name: Generate Javadoc
    run: mvn org.apache.maven.plugins:maven-javadoc-plugin:3.3.1:aggregate
  - name: Deploy 
    uses: JamesIves/github-pages-deploy-action@4.1.8
    with:
      GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
      BRANCH: ${{ inputs.javadoc-branch }}
      CLEAN: true
      FOLDER: target/site/apidocs
      TARGET_FOLDER: javadoc

执行这些 GitHub Actions 的代码:

name: Deploy Javadoc

on:
  push:
    branches:
      - master

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - name: Deploy JavaDoc 
        uses: MathieuSoysal/Javadoc-publisher.yml@v2.0.3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          javadoc-branch: javadoc
          java-version: 17

问题

有人有解决这个问题的想法吗?

2个回答

46

1
这方面有什么资料可以参考吗? - chantey
2
@chantey https://docs.github.com/zh/actions/creating-actions/creating-a-composite-action#creating-an-action-metadata-file - Grzegorz Krukowski
2
@GrzegorzKrukowski 这个链接没有解释为什么。不幸的是,我发现 Github Actions 的文档总体上都比较缺乏。 - Gustavo Puma
1
@GustavoPuma,你说得对,我会在我的回答中更新“WHY”,因为文档中没有它。 - Grzegorz Krukowski
1
谢谢。我理解工作流程总是需要定义一个运行器类型。您是否知道为什么复合操作不能简单地使用调用者中指定的内容? - Gustavo Puma

1

我把这个放在这里是为了帮助像我一样的新手,因为它太长了,不能作为实际答案的评论。

如果你大致按照https://docs.github.com/en/actions/creating-actions/creating-a-composite-action(其中没有明确告诉你需要 shell 属性)创建你的操作,它会告诉你使用 v1 标记提交,然后在你尝试使用该操作的工作流中指定 @v1

现在,如果像我一样,在创建操作时省略了 shell 属性,你将会收到“缺少必需属性:shell”的错误提示。 如果像我一样,在 action.yaml 文件中添加了“shell: bash”几个小时,仍然不知道为什么它还是无法正常工作,那是因为你仍然在工作流文件中指定 @v1,当然这是引用了在你尝试修复操作之前的许多提交/版本。

所以,请确保在你的工作流文件中指定 @master/main/。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接