Skip to content

Commit acd9ce5

Browse files
authored
Merge pull request #16 from rulego/dev
Dev
2 parents 79e586a + 9ab28cb commit acd9ce5

27 files changed

+7492
-278
lines changed

.github/workflows/ci.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master, develop ]
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
go-version: ['1.19', '1.20', '1.21']
16+
17+
steps:
18+
- name: Set up Go ${{ matrix.go-version }}
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: ${{ matrix.go-version }}
22+
23+
- name: Check out code
24+
uses: actions/checkout@v4
25+
26+
- name: Cache Go modules
27+
uses: actions/cache@v3
28+
with:
29+
path: ~/go/pkg/mod
30+
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
31+
restore-keys: |
32+
${{ runner.os }}-go-${{ matrix.go-version }}-
33+
34+
- name: Download dependencies
35+
run: go mod download
36+
37+
- name: Verify dependencies
38+
run: go mod verify
39+
40+
- name: Build
41+
run: go build -v ./...
42+
43+
- name: Run tests
44+
run: go test -v -race -timeout 30s ./...
45+
46+
- name: Run tests with coverage
47+
if: matrix.go-version == '1.21'
48+
run: go test -v -race -coverprofile=coverage.out -covermode=atomic -timeout 30s ./...
49+
50+
- name: Upload coverage to Codecov
51+
if: matrix.go-version == '1.21'
52+
uses: codecov/codecov-action@v3
53+
with:
54+
file: ./coverage.out
55+
flags: unittests
56+
name: codecov-umbrella
57+
58+
case-expression-tests:
59+
name: CASE Expression Tests
60+
runs-on: ubuntu-latest
61+
62+
steps:
63+
- name: Set up Go
64+
uses: actions/setup-go@v4
65+
with:
66+
go-version: '1.21'
67+
68+
- name: Check out code
69+
uses: actions/checkout@v4
70+
71+
- name: Cache Go modules
72+
uses: actions/cache@v3
73+
with:
74+
path: ~/go/pkg/mod
75+
key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }}
76+
77+
- name: Download dependencies
78+
run: go mod download
79+
80+
- name: Run CASE Expression Parsing Tests
81+
run: go test -v -run TestCaseExpressionParsing -timeout 15s
82+
83+
- name: Run CASE Expression Comprehensive Tests
84+
run: go test -v -run TestCaseExpressionComprehensive -timeout 15s
85+
86+
- name: Run CASE Expression Field Extraction Tests
87+
run: go test -v -run TestCaseExpressionFieldExtraction -timeout 15s
88+
89+
- name: Run CASE Expression in SQL Tests
90+
run: go test -v -run TestCaseExpressionInSQL -timeout 15s
91+
92+
- name: Run CASE Expression Aggregation Tests (with known limitations)
93+
run: go test -v -run "TestCaseExpressionInAggregation|TestComplexCaseExpressionsInAggregation" -timeout 20s
94+
95+
- name: Run CASE Expression Edge Cases
96+
run: go test -v -run TestCaseExpressionEdgeCases -timeout 15s
97+
98+
lint:
99+
name: Lint
100+
runs-on: ubuntu-latest
101+
102+
steps:
103+
- name: Set up Go
104+
uses: actions/setup-go@v4
105+
with:
106+
go-version: '1.21'
107+
108+
- name: Check out code
109+
uses: actions/checkout@v4
110+
111+
- name: Run golangci-lint
112+
uses: golangci/golangci-lint-action@v3
113+
with:
114+
version: latest
115+
args: --timeout=5m
116+
117+
security:
118+
name: Security Scan
119+
runs-on: ubuntu-latest
120+
121+
steps:
122+
- name: Set up Go
123+
uses: actions/setup-go@v4
124+
with:
125+
go-version: '1.21'
126+
127+
- name: Check out code
128+
uses: actions/checkout@v4
129+
130+
- name: Run Gosec Security Scanner
131+
uses: securecodewarrior/github-action-gosec@v1
132+
with:
133+
args: './...'

