Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a job on every runner in GitHub Actions

For those that are familiar with Github Actions...

At present, when a job runs, it picks the most suitable runner for the job based on labels and repository (Using self-hosted runners in a workflow - GitHub Docs). My question is whether it is possible to run a single job on every runner that’s meets the requirements of a job.

For example, I have multiple runners, both self-hosted and hosted by Github; I have a job that contains a script that does the following when code is pushed to the repo:

  • Checks out the Git repo using actions/checkout@v2
  • Copies a file from the checked out repo to a user’s home directory

This “action” needs to take place on every runner that the action has access to.

I hope this makes sense!

like image 502
wegotoeleven Avatar asked Jan 21 '21 18:01

wegotoeleven


People also ask

Do jobs run sequentially GitHub Actions?

A workflow run is made up of one or more jobs , which run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using the jobs.

How do you run multiple self-hosted runners on a single host?

To install multiple self-hosted runner on your host, you should use different workdir and different runner name. The registration token can be identical( or you can rerun the api command to get a new one).

How do I use self-hosted runners in GitHub Actions?

Communication between self-hosted runners and GitHubThe application must be running on the machine to accept and run GitHub Actions jobs. Since the self-hosted runner opens a connection to GitHub.com, you do not need to allow GitHub to make inbound connections to your self-hosted runner.

What is a job in GitHub actions?

This may include tasks like building separate portions of a site, running tests on multiple versions, etc. To do all of this, GitHub Actions has the concept of jobs to run a series of actions and commands within a self-contained environment. To start, Let's run a linter & tests for a hypothetical node library at the same time.

How to force a runner to run on multiple jobs?

You could force that by using unique runner labels. By defining unique label on a runner you can then reference that runner in both jobs with runs-on Will I accomplish this better with a composite action rather than using a reusable workflow?

How do I run a cron job on GitHub actions?

You can use GitHub Actions as a way to run a cron job script, which they’ll run for you for free (as long as you stay within the monthly limits ). Let’s say I’m creating a GitHub Action that runs a Node.js script on a schedule. I’ll call the Action “Scheduled Job”, but you can call it whatever you’d like.

How do I run multiple jobs at the same time?

Use workflows to run multiple jobs. A workflow run is made up of one or more jobs, which run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using the jobs.<job_id>.needs keyword. Each job runs in a runner environment specified by runs-on.


1 Answers

According to official documentation you should use strategy option in your job, where you can define on which machine you want your job to run.

Although I didn't find specific use-case for combining github and self-hosted runners, I'd try something like this:

strategy:
  matrix:
    os: [ubuntu-18.04, ubuntu-20.04, self-hosted]
runs-on: ${{ matrix.os }}
steps:
  - uses: actions/checkout@v2
like image 102
Ondřej Tůma Avatar answered Oct 23 '22 06:10

Ondřej Tůma