Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
| `org-id` | No | — | Organization ID for multi-org accounts |
| `workspace-id` | No | — | Workspace ID for multi-workspace accounts |
| `verify-connection` | No | `false` | Run `devhelm auth me` after setup to verify credentials |
| `node-version` | No | `20` | Node.js version. Set to `''` to skip if you manage Node yourself |
| `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 |

## Outputs

Expand All @@ -88,12 +88,16 @@ jobs:

## How it works

1. **Node.js** — ensures Node >= 18 is available (auto-installs via `actions/setup-node` unless you set `node-version: ''`)
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`.
2. **Cache** — restores `~/.npm` cache keyed on OS + CLI version
3. **Install** — runs `npm install -g devhelm@<version>`
4. **Environment** — exports `DEVHELM_API_TOKEN`, `DEVHELM_API_URL`, `DEVHELM_ORG_ID`, `DEVHELM_WORKSPACE_ID` for all subsequent steps
5. **Verify** — optionally runs `devhelm auth me` to fail fast on bad credentials

### Compatibility with caller-installed Node

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.

## Security

- **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).
Expand All @@ -102,7 +106,7 @@ jobs:

## Requirements

- **Node.js >= 18** — the action auto-installs Node 20 by default. Set `node-version: ''` if your workflow already provides Node.
- **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).
- **npm** — ships with Node.js.

## License
Expand Down
30 changes: 24 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ inputs:
required: false
default: 'false'
node-version:
description: 'Node.js version to use if actions/setup-node was not called before this action. Set to empty string to skip auto-setup.'
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.'
required: false
default: '20'

Expand All @@ -43,21 +43,39 @@ outputs:
runs:
using: composite
steps:
- name: Detect existing Node.js
id: node-detect
shell: bash
run: |
if command -v node >/dev/null 2>&1; then
MAJOR=$(node -v | sed 's/^v\([0-9]*\).*/\1/')
if [ "$MAJOR" -ge 18 ]; then
echo "found=true" >> "$GITHUB_OUTPUT"
echo "version=$(node -v)" >> "$GITHUB_OUTPUT"
echo "Node $(node -v) detected (>=18); skipping setup-node."
exit 0
fi
echo "Node $(node -v) detected but <18; will install Node ${{ inputs.node-version }}."
else
echo "No Node.js detected on PATH; will install Node ${{ inputs.node-version }}."
fi
echo "found=false" >> "$GITHUB_OUTPUT"

- name: Ensure Node.js is available
if: inputs.node-version != ''
if: steps.node-detect.outputs.found != 'true' && inputs.node-version != ''
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

- name: Validate Node.js
shell: bash
run: |
if ! command -v node &>/dev/null; then
echo "::error::Node.js is required. Either set input 'node-version' or run actions/setup-node before this action."
if ! command -v node >/dev/null 2>&1; then
echo "::error::Node.js is required. Either set input 'node-version' (default: 20) or run actions/setup-node before this action."
exit 1
fi
NODE_MAJOR=$(node -v | sed 's/v\([0-9]*\).*/\1/')
if (( NODE_MAJOR < 18 )); then
NODE_MAJOR=$(node -v | sed 's/^v\([0-9]*\).*/\1/')
if [ "$NODE_MAJOR" -lt 18 ]; then
echo "::error::DevHelm CLI requires Node.js >= 18 (found $(node -v))"
exit 1
fi
Expand Down
Loading