-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
122 lines (111 loc) · 4.21 KB
/
action.yml
File metadata and controls
122 lines (111 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: 'Setup DevHelm CLI'
description: 'Install and configure the DevHelm CLI for monitoring-as-code workflows'
author: 'DevHelm'
branding:
icon: terminal
color: blue
inputs:
devhelm-version:
description: 'CLI version to install — exact semver (e.g. "0.1.4") or "latest"'
required: false
default: 'latest'
api-token:
description: 'DevHelm API token (recommended: pass via secrets.DEVHELM_API_TOKEN)'
required: false
api-url:
description: 'DevHelm API base URL (default: https://api.devhelm.io)'
required: false
org-id:
description: 'Organization ID for multi-org accounts'
required: false
workspace-id:
description: 'Workspace ID for multi-workspace accounts'
required: false
verify-connection:
description: 'Run "devhelm auth me" after setup to verify credentials work'
required: false
default: 'false'
node-version:
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'
outputs:
devhelm-version:
description: 'Installed CLI version (semver only, e.g. "0.1.4")'
value: ${{ steps.install.outputs.version }}
cache-hit:
description: 'Whether the npm cache was restored'
value: ${{ steps.cache.outputs.cache-hit }}
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: 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 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" -lt 18 ]; then
echo "::error::DevHelm CLI requires Node.js >= 18 (found $(node -v))"
exit 1
fi
- name: Restore npm cache
id: cache
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-devhelm-${{ inputs.devhelm-version }}
- name: Install DevHelm CLI
id: install
shell: bash
run: |
echo "::group::Installing devhelm@${{ inputs.devhelm-version }}"
npm install -g devhelm@${{ inputs.devhelm-version }} 2>&1
echo "::endgroup::"
RAW=$(devhelm --version)
VERSION=$(echo "$RAW" | awk '{print $1}' | sed 's|.*/||')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Installed devhelm $VERSION"
- name: Export environment variables
shell: bash
env:
INPUT_TOKEN: ${{ inputs.api-token }}
INPUT_URL: ${{ inputs.api-url }}
INPUT_ORG: ${{ inputs.org-id }}
INPUT_WS: ${{ inputs.workspace-id }}
run: |
[[ -n "$INPUT_TOKEN" ]] && echo "DEVHELM_API_TOKEN=$INPUT_TOKEN" >> "$GITHUB_ENV"
[[ -n "$INPUT_URL" ]] && echo "DEVHELM_API_URL=$INPUT_URL" >> "$GITHUB_ENV"
[[ -n "$INPUT_ORG" ]] && echo "DEVHELM_ORG_ID=$INPUT_ORG" >> "$GITHUB_ENV"
[[ -n "$INPUT_WS" ]] && echo "DEVHELM_WORKSPACE_ID=$INPUT_WS" >> "$GITHUB_ENV"
exit 0
- name: Verify connection
if: inputs.verify-connection == 'true' && inputs.api-token != ''
shell: bash
run: |
echo "Verifying DevHelm API connection..."
devhelm auth me --output json