跨作业重用部分 github 操作 [英] Reuse portion of github action across jobs

查看:9
本文介绍了跨作业重用部分 github 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 monorepo 中有一个 CI 工作流,对于这个工作流,最终会构建两个项目.作业运行良好,但是,我想知道是否有办法通过设置作业的运行器来删除此 workflow.yml 文件中的重复项.我将它们分开,以便它们并行运行,因为它们不相互依赖并且可以更快地完成.等待 CI 完成时,5 分钟与 10 分钟以上的时间差很大.

I have a workflow for CI in a monorepo, for this workflow two projects end up being built. The jobs run fine, however, I'm wondering if there is a way to remove the duplication in this workflow.yml file with the setting up of the runner for the job. I have them split so they run in parallel as they do not rely on one another and to be faster to complete. It's a big time difference in 5 minutes vs. 10+ when waiting for the CI to finish.

jobs:
  job1:
    name: PT.W Build
    runs-on: macos-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v1

      - name: Setup SSH-Agent
        uses: webfactory/ssh-agent@v0.2.0
        with:
          ssh-private-key: |
            ${{ secrets.SSH_PRIVATE_KEY }}

      - name: Setup JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

      - name: Setup Permobil-Client
        run: |
          echo no | npm i -g nativescript
          tns usage-reporting disable
          tns error-reporting disable
          npm run setup.all

      - name: Build PT.W Android
        run: |
          cd apps/wear/pushtracker
          tns build android --env.uglify

  job2:
    name: SD.W Build
    runs-on: macos-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v1

      - name: Setup SSH-Agent
        uses: webfactory/ssh-agent@v0.2.0
        with:
          ssh-private-key: |
            ${{ secrets.SSH_PRIVATE_KEY }}

      - name: Setup JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

      - name: Setup Permobil-Client
        run: |
          echo no | npm i -g nativescript
          tns usage-reporting disable
          tns error-reporting disable
          npm run setup.all

      - name: Build SD.W Android
        run: |
          cd apps/wear/smartdrive
          tns build android --env.uglify

您可以在此处看到这些作业的流程几乎相同,只是构建不同的应用程序本身.我想知道是否有一种方法可以在作业中获取重复的块并创建一种只编写一次并在两个作业中重用它的方法.

You can see here the jobs have almost an identical process, it's just the building of the different apps themselves. I'm wondering if there is a way to take the duplicate blocks in the jobs and create a way to only write that once and reuse it in both jobs.

推荐答案

据我所知,目前没有办法重用步骤
但在这种情况下,您可以使用 strategy 进行并行构建和不同的变体:

As I know currently there is no way to reuse steps
but in this case, you can use strategy for parallel build and different variation:

jobs:
  build:
    name: Build
    runs-on: macos-latest
    strategy:
      matrix:
        build-dir: ['apps/wear/pushtracker', 'apps/wear/smartdrive']
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v1

      - name: Setup SSH-Agent
        uses: webfactory/ssh-agent@v0.2.0
        with:
          ssh-private-key: |
            ${{ secrets.SSH_PRIVATE_KEY }}

      - name: Setup JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8

      - name: Setup Permobil-Client
        run: |
          echo no | npm i -g nativescript
          tns usage-reporting disable
          tns error-reporting disable
          npm run setup.all

      - name: Build Android
        run: |
          cd ${{ matrix.build-dir }}
          tns build android --env.uglify

更多信息请访问 https:///help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategy

这篇关于跨作业重用部分 github 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