.github/workflows/release.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
test:
10+
name: Test Before Release
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Set up Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: '1.21'
18+
19+
- name: Check out code
20+
uses: actions/checkout@v4
21+
22+
- name: Cache Go modules
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/go/pkg/mod
26+
key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }}
27+
28+
- name: Download dependencies
29+
run: go mod download
30+
31+
- name: Run all tests
32+
run: go test -v -race -timeout 30s ./...
33+
34+
- name: Run CASE expression tests specifically
35+
run: |
36+
echo "Testing CASE expression functionality..."
37+
go test -v -run TestCaseExpression -timeout 20s
38+
39+
release:
40+
name: Create Release
41+
runs-on: ubuntu-latest
42+
needs: test
43+
44+
steps:
45+
- name: Check out code
46+
uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
50+
- name: Set up Go
51+
uses: actions/setup-go@v4
52+
with:
53+
go-version: '1.21'
54+
55+
- name: Cache Go modules
56+
uses: actions/cache@v3
57+
with:
58+
path: ~/go/pkg/mod
59+
key: ${{ runner.os }}-go-1.21-${{ hashFiles('**/go.sum') }}
60+
61+
- name: Download dependencies
62+
run: go mod download
63+
64+
- name: Build binaries
65+
run: |
66+
# Build for multiple platforms
67+
GOOS=linux GOARCH=amd64 go build -o streamsql-linux-amd64 ./...
68+
GOOS=windows GOARCH=amd64 go build -o streamsql-windows-amd64.exe ./...
69+
GOOS=darwin GOARCH=amd64 go build -o streamsql-darwin-amd64 ./...
70+
GOOS=darwin GOARCH=arm64 go build -o streamsql-darwin-arm64 ./...
71+
72+
- name: Generate changelog
73+
id: changelog
74+
run: |
75+
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
76+
echo "## 🚀 StreamSQL $(echo ${{ github.ref }} | sed 's/refs\/tags\///')" >> $GITHUB_OUTPUT
77+
echo "" >> $GITHUB_OUTPUT
78+
echo "### ✨ 新增功能" >> $GITHUB_OUTPUT
79+
echo "- 完善的CASE表达式支持" >> $GITHUB_OUTPUT
80+
echo "- 多条件逻辑表达式 (AND, OR)" >> $GITHUB_OUTPUT
81+
echo "- 数学函数集成" >> $GITHUB_OUTPUT
82+
echo "- 字段提取和引用功能" >> $GITHUB_OUTPUT
83+
echo "" >> $GITHUB_OUTPUT
84+
echo "### 🔧 改进" >> $GITHUB_OUTPUT
85+
echo "- 负数解析优化" >> $GITHUB_OUTPUT
86+
echo "- 字符串和数值混合比较" >> $GITHUB_OUTPUT
87+
echo "- 表达式解析性能提升" >> $GITHUB_OUTPUT
88+
echo "" >> $GITHUB_OUTPUT
89+
echo "### 📋 测试覆盖" >> $GITHUB_OUTPUT
90+
echo "- ✅ 基础CASE表达式解析" >> $GITHUB_OUTPUT
91+
echo "- ✅ 复杂条件组合" >> $GITHUB_OUTPUT
92+
echo "- ✅ 函数调用支持" >> $GITHUB_OUTPUT
93+
echo "- ✅ 字段提取功能" >> $GITHUB_OUTPUT
94+
echo "- ⚠️ 聚合函数中的使用 (部分支持)" >> $GITHUB_OUTPUT
95+
echo "" >> $GITHUB_OUTPUT
96+
echo "---" >> $GITHUB_OUTPUT
97+
echo "📖 **完整文档**: [README.md](README.md) | [中文文档](README_ZH.md)" >> $GITHUB_OUTPUT
98+
echo "EOF" >> $GITHUB_OUTPUT
99+
100+
- name: Create Release
101+
uses: softprops/action-gh-release@v1
102+
with:
103+
body: ${{ steps.changelog.outputs.CHANGELOG }}
104+
files: |
105+
streamsql-linux-amd64
106+
streamsql-windows-amd64.exe
107+
streamsql-darwin-amd64
108+
streamsql-darwin-arm64
109+
draft: false
110+
prerelease: false
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,4 @@ vendor/
4343
# coverage file
4444
coverage.html
4545

