Git workflow to run in the same runner in the group for multiple yml files

  Kiến thức lập trình

I have two workflow yml files codeql.yml and snyk.yml file

codeql.yml

# Define the name of the workflow
name: "CodeQL-Advanced"

# Define when the workflow should be triggered (on push to a specific branch and pull requests to the master branch)
on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

# Define the jobs that will be executed as part of the workflow
jobs:
  analyze:
    name: Analyze
    runs-on:
      group: my-self-host-internal-runners
    timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
    permissions:
      security-events: write
      actions: read
      contents: read

snyk-zap.yml

# Define the name of the workflow
name: snyk-zap

# Define when the workflow should be triggered (on push to a specific branch and pull requests to the master branch)
on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]
  workflow_dispatch:

# Define the jobs that will be executed as part of the workflow 
jobs:
  # Job to build and push the ZAP Docker image to Docker Hub
  Snyk-Docker-Image:
    runs-on:
      group: my-self-host-internal-runners
    permissions:
      actions: read
      contents: read
      security-events: write
      issues: write

   ZAP-Docker-Scan:
    needs: Snyk-Docker-Image
    runs-on:
      group: my-self-host-internal-runners
    permissions:
      actions: read
      contents: read
      security-events: write
      issues: write

I added group name as my-self-host-internal-runners so that the workflow can run on whichever runner that is free in the group my-self-host-internal-runners. But I want bother .yml files to run on the same runner once one of the .yml files picks up the idle runner in the group. Is there a way to achieve this? I don’t want to mention the specific runner name as there are multiple workflows that could be running and the runner won’t be free. Also, I don’t want both .yml files in a single file as well.

LEAVE A COMMENT