有什么方法可以在单个运行器中运行多个作业或在作业之间共享 Github actions 工作区?
在我的组织中,开发团队使用由多个团队创建和管理的多个可重用工作流程。团队
build
创建并管理构建应用程序的 build.yaml
。我的团队创建并管理 analysis.yaml
,对应用程序构建进行数据分析并归档构建的工件。
开发团队计划在他们的应用程序工作流程中使用我们的两个工作流程。为了使我的团队的工作流程正常工作,我的工作流程需要访问构建的代码(
target
构建的maven
目录、build
构建的gradle
目录和node_modules
构建的npm
目录)。
upload
操作和 cache
操作)。是否有其他方法可以完成此任务并在构建运行程序本身上运行可重用工作流程?我有以下例子。
build.yaml
on:
workflow_call
inputs:
build:
description: Build type
required: true
jobs:
Build:
runs-on: self-hosted
steps:
- name: Building apps
- if: ${{inputs.build=='gradle'}}
run: |
gradle build
analysis.yaml
on:
workflow_call
inputs:
analysis:
description: Build type
required: true
type: boolean
jobs:
Build:
runs-on: self-hosted
steps:
- name: Building apps
- if: ${{inputs.analysis}}
run: |
#Run ML build analysis
#Archive the build artifacts
workflow.yaml
on:
push:
branches: [main]
jobs:
Build:
uses: buildteam/.github/workflows/build.yaml@main
with:
build: gradle
Analysis:
uses: analysis/.github/workflows/analysis.yaml@main
with:
analysis: true
您可以获取第一个作业的运行程序并将其作为输出传递给以下作业。
name: main
on:
push: { branches: [main] }
jobs:
get-runner:
name get a runner to use for this workflow
if: ${{ always() }}
runs-on: custom-runner
outputs:
RUNNER: ${{ runner.name }}
steps:
- run: echo "selected runner = ${{ runner.name }}"
other-job:
name: another job
needs: get-runner
runs-on: ${{needs.get-runner.outputs.RUNNER}}
steps:
...
限制:
不,据我所知,至少目前不可能在工作之间共享工作空间。
有没有办法在运行器上运行我的可重用工作流程 代码已构建?
有没有办法可以访问代码所在的工作区 建立(我搜索了其他答案并了解到我可以使用上传 操作和缓存操作)。还有其他方法可以实现此目的吗 并在构建运行器本身上运行我的可重用工作流程?
您可以通过使用独特的跑步者标签来强制执行此操作。通过在跑步者上定义唯一标签,您可以在两个作业中使用
runs-on
引用该跑步者
我会通过复合动作而不是更好地完成这个任务吗? 使用可重复使用的工作流程?
这更多是基于意见的问题,但无论如何我都会回答。是的,我绝对认为在这种情况下复合操作将是更好的解决方案,特别是因为
build
和 analysis
工作流程看起来都很简单并且不使用秘密。但您应该检查文档以了解两者之间的差异,有一些限制。