-
Notifications
You must be signed in to change notification settings - Fork 5
186 lines (154 loc) · 5.96 KB
/
test-branch.yml
File metadata and controls
186 lines (154 loc) · 5.96 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
name: Test Branch
# Minimal permissions for manual branch testing
permissions:
contents: read # Read repository contents
actions: read # Read workflow details
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to test'
required: true
default: 'automated-dependency-updates'
type: string
test_type:
description: 'Type of test to run'
required: true
default: 'full'
type: choice
options:
- full
- quick
- examples-only
jobs:
test-branch:
name: Test Branch - ${{ inputs.branch }}
runs-on: ubuntu-latest
timeout-minutes: 25
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- name: Checkout specified branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Update npm (Node.js version compatible)
run: |
echo "Current npm version: $(npm --version)"
echo "Attempting to update npm..."
if [[ "${{ matrix.node-version }}" == "18.x" ]]; then
npm install -g npm@10 || echo "Failed to update npm, continuing with existing version"
else
npm install -g npm@latest || echo "Failed to update npm, continuing with existing version"
fi
echo "Final npm version: $(npm --version)"
continue-on-error: true
- name: Configure npm for better reliability
run: |
echo "Configuring npm with increased timeouts and retries..."
npm config set fetch-retry-maxtimeout 60000
npm config set fetch-retry-mintimeout 10000
npm config set fetch-timeout 300000
npm config set maxsockets 15
npm config set registry https://registry.npmjs.org/
echo "npm configuration complete"
continue-on-error: true
- name: Verify npm registry access
run: |
echo "Testing npm registry access..."
npm ping || echo "Warning: npm registry ping failed"
echo "Registry test complete"
continue-on-error: true
- name: Install dependencies
run: |
echo "Node.js version: $(node --version)"
echo "npm version: $(npm --version)"
echo "Attempting npm ci..."
# First attempt: npm ci
if npm ci; then
echo "✅ npm ci succeeded"
else
echo "❌ npm ci failed, trying recovery strategies..."
# Second attempt: clear cache and retry npm ci
echo "Clearing cache and retrying npm ci..."
npm cache clean --force || true
if npm ci; then
echo "✅ npm ci succeeded after cache clear"
else
echo "❌ npm ci failed again, trying fresh install..."
# Third attempt: fresh install
rm -f package-lock.json
if npm install; then
echo "✅ npm install succeeded"
echo "Regenerating package-lock.json..."
npm install --package-lock-only || echo "Warning: Could not regenerate package-lock.json"
else
echo "❌ All npm install methods failed"
exit 1
fi
fi
fi
echo "Final dependency installation complete"
- name: Run linting
if: inputs.test_type == 'full' || inputs.test_type == 'quick'
run: npm run lint
- name: Check code formatting
if: inputs.test_type == 'full'
run: npm run format -- --check
- name: Run tests
if: inputs.test_type == 'full' || inputs.test_type == 'quick'
run: npm test
- name: Build project
if: inputs.test_type == 'full' || inputs.test_type == 'quick'
run: npm run build
- name: Test examples
if: inputs.test_type == 'full' || inputs.test_type == 'examples-only'
run: |
echo "Testing example files..."
echo "Note: Examples will fail with API errors since no API key is configured, but imports should work"
echo "Testing basic-usage.js..."
timeout 10s node examples/basic-usage.js || echo "Expected to fail at API call - import successful"
echo "Testing embeddings.js..."
timeout 10s node examples/embeddings.js || echo "Expected to fail at API call - import successful"
echo "Testing enhanced-features.js..."
timeout 10s node examples/enhanced-features.js || echo "Expected to fail at API call - import successful"
echo "✅ All examples loaded successfully"
security-check:
name: Security Check - ${{ inputs.branch }}
runs-on: ubuntu-latest
steps:
- name: Checkout specified branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'npm'
- name: Install dependencies
run: npm ci || npm install
- name: Security audit
run: |
echo "🔍 Running security audit..."
npm audit --audit-level=moderate || echo "Audit completed with findings"
# Generate detailed audit report
npm audit --json > audit-results.json || true
# Check for critical/high severity issues
if command -v jq >/dev/null 2>&1; then
critical=$(jq '.metadata.vulnerabilities.critical // 0' audit-results.json)
high=$(jq '.metadata.vulnerabilities.high // 0' audit-results.json)
echo "Critical vulnerabilities: $critical"
echo "High vulnerabilities: $high"
if [ "$critical" -gt 0 ]; then
echo "❌ Critical vulnerabilities found - blocking merge"
exit 1
fi
fi
echo "✅ Security audit completed"