Skip to content

Read node versions from Github workflows #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: unfurl presets
  • Loading branch information
dominykas committed Jan 31, 2022
commit b36c63ac1beaed7536b147061e9834387cfecb48
39 changes: 37 additions & 2 deletions lib/github-actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const _ = require('lodash');
const Nv = require('@pkgjs/nv');
const Semver = require('semver');


const internals = {};
Expand Down Expand Up @@ -53,6 +54,30 @@ internals.parseActionsSetupNode = function * (workflow, file) {
};


internals.resolveLjharbPreset = function * ({ preset }) {

// @todo: with has more options - resolve to precise versions here and yield the full list
// @todo: return preset as well as resolved version

if (preset === '0.x') {
yield * ['0.8', '0.10', '0.12'];
return;
}

if (preset === 'iojs') {
yield * ['1', '2', '3'];
return;
}

if (!Semver.validRange(preset)) {
yield preset;
return;
}

yield * internals.latestNodeVersions.filter(({ resolved }) => Semver.satisfies(resolved, preset)).map(({ major }) => major);
};


internals.parseLjharbActions = function * (workflow, file) {

for (const job of Object.values(workflow.jobs)) {
Expand Down Expand Up @@ -114,8 +139,7 @@ internals.parseLjharbActions = function * (workflow, file) {
throw new Error(`Unrecognized action in ${needOutput} in ${file}`);
}

// @todo: with has more options - resolve to precise versions here and yield the full list
yield needStep.with.preset;
yield * internals.resolveLjharbPreset(needStep.with);
continue;
}

Expand All @@ -130,6 +154,17 @@ internals.parseLjharbActions = function * (workflow, file) {

exports.detect = async (meta) => {

if (!internals.latestNodeVersions) {
// @todo: unhardcode
const latest = [];
for (const v of ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']) {
const resolved = await Nv(v);
latest.push({ major: v, resolved: resolved[resolved.length - 1].version });
}

internals.latestNodeVersions = latest;
}

const files = await meta.loadFolder('.github/workflows');
const rawSet = new Set();
const byFileSets = {};
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"lodash": "^4.17.21",
"minimist": "^1.2.5",
"pacote": "^12.0.0",
"semver": "^7.3.5",
"simple-git": "^3.0.0",
"tmp": "^0.2.0"
}
Expand Down