Skip to content

Commit 6025fcf

Browse files
fix(action): detect existing Node ≥18 before calling setup-node
Previously the action's default node-version: '20' caused actions/setup-node@v4 to silently downgrade callers who had pinned Node 22+ via an earlier setup-node step. Add a Detect existing Node.js step that checks `node` on PATH and its major version. When Node ≥18 is already present we skip the inner setup-node entirely; otherwise we still install the configured node-version (default 20) as a fallback. Reword the input description and update the README to document the new behavior. Round-2 DevEx friction P1 — see /tmp/devex-r2-setup-devhelm/REPORT.md. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 6eba301 commit 6025fcf

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
| `org-id` | No | — | Organization ID for multi-org accounts |
7878
| `workspace-id` | No | — | Workspace ID for multi-workspace accounts |
7979
| `verify-connection` | No | `false` | Run `devhelm auth me` after setup to verify credentials |
80-
| `node-version` | No | `20` | Node.js version. Set to `''` to skip if you manage Node yourself |
80+
| `node-version` | No | `20` | Node.js version to install **only if** none is detected on PATH (or if detected version is `<18`). Existing Node `>=18` is preserved as-is. Set to `''` to skip auto-install entirely |
8181

8282
## Outputs
8383

@@ -88,12 +88,16 @@ jobs:
8888

8989
## How it works
9090

91-
1. **Node.js** — ensures Node >= 18 is available (auto-installs via `actions/setup-node` unless you set `node-version: ''`)
91+
1. **Node.js** — detects an existing `node` on `PATH`; if it's `>=18`, the action keeps it and skips `actions/setup-node` entirely. Otherwise it installs `node-version` (default `20`) via `actions/setup-node`.
9292
2. **Cache** — restores `~/.npm` cache keyed on OS + CLI version
9393
3. **Install** — runs `npm install -g devhelm@<version>`
9494
4. **Environment** — exports `DEVHELM_API_TOKEN`, `DEVHELM_API_URL`, `DEVHELM_ORG_ID`, `DEVHELM_WORKSPACE_ID` for all subsequent steps
9595
5. **Verify** — optionally runs `devhelm auth me` to fail fast on bad credentials
9696

97+
### Compatibility with caller-installed Node
98+
99+
If your workflow already runs `actions/setup-node@v4` (or otherwise pins a Node version) before this action, **your Node version is preserved**. The action only installs Node when none is on `PATH` or the detected major is `<18`. You no longer need to set `node-version: ''` to avoid being silently downgraded.
100+
97101
## Security
98102
99103
- **Never hardcode tokens** in workflow files. Use [GitHub Secrets](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions).
@@ -102,7 +106,7 @@ jobs:
102106

103107
## Requirements
104108

105-
- **Node.js >= 18** — the action auto-installs Node 20 by default. Set `node-version: ''` if your workflow already provides Node.
109+
- **Node.js >= 18** — if not present (or the detected version is `<18`), the action installs Node 20 by default. Any pre-existing Node `>=18` set up by an earlier step is left untouched. Set `node-version: ''` to skip the install fallback entirely (the action will then error if Node is missing).
106110
- **npm** — ships with Node.js.
107111

108112
## License

action.yml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ inputs:
2828
required: false
2929
default: 'false'
3030
node-version:
31-
description: 'Node.js version to use if actions/setup-node was not called before this action. Set to empty string to skip auto-setup.'
31+
description: 'Node.js version to install IF none is detected on PATH (or if detected version is <18). Existing Node >=18 is preserved. Set to empty string to skip auto-setup entirely. Default: 20.'
3232
required: false
3333
default: '20'
3434

@@ -43,21 +43,39 @@ outputs:
4343
runs:
4444
using: composite
4545
steps:
46+
- name: Detect existing Node.js
47+
id: node-detect
48+
shell: bash
49+
run: |
50+
if command -v node >/dev/null 2>&1; then
51+
MAJOR=$(node -v | sed 's/^v\([0-9]*\).*/\1/')
52+
if [ "$MAJOR" -ge 18 ]; then
53+
echo "found=true" >> "$GITHUB_OUTPUT"
54+
echo "version=$(node -v)" >> "$GITHUB_OUTPUT"
55+
echo "Node $(node -v) detected (>=18); skipping setup-node."
56+
exit 0
57+
fi
58+
echo "Node $(node -v) detected but <18; will install Node ${{ inputs.node-version }}."
59+
else
60+
echo "No Node.js detected on PATH; will install Node ${{ inputs.node-version }}."
61+
fi
62+
echo "found=false" >> "$GITHUB_OUTPUT"
63+
4664
- name: Ensure Node.js is available
47-
if: inputs.node-version != ''
65+
if: steps.node-detect.outputs.found != 'true' && inputs.node-version != ''
4866
uses: actions/setup-node@v4
4967
with:
5068
node-version: ${{ inputs.node-version }}
5169

5270
- name: Validate Node.js
5371
shell: bash
5472
run: |
55-
if ! command -v node &>/dev/null; then
56-
echo "::error::Node.js is required. Either set input 'node-version' or run actions/setup-node before this action."
73+
if ! command -v node >/dev/null 2>&1; then
74+
echo "::error::Node.js is required. Either set input 'node-version' (default: 20) or run actions/setup-node before this action."
5775
exit 1
5876
fi
59-
NODE_MAJOR=$(node -v | sed 's/v\([0-9]*\).*/\1/')
60-
if (( NODE_MAJOR < 18 )); then
77+
NODE_MAJOR=$(node -v | sed 's/^v\([0-9]*\).*/\1/')
78+
if [ "$NODE_MAJOR" -lt 18 ]; then
6179
echo "::error::DevHelm CLI requires Node.js >= 18 (found $(node -v))"
6280
exit 1
6381
fi

0 commit comments

Comments
 (0)