forked from flagos-ai/FlagScale
-
Notifications
You must be signed in to change notification settings - Fork 0
247 lines (219 loc) · 8.1 KB
/
functional_tests_cli.yml
File metadata and controls
247 lines (219 loc) · 8.1 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: Common Functional Tests - CLI
on:
workflow_call:
inputs:
platform:
required: true
type: string
description: Platform name (e.g., cuda, default)
image:
required: true
type: string
runs_on:
required: true
type: string
container_volumes:
required: true
type: string
container_options:
required: true
type: string
source_artifact:
required: true
type: string
description: Name of the artifact containing source code
pkg_mgr:
required: false
type: string
description: Package manager (pip, uv, conda). Default uv.
default: "uv"
env_name:
required: false
type: string
description: Conda environment name (for conda only)
default: ""
env_path:
required: false
type: string
description: Environment path (venv path for uv, conda installation path for conda)
default: "/opt/venv"
jobs:
functional_test_cli:
defaults:
run:
shell: bash
env:
PROJECT_ROOT: /tmp/FlagScale
runs-on: ${{ fromJson(inputs.runs_on) }}
container:
image: ${{ inputs.image }}
ports:
- 80
volumes: ${{ fromJson(inputs.container_volumes) }}
options: ${{ inputs.container_options }}
steps:
- name: Download source code artifact (attempt 1)
uses: actions/download-artifact@v4
continue-on-error: true
id: download_attempt_1
with:
name: ${{ inputs.source_artifact }}
path: /tmp
- name: Download source code artifact (attempt 2)
if: steps.download_attempt_1.outcome == 'failure'
uses: actions/download-artifact@v4
continue-on-error: true
id: download_attempt_2
with:
name: ${{ inputs.source_artifact }}
path: /tmp
- name: Download source code artifact (attempt 3)
if: steps.download_attempt_2.outcome == 'failure'
uses: actions/download-artifact@v4
id: download_attempt_3
with:
name: ${{ inputs.source_artifact }}
path: /tmp
- name: Verify artifact download
run: |
if [ "${{ steps.download_attempt_1.outcome }}" == "success" ]; then
echo "✅ Artifact downloaded successfully on attempt 1"
elif [ "${{ steps.download_attempt_2.outcome }}" == "success" ]; then
echo "✅ Artifact downloaded successfully on attempt 2 (retried once)"
elif [ "${{ steps.download_attempt_3.outcome }}" == "success" ]; then
echo "✅ Artifact downloaded successfully on attempt 3 (retried twice)"
else
echo "❌ Error: All 3 download attempts failed"
echo "Artifact name: ${{ inputs.source_artifact }}"
exit 1
fi
- name: Extract source code
run: |
mkdir -p $PROJECT_ROOT
tar -xzf /tmp/flagscale-source.tar.gz -C $PROJECT_ROOT
- name: Set safe directory
run: |
git config --global --add safe.directory $PROJECT_ROOT
- name: Check environment info
run: cd $PROJECT_ROOT && bash ./tests/test_utils/runners/check_env.sh
- name: Install FlagScale CLI
run: |
set -euo pipefail
cd $PROJECT_ROOT
PKG_MGR='${{ inputs.pkg_mgr }}'
ENV_NAME='${{ inputs.env_name }}'
ENV_PATH='${{ inputs.env_path }}'
echo "Installing FlagScale CLI"
echo "Installing dependencies for training"
echo "Package Manager: $PKG_MGR"
echo "Environment Name: $ENV_NAME"
echo "Environment Path: $ENV_PATH"
# Source environment utilities
source ./tools/install/utils/pyenv_utils.sh
# Activate environment based on package manager
case "$PKG_MGR" in
conda)
if [ -n "$ENV_NAME" ] && [ -n "$ENV_PATH" ]; then
activate_conda "$ENV_NAME" "$ENV_PATH" || { echo "❌ Conda activation failed"; exit 1; }
fi
;;
uv)
if [ -n "$ENV_PATH" ] && [ -d "$ENV_PATH" ]; then
activate_uv_env "$ENV_PATH" || { echo "❌ UV activation failed"; exit 1; }
fi
;;
pip)
echo "Using system Python with pip"
;;
esac
echo "Python location: $(which python)"
echo "Python version: $(python --version)"
# Install FlagScale CLI
pip install . --no-build-isolation --root-user-action=ignore || { echo "❌ FlagScale CLI install failed"; exit 1; }
# Verify installation
command -v flagscale || { echo "❌ FlagScale CLI not found in PATH"; exit 1; }
echo "✅ FlagScale CLI installed successfully"
timeout-minutes: 10
- name: Validate CLI functionality
id: cli_validation
run: |
set -euo pipefail
cd $PROJECT_ROOT
PKG_MGR='${{ inputs.pkg_mgr }}'
ENV_NAME='${{ inputs.env_name }}'
ENV_PATH='${{ inputs.env_path }}'
# Source environment utilities
source ./tools/install/utils/pyenv_utils.sh
# Activate environment based on package manager
# Activate environment based on package manager
case "$PKG_MGR" in
conda)
if [ -n "$ENV_NAME" ] && [ -n "$ENV_PATH" ]; then
activate_conda "$ENV_NAME" "$ENV_PATH" || { echo "❌ Conda activation failed"; exit 1; }
fi
;;
uv)
if [ -n "$ENV_PATH" ] && [ -d "$ENV_PATH" ]; then
activate_uv_env "$ENV_PATH" || { echo "❌ UV activation failed"; exit 1; }
fi
;;
pip)
echo "Using system Python with pip"
;;
esac
echo "Validating CLI"
echo "Python location: $(which python)"
echo "Python version: $(python --version)"
failed=false
# 1. Validate flagscale --version
echo "=========================================="
echo "Test: flagscale --version"
echo "=========================================="
if flagscale --version; then
echo "✅ flagscale --version passed"
else
echo "❌ flagscale --version failed"
failed=true
fi
# 2. Validate flagscale --help
echo "=========================================="
echo "Test: flagscale --help"
echo "=========================================="
if flagscale --help; then
echo "✅ flagscale --help passed"
else
echo "❌ flagscale --help failed"
failed=true
fi
# 3. Validate each subcommand --help
SUBCOMMANDS="train serve inference rl compress install test pull run"
for cmd in $SUBCOMMANDS; do
echo "=========================================="
echo "Test: flagscale $cmd --help"
echo "=========================================="
if flagscale $cmd --help; then
echo "✅ flagscale $cmd --help passed"
else
echo "❌ flagscale $cmd --help failed"
failed=true
fi
done
# 4. Run CLI unit tests
echo "=========================================="
echo "Test: CLI unit tests (pytest)"
echo "=========================================="
pip install pytest pytest-mock --root-user-action=ignore || { echo "❌ pytest install failed"; exit 1; }
if pytest tests/unit_tests/test_cli.py -v; then
echo "✅ CLI unit tests passed"
else
echo "❌ CLI unit tests failed"
failed=true
fi
# Final result
echo "=========================================="
if [ "$failed" = "true" ]; then
echo "❌ CLI validation failed"
exit 1
fi
echo "✅ All CLI validations passed!"
timeout-minutes: 10