46-
examples/server/rules/
47-
examples/server/js/
48-
examples/server/plugins/
46+
streamsql_overflow_data

.golangci.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
run:
2+
timeout: 5m
3+
modules-download-mode: readonly
4+
5+
linters:
6+
enable:
7+
- gofmt
8+
- goimports
9+
- govet
10+
- ineffassign
11+
- misspell
12+
- gosimple
13+
- staticcheck
14+
- unused
15+
- typecheck
16+
- errcheck
17+
- gosec
18+
- gocritic
19+
- gocyclo
20+
- gofumpt
21+
- godot
22+
- goprintffuncname
23+
- gomodguard
24+
- revive
25+
26+
linters-settings:
27+
gocyclo:
28+
min-complexity: 15
29+
30+
gosec:
31+
excludes:
32+
- G404 # 随机数生成器可能不是密码学安全的
33+
34+
gocritic:
35+
enabled-tags:
36+
- diagnostic
37+
- style
38+
- performance
39+
disabled-checks:
40+
- unnamedResult
41+
- whyNoLint
42+
43+
revive:
44+
rules:
45+
- name: exported
46+
disabled: false
47+
arguments:
48+
- "checkPrivateReceivers"
49+
- "sayRepetitiveInsteadOfStutters"
50+
51+
issues:
52+
exclude-rules:
53+
# 排除测试文件中的某些检查
54+
- path: _test\.go
55+
linters:
56+
- gosec
57+
- errcheck
58+
- gocyclo
59+
60+
# 排除CASE表达式测试中的复杂度检查
61+
- path: streamsql_case_test\.go
62+
linters:
63+
- gocyclo
64+
- funlen
65+
66+
# 排除generated文件
67+
- path: ".*\\.pb\\.go"
68+
linters:
69+
- all
70+
71+
exclude:
72+
# 排除一些常见的false positive
73+
- "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*print.*|os\\.(Un)?Setenv). is not checked"
74+
- "should have a package comment"
75+
76+
output:
77+
format: colored-line-number
78+
print-issued-lines: true
79+
print-linter-name: true

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# StreamSQL
2+
[![GoDoc](https://pkg.go.dev/badge/github.com/rulego/streamsql)](https://pkg.go.dev/github.com/rulego/streamsql)
3+
[![Go Report](https://goreportcard.com/badge/github.com/rulego/streamsql)](https://goreportcard.com/report/github.com/rulego/streamsql)
4+
[![ci](https://github.com/rulego/streamsql/workflows/test/badge.svg)](https://github.com/rulego/streamsql/actions/workflows/ci.yml)
5+
[![build](https://github.com/rulego/streamsql/workflows/release/badge.svg)](https://github.com/rulego/streamsql/actions/workflows/release.yml)
26

37
English| [简体中文](README_ZH.md)
48

README_ZH.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# StreamSQL
2+
[![GoDoc](https://pkg.go.dev/badge/github.com/rulego/streamsql)](https://pkg.go.dev/github.com/rulego/streamsql)
3+
[![Go Report](https://goreportcard.com/badge/github.com/rulego/streamsql)](https://goreportcard.com/report/github.com/rulego/streamsql)
4+
[![ci](https://github.com/rulego/streamsql/workflows/test/badge.svg)](https://github.com/rulego/streamsql/actions/workflows/ci.yml)
5+
[![build](https://github.com/rulego/streamsql/workflows/release/badge.svg)](https://github.com/rulego/streamsql/actions/workflows/release.yml)
26

37
[English](README.md)| 简体中文
48

0 commit comments

Comments
 (0)