Skip to content

Commit 01b1eaa

Browse files
committed
feat: unfurl presets
1 parent e32d37c commit 01b1eaa

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/github-actions/index.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const _ = require('lodash');
44
const Nv = require('@pkgjs/nv');
5+
const Semver = require('semver');
56

67

78
const internals = {};
@@ -53,6 +54,30 @@ internals.parseActionsSetupNode = function * (workflow, file) {
5354
};
5455

5556

57+
internals.resolveLjharbPreset = function * ({ preset }) {
58+
59+
// @todo: with has more options - resolve to precise versions here and yield the full list
60+
// @todo: return preset as well as resolved version
61+
62+
if (preset === '0.x') {
63+
yield * ['0.8', '0.10', '0.12'];
64+
return;
65+
}
66+
67+
if (preset === 'iojs') {
68+
yield * ['1', '2', '3'];
69+
return;
70+
}
71+
72+
if (!Semver.validRange(preset)) {
73+
yield preset;
74+
return;
75+
}
76+
77+
yield * internals.latestNodeVersions.filter(({ resolved }) => Semver.satisfies(resolved, preset)).map(({ major }) => major);
78+
};
79+
80+
5681
internals.parseLjharbActions = function * (workflow, file) {
5782

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

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

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

131155
exports.detect = async (meta) => {
132156

157+
if (!internals.latestNodeVersions) {
158+
// @todo: unhardcode
159+
const latest = [];
160+
for (const v of ['4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16']) {
161+
const resolved = await Nv(v);
162+
latest.push({ major: v, resolved: resolved[resolved.length - 1].version });
163+
}
164+
165+
internals.latestNodeVersions = latest;
166+
}
167+
133168
const files = await meta.loadFolder('.github/workflows');
134169
const rawSet = new Set();
135170
const byFileSets = {};

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"js-yaml": "^4.0.0",
4545
"minimist": "^1.2.5",
4646
"pacote": "^11.1.0",
47+
"semver": "^7.3.5",
4748
"simple-git": "^2.13.1",
4849
"tmp": "^0.2.0"
4950
}

0 commit comments

Comments
 (0)