Skip to content

Commit 3cee33f

Browse files
committed
2 parents bd434c6 + a746398 commit 3cee33f

22 files changed

Lines changed: 972 additions & 13 deletions

File tree

.DS_Store

0 Bytes
Binary file not shown.

.github/CI_README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# CI/CD 配置说明
2+
3+
## 概述
4+
5+
本仓库配置了 **轻量级 CI(持续集成),但**不包含 CD(持续部署)。
6+
7+
---
8+
9+
## 📋 为什么这样配置?
10+
11+
### ✅ 已添加:CI(持续集成)
12+
13+
**理由:**
14+
15+
| 功能 | 作用 |
16+
|------|------|
17+
| **C++ 编译检查** | 自动检查 `.cpp` 文件语法(仅提示,不阻止提交) |
18+
| **Python 语法检查** | 检查 Python 代码语法(仅提示,不阻止提交) |
19+
| **Go 编译检查** | 检查 Go 代码构建(仅提示,不阻止提交) |
20+
21+
**重要:这是信息性检查,不会阻止提交!**
22+
- 即使 LeetCode 代码缺少 `main` 函数或依赖预定义类型(如 `ListNode`),也能正常提交
23+
- CI 结果仅供参考,帮助你发现明显的语法错误
24+
- 不会因为检查失败而阻止合并 PR
25+
26+
---
27+
28+
### ❌ 不添加:CD(持续部署)
29+
30+
**理由:**
31+
32+
这是一个**算法学习笔记仓库**,不是需要部署到服务器的应用程序,因此不需要 CD。
33+
34+
---
35+
36+
## 🛠 CI 工作原理
37+
38+
```
39+
.github/
40+
├── workflows/
41+
│ └── ci.yml # GitHub Actions 主配置
42+
└── scripts/
43+
├── check_cpp.sh # C++ 编译检查脚本
44+
├── check_python.sh # Python 语法检查脚本
45+
└── check_go.sh # Go 编译检查脚本
46+
```
47+
48+
**触发时机:**
49+
- 推送到 `main` / `master` 分支
50+
- 创建 PR 到 `main` / `master` 分支
51+
52+
---
53+
54+
## 📊 包含的检查
55+
56+
| 语言 | 检查方式 | 标准 |
57+
|------|---------|------|
58+
| C++ | `g++ -fsyntax-only` | C++20 (gnu++20) |
59+
| Python | `py_compile` | Python 3.11 |
60+
| Go | `go build` | Go 1.21 |
61+
62+
---
63+
64+
## 🚀 如何使用?
65+
66+
CI 会自动运行,无需手动操作。
67+
68+
查看 CI 结果:
69+
1. 进入仓库的 **Actions** 标签页
70+
2. 点击对应的 workflow run
71+
3. 查看各 job 的详细输出
72+
73+
---
74+
75+
## 💡 本地测试(可选)
76+
77+
如果你想在本地运行检查:
78+
79+
```bash
80+
# C++ 检查
81+
.github/scripts/check_cpp.sh
82+
83+
# Python 检查
84+
.github/scripts/check_python.sh
85+
86+
# Go 检查
87+
.github/scripts/check_go.sh
88+
```

.github/scripts/check_cpp.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# set -e # Don't exit on error - this is informational only
3+
4+
echo "========================================="
5+
echo "C++ Compile Check"
6+
echo "========================================="
7+
8+
# Find all C++ files
9+
CPP_FILES=$(find . -type f \( -name "*.cpp" -o -name "*.cc" -o -name "*.cxx" \) \
10+
-not -path "./.git/*" \
11+
-not -path "./.github/*" \
12+
-not -path "./bits/*" \
13+
-not -path "./.cursor/*" \
14+
-not -path "./.cache/*" | head -100)
15+
16+
if [ -z "$CPP_FILES" ]; then
17+
echo "No C++ files found to check."
18+
exit 0
19+
fi
20+
21+
echo "Found $(echo "$CPP_FILES" | wc -l) C++ files (checking first 100)"
22+
echo ""
23+
24+
FAILED=0
25+
PASSED=0
26+
27+
for FILE in $CPP_FILES; do
28+
echo -n "Checking $FILE ... "
29+
30+
# Try to compile with syntax check only
31+
if g++ -std=gnu++20 -fsyntax-only -Wall -Wextra -I. "$FILE" 2>/dev/null; then
32+
echo "PASS"
33+
PASSED=$((PASSED + 1))
34+
else
35+
echo "FAIL"
36+
echo " Compile error details:"
37+
g++ -std=gnu++20 -fsyntax-only -Wall -Wextra -I. "$FILE" 2>&1 | sed 's/^/ /'
38+
FAILED=$((FAILED + 1))
39+
fi
40+
done
41+
42+
echo ""
43+
echo "========================================="
44+
echo "Results: $PASSED passed, $FAILED failed"
45+
echo "========================================="
46+
echo ""
47+
echo "Note: This check is informational only."
48+
echo "Even if some files fail, the workflow will continue."
49+
50+
# Always exit successfully - this is just an informational check
51+
exit 0

