如何在一个 repo 中合并两个 action.yml 文件?

ben*_*gis 6 github-actions

我希望我的 repo 有两个功能:

  1. 在标签推送上创建发布
  2. 在 docker 环境中测试我的软件

两者都需要 repo 中的 action.yml。我如何组合它们?

name: "Upload a Release Asset"
description: "Upload a release asset to an existing release on your repository"
author: "Github"
inputs:
  upload_url:
    description: "The URL for uploading assets to the release"
    required: true
  asset_path:
    description: "The path to the asset you want to upload"
    required: true
  asset_name:
    description: "The name of the asset you want to upload"
    required: true
  asset_content_type:
    description: "The content-type of the asset you want to upload. See the supported Media Types here: https://www.iana.org/assignments/media-types/media-types.xhtml for more information"
    required: true
outputs:
  browser_download_url:
    description: "The URL users can navigate to in order to download the uploaded asset"
runs:
  using: "node12"
  main: "dist/index.js"
branding:
  icon: "package"
  color: "gray-dark"
Run Code Online (Sandbox Code Playgroud)
name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  time: # id of output
    description: 'The time we greeted you'
runs:
  using: 'docker'
  image: 'Dockerfile'
  args:
    - ${{ inputs.who-to-greet }}
Run Code Online (Sandbox Code Playgroud)

Mic*_*l J 15

@成和潘!如果您想在同一个存储库中有两个操作,它们应该位于不同的目录中。

但是,该action.yml文件不是必需的。

如果您计划在 GitHub Marketplace 中列出某个操作,则该文件仅需要该文件。

如果您在同一个 repo 中有这些操作,则它们可以拥有自己的action.yml文件以及它们的 Dockerfile 或节点脚本。这是一个包含两个 dockerfile 的示例:

.
??? README.md
??? .github
?   ??? workflows
?       ??? main.yml
??? action1
?   ??? Dockerfile
?   ??? action.yml
?   ??? entrypoint.sh
??? action2
    ??? Dockerfile
    ??? action.yml
    ??? entrypoint.sh
Run Code Online (Sandbox Code Playgroud)

这是同一个 repo 中的一个工作流,调用同一个 repo 中的两个操作:

name: Test two actions
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: ./action1
      - uses: ./action2
Run Code Online (Sandbox Code Playgroud)

这是另一个调用操作的存储库中的工作流:

name: Test two actions
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: managedkaos/github-actions-two-actions/action1@master
      - uses: managedkaos/github-actions-two-actions/action2@master
Run Code Online (Sandbox Code Playgroud)

如果您不同意在 GitHub Marketplace 中列出操作,只需将action.yml文件放在与操作相同的目录中,就可以了!

作为参考,您可以在此处找到这些示例中的代码:

  1. https://github.com/managedkaos/github-actions-two-actions
  2. https://github.com/managedkaos/test-two-actions


Von*_*onC 6

两者都需要 repo 中的 action.yml。我如何组合它们?

您可以将每个操作保留在各自独立的 GitHub 操作存储库中。

并且,自 2020 年 8 月起,将它们结合起来

看:

GitHub 操作:复合运行步骤

您现在可以使用 shell 脚本创建可重用的操作,甚至可以在同一个操作中混合使用多种 shell 语言。
您可能有很多 shell 脚本来自动化许多任务,现在您可以轻松地将它们转换为一个动作并在不同的工作流中重复使用它们。有时,编写一个 shell 脚本比 JavaScript 或 Docker 更容易。
现在您不必担心将脚本包装在 Docker 容器中。

以下是如何使用复合运行步骤操作的示例:

复合运行步骤示例——https://i2.wp.com/user-images.githubusercontent.com/8660827/89449714-7bdd0480-d727-11ea-9863-7486fe666fd5.png?ssl=1

工作流.yml:

jobs:
 build:
   runs-on: windows-latest
   steps:
   - uses: actions/checkout@v2
   - uses: octocat/say-hello@v1
     with: 
       name: OctoCat
Run Code Online (Sandbox Code Playgroud)

octocat/say-hello/action.yml:

inputs:
 name: 
   description: 'Your name'
   default: 'No name provided'
runs:
 using: "composite"
 steps: 
   - run: echo Hello ${{ inputs.name }}.
     shell: bash
   - run: echo "Nice to meet you!"
     shell: pwsh
Run Code Online (Sandbox Code Playgroud)

了解有关复合运行步骤的更多信息,并访问GitHub Actions 社区论坛以获取问题。