Skip to content

Commit 133076a

Browse files
authored
feat: add get-node-version and cleanup env variables (#230)
* feat: add smart get-node-version * Cleanup env variables * Cleanup pypi_registry
1 parent 5922921 commit 133076a

File tree

9 files changed

+120
-91
lines changed

9 files changed

+120
-91
lines changed

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

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,28 @@ inputs:
99
required: true
1010
run_parallel:
1111
description: "enables parallel running of node and python tasks"
12-
default: true
12+
default: "true"
1313
required: true
1414
# Node
1515
enable_node:
1616
description: "enables the node part of the action"
17-
default: true
17+
default: "true"
1818
required: true
1919
node_version:
2020
description: "node version to use"
21-
default: "20.9"
22-
required: true
21+
default: ""
22+
required: false
2323
npm_registry:
2424
description: "npm registry"
25-
default: "https://registry.npmjs.org/"
26-
required: true
25+
required: false
2726
enable_node_cache:
2827
description: "enables the yarn cache download and upload"
2928
required: false
30-
default: true
29+
default: "true"
3130
download_yarn_lock:
3231
description: "downloads the node-yarn-lock artifact (only available when build-node was called before)"
3332
required: false
34-
default: false
33+
default: "false"
3534
upload_yarn_lock:
3635
description: "name of the artifact to upload the node-yarn-lock artifact"
3736
required: false
@@ -41,66 +40,76 @@ inputs:
4140
required: false
4241
default: ''
4342
run_node_lint:
44-
default: true
43+
description: "run node lint"
44+
default: "true"
4545
required: false
4646
run_playwright_browser_install:
47-
default: false
47+
description: "run playwright browser install"
48+
default: "false"
4849
required: false
4950
run_node_test:
50-
default: true
51+
description: "run node test"
52+
default: "true"
5153
required: false
5254
run_node_build:
53-
default: true
55+
description: "run node build"
56+
default: "true"
5457
required: false
5558
run_node_bundle:
56-
default: false
59+
description: "run node bundle"
60+
default: "false"
5761
required: false
5862
chromatic_enable:
5963
description: "Enable Chromatic tests"
6064
required: false
61-
type: boolean
62-
default: false
65+
default: "false"
6366
chromatic_project_token:
6467
description: "Chromatic project token"
6568
required: false
6669
# Python
6770
enable_python:
6871
description: "enables the python part of the action"
69-
default: true
72+
default: "true"
7073
required: true
7174
python_version:
7275
description: "python version to use"
73-
default: "3.10"
74-
required: true
76+
required: false
7577
enable_python_cache:
7678
description: "deprecated and disabled as uv is usually faster anyways"
7779
required: false
78-
default: false
80+
default: "false"
7981
run_python_lint:
80-
default: true
82+
description: "run python lint"
83+
default: "true"
8184
required: false
8285
run_python_test:
83-
default: true
86+
description: "run python test"
87+
default: "true"
8488
required: false
8589
run_python_build:
86-
default: true
90+
description: "run python build"
91+
default: "true"
8792
required: false
8893
# Rust
8994
enable_rust:
9095
description: "enables the rust part of the action"
91-
default: false
96+
default: "false"
9297
required: true
9398

9499
runs:
95100
using: "composite"
96101
steps:
97102
# Node
103+
- uses: ./tmp/github-workflows/.github/actions/get-node-version
104+
if: inputs.enable_node == 'true' && inputs.node_version == ''
105+
id: get-node-version
98106
- name: Set up node version
99-
uses: actions/setup-node@v4
107+
uses: actions/setup-node@v5
100108
if: inputs.enable_node == 'true'
101109
with:
102-
node-version: ${{ inputs.node_version }}
103-
registry-url: ${{ inputs.npm_registry }}
110+
node-version: ${{ inputs.node_version || fromJson(steps.get-node-version.outputs.node_version) }}
111+
registry-url: ${{ inputs.npm_registry || 'https://registry.npmjs.org/' }}
112+
package-manager-cache: false
104113
- name: Show node and npm version
105114
if: inputs.enable_node == 'true'
106115
run: |
@@ -113,7 +122,7 @@ runs:
113122
uses: actions/setup-python@v5
114123
if: inputs.enable_python == 'true'
115124
with:
116-
python-version: ${{ inputs.python_version }}
125+
python-version: ${{ inputs.python_version || '3.10' }}
117126
# cache: ${{ inputs.enable_python_cache == 'true' && 'pip' || null }} Disable cache as uv is probably faster anyways: https://github.com/actions/setup-python/issues/822
118127
- name: Install additional python requirements
119128
if: inputs.enable_python == 'true'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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: Setup sandboxed dependencies
14+
shell: bash
15+
run: |
16+
npm init -y --prefix ${{ github.action_path }} >/dev/null 2>&1
17+
npm install semver --prefix ${{ github.action_path }} >/dev/null 2>&1
18+
19+
- name: Find version script
20+
id: get-node-version
21+
uses: actions/github-script@v7
22+
with:
23+
script: |
24+
const path = require('path');
25+
const fs = require('fs');
26+
// Load the sandboxed semver dependency from the action's own node_modules
27+
const semver = require(path.join(process.env.GITHUB_ACTION_PATH, 'node_modules/semver'));
28+
29+
const defaultVersion = '20.9';
30+
31+
// Define the versions to check against the package.json engines field, in order of preference
32+
// See https://github.com/actions/node-versions/releases for available versions
33+
const versionsToCheck = [defaultVersion, '24.9'].map((v) => semver.minVersion(v).version);
34+
35+
const packageJsonPath = path.join(process.env.GITHUB_WORKSPACE, 'package.json');
36+
if (!fs.existsSync(packageJsonPath)) {
37+
core.setFailed(`Error: package.json not found at ${packageJsonPath}`);
38+
return;
39+
}
40+
41+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
42+
const requiredRange = packageJson.engines?.node;
43+
44+
if (!requiredRange) {
45+
core.info(`No node engine requirement in package.json. Returning default version ${defaultVersion}.`);
46+
return defaultVersion;
47+
}
48+
49+
for (const version of versionsToCheck) {
50+
if (semver.satisfies(version, requiredRange)) {
51+
core.info(`\nMatch found! Returning version ${version} out of ${versionsToCheck.join(', ')} for range "${requiredRange}".`);
52+
// Simply return the matching version string to set the 'result' output
53+
return version;
54+
}
55+
}
56+
57+
core.setFailed(`\nNo compatible Node.js version found in the list of versions "${versionsToCheck.join(', ')}" for range "${requiredRange}". Returning default version ${defaultVersion}.`);
58+
return defaultVersion;

.github/actions/publish-python/action.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ author: datavisyn
55
inputs:
66
pypi_registry:
77
description: "registry where to publish python package"
8-
default: "https://upload.pypi.org/legacy/"
9-
required: true
8+
required: false
109
pypi_username:
1110
description: "username for python registry"
12-
default: "admin"
1311
required: true
1412
pypi_password:
1513
description: "passwort for python registry"
16-
default: "admin"
1714
required: true
1815

1916
runs:
@@ -30,6 +27,6 @@ runs:
3027
twine upload dist_python/*
3128
shell: bash
3229
env:
33-
PYPI_REPOSITORY: ${{ inputs.pypi_registry }}
30+
PYPI_REPOSITORY: ${{ inputs.pypi_registry || 'https://upload.pypi.org/legacy/' }}
3431
TWINE_USERNAME: ${{ inputs.pypi_username }}
3532
TWINE_PASSWORD: ${{ inputs.pypi_password }}

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

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ on:
102102
secrets:
103103
DATAVISYN_BOT_REPO_TOKEN:
104104
required: false
105-
NODE_VERSION:
106-
required: false
107-
PYTHON_VERSION:
108-
required: false
109105
ENV_PASSWORD:
110106
required: false
111107
CYPRESS_ENV:
@@ -114,12 +110,7 @@ on:
114110
required: false
115111

116112
env:
117-
NPM_REGISTRY: "https://registry.npmjs.org/"
118-
NODE_VERSION: ${{ vars.NODE_VERSION || '20.9' }}
119-
PYPI_REGISTRY: "https://upload.pypi.org/legacy/"
120-
PYPI_USERNAME: "datavisyn"
121-
PYTHON_VERSION: ${{ vars.PYTHON_VERSION || '3.10' }}
122-
WORKFLOW_BRANCH: "main"
113+
WORKFLOW_BRANCH: "mp/node_version"
123114
POSTGRES_HOSTNAME: postgres_${{ github.job }}_${{ inputs.deduplication_id }}_${{ github.run_id }}_${{ github.run_attempt }}
124115

125116
permissions:
@@ -161,9 +152,9 @@ jobs:
161152
# We probably won't need Rust on Node builds...
162153
# enable_rust: ${{ inputs.rust_enable }}
163154
run_parallel: ${{ inputs.run_parallel }}
164-
node_version: ${{ inputs.node_version || secrets.NODE_VERSION || env.NODE_VERSION }}
165-
npm_registry: ${{ env.NPM_REGISTRY }}
166-
python_version: ${{ inputs.python_version || secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
155+
node_version: ${{ vars.NODE_VERSION || inputs.node_version }}
156+
npm_registry: ${{ vars.NPM_REGISTRY }}
157+
python_version: ${{ vars.PYTHON_VERSION || inputs.python_version }}
167158
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
168159
run_node_bundle: ${{ inputs.node_run_webpack }}
169160
enable_node_cache: ${{ inputs.runs_on != 'self-hosted' }}
@@ -202,9 +193,9 @@ jobs:
202193
enable_python: true
203194
enable_rust: ${{ inputs.rust_enable }}
204195
run_parallel: ${{ inputs.run_parallel }}
205-
node_version: ${{ inputs.node_version || secrets.NODE_VERSION || env.NODE_VERSION }}
206-
npm_registry: ${{ env.NPM_REGISTRY }}
207-
python_version: ${{ inputs.python_version || secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
196+
node_version: ${{ vars.NODE_VERSION || inputs.node_version }}
197+
npm_registry: ${{ vars.NPM_REGISTRY }}
198+
python_version: ${{ vars.PYTHON_VERSION || inputs.python_version }}
208199
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
209200
run_node_bundle: ${{ inputs.node_run_webpack }}
210201
enable_node_cache: ${{ inputs.runs_on != 'self-hosted' }}
@@ -293,9 +284,9 @@ jobs:
293284
with:
294285
enable_rust: ${{ inputs.rust_enable }}
295286
run_parallel: ${{ inputs.run_parallel }}
296-
node_version: ${{ inputs.node_version || secrets.NODE_VERSION || env.NODE_VERSION }}
297-
npm_registry: ${{ env.NPM_REGISTRY }}
298-
python_version: ${{ inputs.python_version || secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
287+
node_version: ${{ vars.NODE_VERSION || inputs.node_version }}
288+
npm_registry: ${{ vars.NPM_REGISTRY }}
289+
python_version: ${{ vars.PYTHON_VERSION || inputs.python_version }}
299290
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
300291
run_node_bundle: false # Disable the build here and call afterwards, as otherwise the yarn run env:decrypt will fail due to a missing yarn install
301292
enable_node_cache: ${{ inputs.cypress_runs_on != 'self-hosted' && inputs.runs_on != 'self-hosted' }}
@@ -436,9 +427,9 @@ jobs:
436427
with:
437428
enable_rust: ${{ inputs.rust_enable }}
438429
run_parallel: ${{ inputs.run_parallel }}
439-
node_version: ${{ inputs.node_version || secrets.NODE_VERSION || env.NODE_VERSION }}
440-
npm_registry: ${{ env.NPM_REGISTRY }}
441-
python_version: ${{ inputs.python_version || secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
430+
node_version: ${{ vars.NODE_VERSION || inputs.node_version }}
431+
npm_registry: ${{ vars.NPM_REGISTRY }}
432+
python_version: ${{ vars.PYTHON_VERSION || inputs.python_version }}
442433
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
443434
run_node_bundle: false # Disable the build here and call afterwards, as otherwise the yarn run env:decrypt will fail due to a missing yarn install
444435
run_playwright_browser_install: true

.github/workflows/build-node.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ on:
2828
secrets:
2929
DATAVISYN_BOT_REPO_TOKEN:
3030
required: false
31-
NODE_VERSION:
32-
required: false
3331
CHROMATIC_PROJECT_TOKEN:
3432
required: false
3533

3634
env:
37-
NPM_REGISTRY: "https://registry.npmjs.org/"
38-
NODE_VERSION: ${{ vars.NODE_VERSION || '20.9' }}
3935
WORKFLOW_BRANCH: "main"
4036

4137
permissions:
@@ -73,8 +69,8 @@ jobs:
7369
with:
7470
enable_node: true
7571
enable_python: false
76-
node_version: ${{ inputs.node_version || secrets.NODE_VERSION || env.NODE_VERSION }}
77-
npm_registry: ${{ env.NPM_REGISTRY }}
72+
node_version: ${{ vars.NODE_VERSION || inputs.node_version }}
73+
npm_registry: ${{ vars.NPM_REGISTRY }}
7874
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
7975
run_node_bundle: ${{ inputs.node_run_webpack }}
8076
enable_node_cache: ${{ inputs.runs_on != 'self-hosted' }}

.github/workflows/build-python.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ on:
1818
secrets:
1919
DATAVISYN_BOT_REPO_TOKEN:
2020
required: false
21-
PYTHON_VERSION:
22-
required: false
2321

2422
env:
25-
PYPI_REGISTRY: "https://upload.pypi.org/legacy/"
26-
PYPI_USERNAME: "test"
27-
PYTHON_VERSION: ${{ vars.PYTHON_VERSION || '3.10' }}
2823
WORKFLOW_BRANCH: "main"
2924

3025
permissions:
@@ -62,5 +57,5 @@ jobs:
6257
enable_node: false
6358
enable_python: true
6459
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
65-
python_version: ${{ inputs.python_version || secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
60+
python_version: ${{ vars.PYTHON_VERSION || inputs.python_version }}
6661
enable_python_cache: ${{ inputs.runs_on != 'self-hosted' }}

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,8 @@ on:
1919
required: true
2020
DATAVISYN_BOT_REPO_TOKEN:
2121
required: false
22-
NODE_VERSION:
23-
required: false
24-
PYTHON_VERSION:
25-
required: false
2622

2723
env:
28-
NODE_VERSION: ${{ vars.NODE_VERSION || '20.9' }}
29-
NPM_REGISTRY: "https://registry.npmjs.org/"
30-
PYPI_REGISTRY: "https://upload.pypi.org/legacy/"
31-
PYPI_USERNAME: "datavisyn"
32-
PYTHON_VERSION: ${{ vars.PYTHON_VERSION || '3.10' }}
3324
WORKFLOW_BRANCH: "main"
3425

3526
permissions:
@@ -71,8 +62,8 @@ jobs:
7162
with:
7263
enable_node: true
7364
enable_python: false
74-
node_version: ${{ inputs.node_version || secrets.NODE_VERSION || env.NODE_VERSION }}
75-
npm_registry: ${{ env.NPM_REGISTRY }}
65+
node_version: ${{ vars.NODE_VERSION || inputs.node_version }}
66+
npm_registry: ${{ vars.NPM_REGISTRY }}
7667
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
7768
- uses: ./tmp/github-workflows/.github/actions/publish-node
7869
with:
@@ -104,10 +95,10 @@ jobs:
10495
with:
10596
enable_node: false
10697
enable_python: true
107-
python_version: ${{ inputs.python_version || secrets.PYTHON_VERSION || env.PYTHON_VERSION }}
98+
python_version: ${{ vars.PYTHON_VERSION || inputs.python_version }}
10899
github_ro_token: ${{ github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
109100
- uses: ./tmp/github-workflows/.github/actions/publish-python
110101
with:
111-
pypi_registry: ${{ env.PYPI_REGISTRY }}
102+
pypi_registry: ${{ vars.PYPI_REGISTRY }}
112103
pypi_username: ${{ secrets.PYPI_USERNAME }}
113104
pypi_password: ${{ secrets.PYPI_PASSWORD }}

0 commit comments

Comments
 (0)