GitHub Action Job 可以从上一个作业留下的状态继续(没有工件或复杂的过程)吗?

Ale*_* 75 9 github-actions

我之前有一个 GitHub Action,其中有一个 Job 做了 3 件事:

  • 构建 .net 应用程序
  • 运行单元测试
  • 运行集成测试

现在,我将这项工作分成了 3 个不同的部分,因为:

  • 我喜欢尝试
  • 我喜欢看到 GitHub PR 单独更新步骤
  • 我可以/想要并行运行单元测试和集成测试,以便整个过程可以快速完成

这是当前的 GitHub 操作:

name: Pull Request Checks

on: 
  pull_request:
    types: [opened, synchronize, reopened, labeled]
  
jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Buid VS solution
      id: build
      run: dotnet build "FSharp project/MyProject.sln" -c RELEASE

  unit-tests:
    name: Unit Tests
    needs: [build]
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Unit Tests
      id: unit-tests
      run: dotnet test "FSharp project/UnitTests/UnitTests.fsproj" -c Release --no-build --filter "TestCategory!=SKIP_ON_DEPLOY"

  integration-tests:
    name: Integration Tests
    needs: [build]
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Integration Tests
      id: integration-tests
      if: github.event.action == 'labeled' && github.event.label.name == 'pr:ready'
      run: dotnet test "FSharp project/IntegrationTests/IntegrationTests.fsproj" -c Release --no-build --filter "TestCategory!=SKIP_ON_DEPLOY"
Run Code Online (Sandbox Code Playgroud)

理想情况下,集成测试作业仅在 PR 标记为“pr:ready”时运行(这一点可能仍需调整/解决)。

整个过程有效。
我必须在每个作业中重复“结账”步骤,这意味着它们是完全不同的“机器”。
如果这是真的,为什么dotnet testwith--no-build仍然能够工作?
MS 更改了该标志的行为,所以老实说,我不记得此处运行的 dotnet cli 版本是否能够重用可能执行的构建,或者如果需要的话它本身会运行构建。

所以我不完全确定结帐结果在“连续”作业中拥有一个完全新鲜的环境,如果是这种情况......有一种方法可以以简单的方式重用以前的“状态”(就像一个简单的方法)参数,不使用工件和类似的东西)?

小智 2

每个 GitHub actions 作业都在全新的虚拟环境中运行。在作业之间获取数据/文件/等的唯一方法是工件。在您的情况下,解决方案是在构建作业中生成一个工件,然后可以在两个测试作业中并行使用该工件。在结帐操作存储库上查看此问题,询问同样的事情。

因此,您可以将测试所需的所有内容打包到一个工件中,并用下载该工件来替换测试作业中的签出步骤。

至于为什么你的--no-build测试有效,在不知道到底要检查什么的情况下很难回答。