-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yml
More file actions
225 lines (196 loc) · 7 KB
/
action.yml
File metadata and controls
225 lines (196 loc) · 7 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: "Setup vx"
description: "Setup vx - Universal Development Tool Manager for your CI/CD workflows"
author: "loonghao"
branding:
icon: "package"
color: "blue"
inputs:
version:
description: 'vx version to install (e.g., "0.5.7", "latest")'
required: false
default: "latest"
github-token:
description: "GitHub token for API requests (avoids rate limiting)"
required: false
default: ${{ github.token }}
tools:
description: 'Space-separated list of tools to pre-install (e.g., "node go uv")'
required: false
default: ""
cache:
description: "Enable caching of vx tools directory"
required: false
default: "true"
cache-key-prefix:
description: "Custom prefix for cache key"
required: false
default: "vx-tools"
setup:
description: 'Run vx setup --ci to install tools from vx.toml and export tool paths to GITHUB_PATH. Set to "true" to enable, "false" to disable (default)'
required: false
default: "false"
outputs:
version:
description: "The installed vx version"
value: ${{ steps.setup.outputs.version }}
cache-hit:
description: "Whether the cache was hit"
value: ${{ steps.cache.outputs.cache-hit }}
runs:
using: "composite"
steps:
# Cache vx tools directory
- name: Cache vx tools
if: inputs.cache == 'true'
id: cache
uses: actions/cache@v5
with:
path: |
~/.vx
~/.local/bin/vx
~/.local/bin/vx.exe
key: ${{ inputs.cache-key-prefix }}-${{ runner.os }}-${{ inputs.version }}-${{ inputs.tools }}
restore-keys: |
${{ inputs.cache-key-prefix }}-${{ runner.os }}-${{ inputs.version }}-
${{ inputs.cache-key-prefix }}-${{ runner.os }}-
# Install vx on Linux/macOS using install.sh
- name: Install vx (Unix)
if: runner.os != 'Windows'
id: install-unix
shell: bash
env:
VX_VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ inputs.github-token }}
run: |
set -e
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
# Add to PATH immediately for current step and subsequent steps
echo "$INSTALL_DIR" >> $GITHUB_PATH
export PATH="$INSTALL_DIR:$PATH"
# Add vx managed tools bin directory to PATH
VX_BIN_DIR="$HOME/.vx/bin"
mkdir -p "$VX_BIN_DIR"
echo "$VX_BIN_DIR" >> $GITHUB_PATH
export PATH="$VX_BIN_DIR:$PATH"
# Skip download if already cached
if [ -f "$INSTALL_DIR/vx" ]; then
echo "vx already installed (from cache)"
else
echo "Installing vx via install.sh..."
# Use the bundled install.sh script
# VX_INSTALL_DIR controls where the binary is placed
export VX_INSTALL_DIR="$INSTALL_DIR"
export GITHUB_TOKEN="$GH_TOKEN"
# install.sh is bundled with the action
bash "${{ github.action_path }}/install.sh"
fi
# Verify installation
"$INSTALL_DIR/vx" --version
# Export for subsequent steps
echo "VX_INSTALL_DIR=$INSTALL_DIR" >> $GITHUB_ENV
if [ -n "$GH_TOKEN" ]; then
echo "GITHUB_TOKEN=$GH_TOKEN" >> $GITHUB_ENV
fi
# Install vx on Windows using install.ps1
- name: Install vx (Windows)
if: runner.os == 'Windows'
id: install-windows
shell: pwsh
env:
VX_VERSION: ${{ inputs.version }}
GH_TOKEN: ${{ inputs.github-token }}
run: |
$ErrorActionPreference = "Stop"
$InstallDir = "$env:USERPROFILE\.local\bin"
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
# Add to PATH immediately for current step and subsequent steps
$InstallDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
$env:PATH = "$InstallDir;$env:PATH"
# Add vx managed tools bin directory to PATH
$VxBinDir = "$env:USERPROFILE\.vx\bin"
New-Item -ItemType Directory -Path $VxBinDir -Force | Out-Null
$VxBinDir | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
$env:PATH = "$VxBinDir;$env:PATH"
$vxPath = "$InstallDir\vx.exe"
# Skip download if already cached
if (Test-Path $vxPath) {
Write-Host "vx already installed (from cache)"
} else {
Write-Host "Installing vx via install.ps1..."
# Use the bundled install.ps1 script
$env:VX_INSTALL_DIR = $InstallDir
$env:GITHUB_TOKEN = $env:GH_TOKEN
& "${{ github.action_path }}\install.ps1"
}
# Verify installation
& $vxPath --version
# Export for subsequent steps
"VX_INSTALL_DIR=$InstallDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
if ($env:GH_TOKEN) {
"GITHUB_TOKEN=$env:GH_TOKEN" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
# Get installed version
- name: Get vx version
id: setup
shell: bash
run: |
# Ensure PATH includes vx install directory
if [ -n "$VX_INSTALL_DIR" ]; then
export PATH="$VX_INSTALL_DIR:$PATH"
fi
if [ -f "$HOME/.local/bin/vx" ]; then
export PATH="$HOME/.local/bin:$PATH"
fi
export PATH="$HOME/.vx/bin:$PATH"
VERSION=$(vx --version | head -1 | awk '{print $2}')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "vx version: $VERSION"
# Pre-install specified tools
- name: Pre-install tools
if: inputs.tools != ''
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
if [ -n "$VX_INSTALL_DIR" ]; then
export PATH="$VX_INSTALL_DIR:$PATH"
fi
if [ -f "$HOME/.local/bin/vx" ]; then
export PATH="$HOME/.local/bin:$PATH"
fi
export PATH="$HOME/.vx/bin:$PATH"
echo "Pre-installing tools: ${{ inputs.tools }}"
for tool in ${{ inputs.tools }}; do
echo "Installing $tool..."
vx $tool --version || echo "Warning: Failed to install $tool"
done
echo ""
echo "Installed tools:"
vx list --status
# Setup environment for vx.toml projects
- name: Setup vx environment
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
VX_SETUP: ${{ inputs.setup }}
run: |
if [ -n "$VX_INSTALL_DIR" ]; then
export PATH="$VX_INSTALL_DIR:$PATH"
fi
if [ -f "$HOME/.local/bin/vx" ]; then
export PATH="$HOME/.local/bin:$PATH"
fi
export PATH="$HOME/.vx/bin:$PATH"
if [ -f "vx.toml" ] || [ -f ".vx.toml" ]; then
echo "Found vx configuration, setting up vx environment..."
if [ "$VX_SETUP" = "true" ]; then
echo "Running vx setup --ci..."
vx setup --ci || echo "Warning: vx setup failed"
echo "$HOME/.vx/bin" >> $GITHUB_PATH
else
echo "Skipping vx setup (set setup: 'true' to enable)"
fi
else
echo "No vx.toml found, skipping vx setup"
fi