Run lint and lint tests in parallel in github actions with self hosted runner
Asked Answered
M

1

0

I have below pipeline and in this i want to run lint and lint-test in parallel. 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

enter image description here

How can I use self hosted runners for parallel execution of lint and lint-tests?

Mousey answered 15/3, 2022 at 5:52 Comment(0)
S
2

One GitHub runner can only run one job at the time. Therefore, you would need to run multiple runners fulfilling the runs-on requirements of the parallel jobs.

Sse answered 15/3, 2022 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.