-
Notifications
You must be signed in to change notification settings - Fork 6
222 lines (186 loc) · 7.63 KB
/
deploy.yml
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
name: Code Quality
on:
push:
branches: [dev]
pull_request:
branches: [main, dev]
types: [opened, synchronize, reopened]
jobs:
quality-checks:
name: Quality Checks
runs-on: ubuntu-latest
timeout-minutes: 15 # Prevent hanging jobs
permissions:
id-token: write # Needed for auth with Deno Deploy
contents: read # Needed to clone the repository
pull-requests: write # Needed for PR comments
env:
CSRF_SECRET_KEY: "12323" # Placeholder key
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Cache npm dependencies
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
- name: Install npm dependencies
run: npm ci # More reliable than npm install
- name: Validate OpenAPI Schema
run: npm run validate:ci
# Cache Deno dependencies
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.1.5
- name: Cache Deno dependencies
uses: actions/cache@v3
with:
path: |
~/.deno
~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}
restore-keys: |
${{ runner.os }}-deno-
- name: Install reviewdog
uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Enable debug output and error handling
set -x
set -e
# Function to cleanup on error
cleanup() {
echo "Error occurred. Cleaning up..."
pkill -f reviewdog || true
exit 1
}
trap cleanup ERR
# Set timeout for each reviewdog process
timeout_duration=60 # Increased timeout
# Debug: Show environment
echo "Current directory: $(pwd)"
echo "Files in scripts directory:"
ls -la ./scripts/
# Error handling function
error() {
echo "ERROR: $*" >&2
exit 1
}
# Function to process files in batches with rate limit handling
process_files() {
local check_type=$1
local batch_size=3 # Minimal batch size for stability
local batch_num=1
local retry_delay=15 # Retry delay for rate limits
local max_files=30 # Further reduced file limit for testing
# Create temporary directory
temp_dir=$(mktemp -d) || error "Failed to create temp directory"
trap 'rm -rf "$temp_dir"' EXIT
# Use shell globbing for file discovery
shopt -s globstar nullglob
local files=()
if [ "$check_type" = "fmt" ]; then
while IFS= read -r -d $'\0' file; do
[[ "$file" == *"/node_modules/"* ]] && continue
[[ "$file" == *"/_fresh/"* ]] && continue
[[ "$file" == */dist/* ]] && continue
[[ "$file" == */.git/* ]] && continue
files+=("$file")
done < <(find . -maxdepth 3 -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \) -print0)
else
while IFS= read -r -d $'\0' file; do
[[ "$file" == *"/node_modules/"* ]] && continue
[[ "$file" == *"/_fresh/"* ]] && continue
[[ "$file" == */dist/* ]] && continue
[[ "$file" == */.git/* ]] && continue
files+=("$file")
done < <(find . -maxdepth 3 -type f \( -name "*.ts" -o -name "*.tsx" \) -print0)
fi
# Get total files and limit if needed
total_files=${#files[@]}
if [ "$total_files" -gt "$max_files" ]; then
total_files=$max_files
fi
# Process files in batches
for ((i = 0; i < total_files; i += batch_size)); do
echo "Processing $check_type batch $batch_num..."
# Create batch directory
batch_dir="$temp_dir/batch_$batch_num"
mkdir -p "$batch_dir"
# Process current batch
for ((j = i; j < i + batch_size && j < total_files; j++)); do
file="${files[$j]}"
if [ -f "$file" ]; then
out_file="$batch_dir/$(basename "$file").out"
if [ "$check_type" = "fmt" ]; then
deno fmt --check "$file" > "$out_file" 2>&1 || true
else
deno lint --json "$file" > "$out_file" 2>&1 || true
fi
fi
done
# Combine batch outputs
{
for f in "$batch_dir"/*.out; do
[ -f "$f" ] && cat "$f"
done
} | ./scripts/transform-deno-output.sh "$check_type" > "$temp_dir/${check_type}_${batch_num}.json"
# Run reviewdog on batch with retries
if [ -s "$temp_dir/${check_type}_${batch_num}.json" ]; then
local attempts=0
local max_attempts=3
while [ $attempts -lt $max_attempts ]; do
echo "Running reviewdog on ${check_type} batch $batch_num (attempt $((attempts + 1)))..."
if timeout $timeout_duration reviewdog \
-f=rdjson \
-name="${check_type}" \
-reporter=github-pr-review \
< "$temp_dir/${check_type}_${batch_num}.json"; then
break # Success, exit retry loop
else
local exit_code=$?
# Check if it's a rate limit error
if grep -q "API rate limit exceeded" "$temp_dir/${check_type}_${batch_num}.json"; then
echo "Rate limit exceeded. Waiting ${retry_delay} seconds before retry..."
sleep $retry_delay
retry_delay=$((retry_delay * 2)) # Exponential backoff
else
echo "Error running reviewdog (exit code: $exit_code)"
break # Exit on non-rate-limit errors
fi
fi
((attempts++))
done
fi
# Cleanup batch files
rm -rf "$batch_dir"
rm -f "$temp_dir/${check_type}_${batch_num}.json"
rm -f "${check_type}_${batch_num}.json"
((batch_num++))
# Add a small delay between batches to avoid rate limiting
sleep 5
done
}
# Process fmt and lint separately
echo "Starting fmt checks..."
process_files fmt
echo "Starting lint checks..."
process_files lint
exit 0
# Fail the workflow if any checks failed
- name: Check for failures
if: steps.fmt.outcome == 'failure' || steps.lint.outcome == 'failure'
run: exit 1
# Build check
- name: Build project
run: deno task build
# Commented out for future implementation
# - name: Type check
# run: deno task check:types
# continue-on-error: true # Optional: allow type checks to fail for now