This is day 3 of my GitHub Actions Advent Calendar. If you want to see the whole list of tips as they're published, see the index.
One of the nice things about GitHub Actions is that it doesn't just support running builds on Linux hosts, or in containers. GitHub provides Linux virtual machines - of course - but they also provide virtual machines running Windows and macOS.
The macOS virtual environments are especially important, since even as a developer, you can't run macOS in a virtual machine unless you do it on Apple hardware. So if you're building cross-platform applications, that could limit how you can build and test your own application locally.
To specify the host type, you indicate that with the
for a job. For example,
runs-on: macos-latest will run on macOS, and
runs-on: windows-latest will - no surprise - run on Windows. So if
you wanted to build an application by running
make on all three
platforms: Linux, macOS and Windows, you could specify each one as
an individual job. Here's an example:
But this is a lot of repetition… and if you read yesterday's post
about matrix workflows, you
might remember that I said that matrix expansions are really just
simple variable substitution. Well, they are… even in the
That means that you can set up a cross-platform build with a matrix, with just a few lines of a workflow definition:
So you have a choice: you can specify each individual job with the virtual environment that you want to run it on, or if you have common steps, you can run with a matrix.