-
Notifications
You must be signed in to change notification settings - Fork 14
284 lines (250 loc) · 8.83 KB
/
Copy pathopenlake-ci.yml
File metadata and controls
284 lines (250 loc) · 8.83 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# OpenLake Standard CI/CD Workflow
# NEVER pushes directly to main - only runs on PRs
# Use this as a template for all OpenLake repos
name: OpenLake CI
on:
pull_request:
branches: [main, master, develop]
types: [opened, synchronize, reopened]
push:
branches: [main, master]
# Only run on main for status checks, never auto-merge without PR review
# Prevent multiple concurrent workflows on same PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ==============================
# SECURITY SCANNING
# ==============================
security:
name: 🔒 Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Scan for hardcoded secrets
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Dependency vulnerability scan
run: |
# Python
if [ -f "requirements.txt" ]; then
pip install safety
safety check -r requirements.txt --json || true
fi
# Node.js
if [ -f "package.json" ]; then
npm audit --production || true
fi
# Go
if [ -f "go.mod" ]; then
go list -m -json all | govulncheck || true
fi
continue-on-error: true
# ==============================
# CODE QUALITY
# ==============================
code-quality:
name: 🧹 Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check formatting
run: |
# Python
if [ -f "requirements.txt" ] || [ -f "pyproject.toml" ]; then
pip install black isort flake8
black --check . || echo "Python formatting issues found"
isort --check-only . || echo "Python import sorting issues found"
fi
# Node.js
if [ -f "package.json" ]; then
npm ci || npm install
npm run lint || echo "ESLint issues found (non-blocking)"
fi
# Go
if [ -f "go.mod" ]; then
go fmt ./...
if [ -n "$(git status --porcelain)" ]; then
echo "Go formatting issues found - run 'go fmt'"
fi
fi
# Rust
if [ -f "Cargo.toml" ]; then
rustup component add rustfmt
cargo fmt -- --check || echo "Rust formatting issues found"
fi
continue-on-error: true
- name: Check for TODOs and FIXMEs
run: |
echo "=== TODOs in codebase ==="
grep -rn "TODO\|FIXME\|HACK\|XXX" --include="*.py" --include="*.js" --include="*.ts" --include="*.go" --include="*.rs" . || true
echo "=== Count ==="
grep -rc "TODO\|FIXME\|HACK\|XXX" --include="*.py" --include="*.js" --include="*.ts" --include="*.go" --include="*.rs" . || true
continue-on-error: true
# ==============================
# BUILD & TEST
# ==============================
build-test:
name: 🔨 Build & Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [detected]
steps:
- name: Checkout code
uses: actions/checkout@v4
# ==========================
# Python
# ==========================
- name: Setup Python
if: hashFiles('requirements.txt') != '' || hashFiles('setup.py') != '' || hashFiles('pyproject.toml') != ''
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install Python dependencies
if: hashFiles('requirements.txt') != '' || hashFiles('setup.py') != '' || hashFiles('pyproject.toml') != ''
run: |
pip install -r requirements.txt || true
pip install pytest pytest-cov || true
- name: Run Python tests
if: hashFiles('requirements.txt') != '' || hashFiles('setup.py') != '' || hashFiles('pyproject.toml') != ''
run: |
pytest --cov=. --cov-report=xml || echo "Tests failed or none found"
continue-on-error: true
# ==========================
# Node.js
# ==========================
- name: Setup Node.js
if: hashFiles('package.json') != ''
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install Node dependencies
if: hashFiles('package.json') != ''
run: npm ci || npm install
- name: Run Node.js tests
if: hashFiles('package.json') != ''
run: npm test || echo "Tests failed or none found"
continue-on-error: true
- name: Build check
if: hashFiles('package.json') != ''
run: npm run build || echo "Build failed or no build script"
continue-on-error: true
# ==========================
# Go
# ==========================
- name: Setup Go
if: hashFiles('go.mod') != ''
uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true
- name: Download Go dependencies
if: hashFiles('go.mod') != ''
run: go mod download
- name: Run Go tests
if: hashFiles('go.mod') != ''
run: |
go test -v -coverprofile=coverage.out ./... || echo "Go tests failed or none found"
continue-on-error: true
- name: Build Go binary
if: hashFiles('go.mod') != ''
run: go build -v ./... || echo "Go build failed"
continue-on-error: true
# ==========================
# Rust
# ==========================
- name: Setup Rust
if: hashFiles('Cargo.toml') != ''
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run Rust tests
if: hashFiles('Cargo.toml') != ''
run: cargo test || echo "Rust tests failed or none found"
continue-on-error: true
- name: Build Rust binary
if: hashFiles('Cargo.toml') != ''
run: cargo build || echo "Rust build failed"
continue-on-error: true
# ==========================
# Flutter
# ==========================
- name: Setup Flutter
if: hashFiles('pubspec.yaml') != ''
uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'
cache: true
- name: Install Flutter dependencies
if: hashFiles('pubspec.yaml') != ''
run: flutter pub get
- name: Run Flutter tests
if: hashFiles('pubspec.yaml') != ''
run: flutter test || echo "Flutter tests failed or none found"
continue-on-error: true
- name: Analyze Flutter code
if: hashFiles('pubspec.yaml') != ''
run: flutter analyze || echo "Flutter analysis issues found"
continue-on-error: true
# ==============================
# DOCKER BUILD (if Dockerfile exists)
# ==============================
docker:
name: 🐳 Docker Build
runs-on: ubuntu-latest
if: hashFiles('Dockerfile') != '' || hashFiles('docker-compose.yml') != ''
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: openlake/${{ github.event.repository.name }}:pr-${{ github.event.pull_request.number }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ==============================
# PR COMMENT
# ==============================
pr-comment:
name: 💬 PR Status Comment
runs-on: ubuntu-latest
needs: [security, code-quality, build-test, docker]
if: always()
steps:
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const needs = ${{ toJSON(needs) }};
let status = "✅";
let summary = "All checks passed!";
for (const [job, result] of Object.entries(needs)) {
if (result.result === 'failure') {
status = "❌";
summary = `Job '${job}' failed.`;
break;
} else if (result.result === 'cancelled') {
status = "⚠️";
summary = `Job '${job}' was cancelled.`;
}
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${status} **OpenLake CI Status**: ${summary}\n\n` +
`Run #${context.runNumber} | [View Logs](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`
});