.github/scripts/check_go.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# set -e # Don't exit on error - this is informational only
3+
4+
echo "========================================="
5+
echo "Go Build Check"
6+
echo "========================================="
7+
8+
# Find all Go files
9+
GO_FILES=$(find . -type f -name "*.go" \
10+
-not -path "./.git/*" \
11+
-not -path "./.github/*" \
12+
-not -path "./.cursor/*" \
13+
-not -path "./.cache/*")
14+
15+
if [ -z "$GO_FILES" ]; then
16+
echo "No Go files found to check."
17+
exit 0
18+
fi
19+
20+
echo "Found $(echo "$GO_FILES" | wc -l) Go files"
21+
echo ""
22+
23+
# Check each Go file individually
24+
FAILED=0
25+
PASSED=0
26+
27+
for FILE in $GO_FILES; do
28+
echo -n "Checking $FILE ... "
29+
30+
# Create a temp directory for building
31+
TEMP_DIR=$(mktemp -d)
32+
cp "$FILE" "$TEMP_DIR/"
33+
BASENAME=$(basename "$FILE")
34+
35+
# Try to build
36+
if (cd "$TEMP_DIR" && go build -o /dev/null "$BASENAME" 2>/dev/null); then
37+
echo "PASS"
38+
PASSED=$((PASSED + 1))
39+
else
40+
echo "FAIL"
41+
echo " Build error details:"
42+
(cd "$TEMP_DIR" && go build -o /dev/null "$BASENAME" 2>&1) | sed 's/^/ /'
43+
FAILED=$((FAILED + 1))
44+
fi
45+
46+
rm -rf "$TEMP_DIR"
47+
done
48+
49+
echo ""
50+
echo "========================================="
51+
echo "Results: $PASSED passed, $FAILED failed"
52+
echo "========================================="
53+
echo ""
54+
echo "Note: This check is informational only."
55+
echo "Even if some files fail, the workflow will continue."
56+
57+
# Always exit successfully - this is just an informational check
58+
exit 0

.github/scripts/check_python.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# set -e # Don't exit on error - this is informational only
3+
4+
echo "========================================="
5+
echo "Python Syntax Check"
6+
echo "========================================="
7+
8+
# Find all Python files
9+
PY_FILES=$(find . -type f -name "*.py" \
10+
-not -path "./.git/*" \
11+
-not -path "./.github/*" \
12+
-not -path "./.cursor/*" \
13+
-not -path "./.cache/*" | head -100)
14+
15+
if [ -z "$PY_FILES" ]; then
16+
echo "No Python files found to check."
17+
exit 0
18+
fi
19+
20+
echo "Found $(echo "$PY_FILES" | wc -l) Python files (checking first 100)"
21+
echo ""
22+
23+
FAILED=0
24+
PASSED=0
25+
26+
for FILE in $PY_FILES; do
27+
echo -n "Checking $FILE ... "
28+
29+
# Check syntax without executing
30+
if python3 -m py_compile "$FILE" 2>/dev/null; then
31+
echo "PASS"
32+
PASSED=$((PASSED + 1))
33+
else
34+
echo "FAIL"
35+
echo " Syntax error details:"
36+
python3 -m py_compile "$FILE" 2>&1 | sed 's/^/ /'
37+
FAILED=$((FAILED + 1))
38+
fi
39+
done
40+
41+
# Clean up pycache
42+
find . -name "__pycache__" -type d -prune -exec rm -rf {} + 2>/dev/null || true
43+
find . -name "*.pyc" -delete 2>/dev/null || true
44+
45+
echo ""
46+
echo "========================================="
47+
echo "Results: $PASSED passed, $FAILED failed"
48+
echo "========================================="
49+
echo ""
50+
echo "Note: This check is informational only."
51+
echo "Even if some files fail, the workflow will continue."
52+
53+
# Always exit successfully - this is just an informational check
54+
exit 0

.github/workflows/ci.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
cpp-check:
15+
name: C++ Compile Check
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Install g++
21+
run: sudo apt-get update && sudo apt-get install -y g++
22+
23+
- name: Check C++ files
24+
run: |
25+
chmod +x .github/scripts/check_cpp.sh
26+
.github/scripts/check_cpp.sh
27+
28+
python-check:
29+
name: Python Syntax Check
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Set up Python
35+
uses: actions/setup-python@v5
36+
with:
37+
python-version: '3.11'
38+
39+
- name: Check Python files
40+
run: |
41+
chmod +x .github/scripts/check_python.sh
42+
.github/scripts/check_python.sh
43+
44+
go-check:
45+
name: Go Build Check
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
- name: Set up Go
51+
uses: actions/setup-go@v5
52+
with:
53+
go-version: '1.21'
54+
55+
- name: Check Go files
56+
run: |
57+
chmod +x .github/scripts/check_go.sh
58+
.github/scripts/check_go.sh

0 commit comments

Comments
 (0)