Run cmd command on virtual window machine from within github action

I’m kinda beginner in Github actions. And when it comes to creating action using JavaScript, I’m a total noob.

From my little experience in creating action using Dockerfile, I got to know that if I want my action to be executed/run on Ubuntu machine, I can do that by adding this line in the Dockerfile,

FROM ubuntu:18.04

And I can even configure it to work and include dependencies for my action and I’ll get a configured Ubuntu environment where I can run my desired commands. It’s kinda straight forward.

I thought I could do the same if I require to work on a windows machine but it’s there when I got an error saying something like,

Container is only supported on Linux

I also found types-of-actions where I got to know that if I want to use windows OS, I need to create JavaScript type action and so I followed this article on Creating a JavaScript action .

I tried searching for references where I could get to know more about working on Windows OS using JavaScript action but I found none.

So my question is pretty straight forward here: How can I run any command(in cmd or PowerShell) in windows environment from within my action(and not through the workflow). I’m trying to create some sort of automation which need some commands to be run in cmd on windows platform. Has it to do anything with the GitHub hosted runners?(I’ve no idea about them tho)

Is there any work-around? Any input is highly appreciated. Thanks.

Hi @shashi278 ,

Thank you for being here!

For javascript action, the action.yaml metadata file will check the js file defined(eg: index.js). Hence, if you’d like the action execute command(eg: cmd), you can put below code in index.js:

function exec(cmd, handler = function(error, stdout, stderr){console.log(stdout);if(error !== null){console.log(stderr)}})
  {
      const childfork = require('child_process');
      return childfork.exec(cmd, handler);
  }
  exec('echo test', function(err, stdout){console.log(stdout)});

It will echo test when action is involved.

You can find more details in this link.

All actions will be executed on github runner, there are two types: hosted runner , self-hosted runner.

Thanks.

1 Like

Thanks for your input. It was helpful. And I also found @action/exec, so now I know how to execute commands on windows platform from within an action.

However, I’d like to know the version of OpenGL in the window-latest virtual environment. I tried to find it but couldn’t get that. I’m actually trying to work on something which requires OpenGL version >2.0 and my command reports it to be 1.1. Now since my commands have a tendency to give false-positive results, I’d like to confirm if someone can help here.

Thanks @shashi278 for your reply.

Checked OpenGL is not in the hosted windows runner software list. Looks open GL is provided as a static library which indicated in this link. Did you ever configure it on local client? You can follow the command and try the same on github hosted runner. Or you can directly use local client as a self-hosted runner for your workflow.