Get name of virtual machine type and version inside action

Hi!

I’m exploring creating actions for setting up tooling for my projects. One of the problems I’m facing is needing to know what os and os version the job is running on in order to download correct artifacts etc.

Ideally this should be exposed somewhere but so far I haven’t found any way of figuring this out in an action.

Right now as a workaround, I’m passing the same value that’s passed to jobs.<job_id>.runs-on as an argument to my actions but that isn’t really ideal…

Any suggestions would be greatly apreciated!

You do not need to pass operating system as an input.
You can use process.platform to get the operating system.

console.log(`This platform is ${process.platform}`);

For GitHub Actions you will have to handle 3 cases for process.platform
1)  linux - ubuntu
2) win32 - windows
3) darwin - macOS

The operating system is exposed using the environment variable RUNNER_OS also.

console.log(process.env['RUNNER_OS']) 

Unfortunately that only solves one of the two problems, I still need to get the version of the operating system.

I’ve tried os.release() but that returns “5.0.0-1020-azure” for “ubuntu-18.04”.

My best bet right now seems to be getos (at least for linux) or something similar.