Repository navigation
Support parsing node versions from Github Actions #4
Description
Activity
A node version can be defined in any of the
.github/workflows/*.ymlfiles:- In the matrix (it seems people use
node-versionandnodekeys for that) - Inside
uses: with:(whenuses: setup-node@v1, thewithwill containnode-version, which can either be a static value or an item from thematrix) - Some people install node using
nvs, rather thansetup-node(e.g. https://github.com/mishoo/UglifyJS2/blob/master/.github/workflows/ci.yml)
- In the matrix (it seems people use
Since this is the one I am most interested in, I will post a link to the basic setup I am doing:
https://github.com/pkgjs/support/blob/master/.github/workflows/test.yml
As you say, this follows the pattern of using
node-version, but that is just an arbitrary key coppied from their examples. A user can change that to anything. So, the best way to robustly do this is to read the lines here https://github.com/wesleytodd/create-package-json/blob/master/.github/workflows/test.yml#L17-L18.If you look for
jobs.[job].steps[step].uses.startsWith('actions/setup-node'), then in that look at.with.node-version, then parse the double curly brace expression we should be able to look up the key in thematrixblock.I think this will be brittle, but I am not sure we can do better with the power which GitHub Actions gives. I am going to ping in @bdougieYO from GH to see if maybe someone from their side can give us a better way to do this. @bdougieYO any help (or hook us up with someone who can) would be appreciated!
I would lean towards what you are describing @wesleytodd.
But if I had the bandwidth, I would explore updating the https://github.com/actions/setup-node to provide a $NODE_VERSION env. That way you wouldn't have to guess or need to lean on a deeply nested check.
I am not sure if that would get approved and merged, but it would be worth opening up this discussion/issue in that repo.
Reacted by Wes Todd$NODE_VERSION env
This would only be available when the action is running?
The tool I'm building is to generate the stats about what people are using in their test setup - so I suspect I'll do what @wesleytodd proposes for now, and I'll see where that takes me after I actually collect some data.
Reacted by Wes Todd