Skip to content

Commit 0a61113

Browse files
committed
feat: add smart get-node-version
1 parent 5922921 commit 0a61113

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

.github/actions/build-node-python/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ runs:
9595
using: "composite"
9696
steps:
9797
# Node
98+
- uses: ./tmp/github-workflows/.github/actions/get-node-version
99+
if: inputs.enable_node == 'true'
100+
id: get-node-version
101+
98102
- name: Set up node version
99103
uses: actions/setup-node@v4
100104
if: inputs.enable_node == 'true'
101105
with:
102-
node-version: ${{ inputs.node_version }}
106+
# TODO: Revert the two
107+
node-version: ${{ steps.get-node-version.outputs.node_version || inputs.node_version }}
103108
registry-url: ${{ inputs.npm_registry }}
104109
- name: Show node and npm version
105110
if: inputs.enable_node == 'true'
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: get-node-version
2+
description: extracts the node version from the package.json engines
3+
author: datavisyn
4+
5+
outputs:
6+
node_version:
7+
description: "extracted node version"
8+
value: ${{ steps.get-node-version.outputs.result }}
9+
10+
runs:
11+
using: "composite"
12+
steps:
13+
- name: Find version script
14+
id: get-node-version
15+
uses: actions/github-script@v7
16+
with:
17+
script: |
18+
const path = require('path');
19+
const fs = require('fs');
20+
21+
// Load the sandboxed semver dependency from the action's own node_modules
22+
const semver = require(path.join(process.env.GITHUB_ACTION_PATH, 'node_modules/semver'));
23+
24+
// ✅ Define your extendable array of versions to check
25+
const versionsToCheck = ['24.10', '20.9', '18.17.0'];
26+
27+
const packageJsonPath = path.join(process.env.GITHUB_WORKSPACE, 'package.json');
28+
if (!fs.existsSync(packageJsonPath)) {
29+
core.setFailed(`Error: package.json not found at ${packageJsonPath}`);
30+
return;
31+
}
32+
33+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
34+
const requiredRange = packageJson.engines?.node;
35+
36+
if (!requiredRange) {
37+
core.info('No node engine requirement in package.json. Returning empty.');
38+
return '';
39+
}
40+
41+
core.info(`Required Node.js range: ${requiredRange}`);
42+
43+
for (const version of versionsToCheck) {
44+
if (semver.satisfies(version, requiredRange)) {
45+
core.info(`\n✅ Match found! Returning version ${version}.`);
46+
// Simply return the matching version string to set the 'result' output
47+
return version;
48+
}
49+
}
50+
51+
core.setFailed(`\n❌ No compatible Node.js version found in the list for range "${requiredRange}".`);

.github/workflows/build-node-python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ env:
119119
PYPI_REGISTRY: "https://upload.pypi.org/legacy/"
120120
PYPI_USERNAME: "datavisyn"
121121
PYTHON_VERSION: ${{ vars.PYTHON_VERSION || '3.10' }}
122-
WORKFLOW_BRANCH: "main"
122+
WORKFLOW_BRANCH: "mp/node_version"
123123
POSTGRES_HOSTNAME: postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}
124124

125125
permissions:

0 commit comments

Comments
 (0)