GitHub 操作:缺少必需的属性:shell

问题描述 投票:0回答:3

简介

我目前正在创建一个复合 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/[email protected]' (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/[email protected]
    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/[email protected]
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          javadoc-branch: javadoc
          java-version: 17

问题

有人有办法解决这个问题吗?

java maven github-actions javadoc building-github-actions
3个回答
68
投票

使用复合操作时,必须指定 shell。

由于您没有在复合操作中指定跑步者类型,因此您需要为每个操作指定 shell。

就你的情况来说,问题出在这一步,你需要在这里添加

shell: bash

- name: Generate Javadoc
  shell: bash
  run: mvn org.apache.maven.plugins:maven-javadoc-plugin:3.3.1:aggregate

文档:https://docs.github.com/en/actions/creating-actions/creating-a-composite-action#creating-an-action-metadata-file


4
投票

将其放在这里是为了帮助像我这样的其他菜鸟,因为对实际答案的评论太长了。

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

现在,如果像我一样,您在创建的操作中省略了 shell 属性,您将收到“缺少必需的属性:shell” 如果像我一样,您已经在整个 action.yaml 中添加“shell: bash”几个小时了,想知道为什么它仍然损坏,那是因为您仍在工作流程文件中指定 @v1,这当然是引用提交/version 在您尝试修复操作之前进行的多次提交。

因此,请确保在工作流程文件中指定@master/main/..


0
投票

我提出了这个问题,但我的错误是

No event triggers defined in "on"

我的目的是进行一个小操作,在我自己的存储库上运行节点设置 + npm install 并进行缓存。

复合操作不应位于

.github/workflows/
文件夹中,否则它们会将其视为工作流程。有点明显,但并不完全直观😅

© www.soinside.com 2019 - 2024. All rights reserved.