简体   繁体   English

使用自托管运行器在 github 操作中并行运行 lint 和 lint 测试

[英]Run lint and lint tests in parallel in github actions with self hosted runner

I have below pipeline and in this i want to run lint and lint-test in parallel.我有下面的管道,在这里我想并行运行 lint 和 lint-test。 Earlier I had one job with multiple steps but as I checked that if we create different jobs then It can run in parallel.早些时候我有一份工作有多个步骤,但我检查过如果我们创建不同的工作那么它可以并行运行。 I have one runner for this, But still its running one after another.. Here is a piece of code我有一个跑步者,但它仍然一个接一个地跑着。这是一段代码

name: CI
defaults:
  run:
    working-directory: ./
on:
  push:
    tags:
      - v*
  pull_request:
    branches:
      - "**"
env:
  AZURE_REGISTRY_LOGIN_SERVER: ${{ secrets.AZURE_REGISTRY_LOGIN_SERVER }}

jobs:
  build:
    name: 'Setup and Build'
    environment: non-prod
    runs-on: ["self-hosted", "linux", "X64", "myr"]
    outputs:
      version: ${{ steps.setbuildenv.outputs.VERSION }}
      module: ${{ steps.setbuildenv.outputs.MODULE }}

    steps:
    - name: Checkout
      uses: actions/checkout@v1
    - id: setbuildenv
      env:
        GITHUB_SHA: ${{ github.sha }}
        GITHUB_REF: ${{ github.ref }}
        GITHUB_REPO: ${{ github.repository }}
      run: |
        MODULE=$(echo -n ${GITHUB_REPO} | sed -e 's/.*\///')
        if [[ $GITHUB_REF =~ refs/tags ]]; then
          VERSION=$(echo -n ${GITHUB_REF} | sed -e 's/refs\/tags\///')
        else
          VERSION=${GITHUB_SHA:0:7}
        fi
        echo "VERSION=${VERSION}" >> $GITHUB_ENV
        echo "::set-output name=VERSION::${VERSION}"
        echo "MODULE=${MODULE}" >> $GITHUB_ENV
        echo "::set-output name=MODULE::${MODULE}"
    - name: Build
      env:
        GIT_TOKEN: ${{ secrets.PAT }}
      run: |
        docker build -t ${{ env.AZURE_REGISTRY_LOGIN_SERVER }}/${MODULE}:${VERSION} --build-arg GIT_TOKEN="${GIT_TOKEN}" -f container/smpl/Dockerfile .
        docker build -t ${{ env.AZURE_REGISTRY_LOGIN_SERVER }}/${MODULE}-tools:${VERSION} -f container/smpl/Dockerfile .
  lint:
    name: 'Lint'
    needs: build
    environment: non-prod
    runs-on: ["self-hosted", "linux", "X64", "myr"]
    steps:
    - name: Lint
      run: |
        docker run --rm ${{ env.AZURE_REGISTRY_LOGIN_SERVER }}/${{ needs.build.outputs.module }}:${{ needs.build.outputs.version }} make lint
  lint-tests:
    name: 'Lint tests'
    needs: build
    environment: non-prod
    runs-on: ["self-hosted", "linux", "X64", "myr"]
    steps:
    - name: Lint Tests
      run: |
          docker run --rm ${{ env.AZURE_REGISTRY_LOGIN_SERVER }}/${{ needs.build.outputs.module }}:${{ needs.build.outputs.version }} make lint-tests
.
.
.
.
.
.

  cleanup:
    name: 'Run Cleanup'
    needs: push
    environment: non-prod
    runs-on: ["self-hosted", "linux", "X64", "myr"]
    steps:
    - name: Cleanup
      run: |
        docker rmi ${{ env.AZURE_REGISTRY_LOGIN_SERVER }}/${{ needs.build.outputs.module }}:${{ needs.build.outputs.version }}
        docker rmi ${{ env.AZURE_REGISTRY_LOGIN_SERVER }}/${{ needs.build.outputs.module }}-tools:${{ needs.build.outputs.version }}

Attaching image of how it looks like附上它的外观图片

在此处输入图像描述

How can I use self hosted runners for parallel execution of lint and lint-tests?如何使用自托管运行器并行执行 lint 和 lint 测试?

One GitHub runner can only run one job at the time.一个 GitHub runner 一次只能运行一个job。 Therefore, you would need to run multiple runners fulfilling the runs-on requirements of the parallel jobs.因此,您需要运行多个运行器runs-on要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM