mirror of
https://gitee.com/samwaf/SamWaf.git
synced 2026-10-30 17:51:44 +08:00
ci:pre check
This commit is contained in:
+27
-101
@@ -148,111 +148,37 @@ jobs:
|
||||
echo "Windows binary built successfully:"
|
||||
ls -lh SamWaf64.exe
|
||||
file SamWaf64.exe
|
||||
# # 代码质量检查
|
||||
# code-quality:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v4
|
||||
|
||||
# Docker 构建和测试
|
||||
build-and-test-docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
# - name: Set up Go
|
||||
# uses: actions/setup-go@v4
|
||||
# with:
|
||||
# go-version: '1.21.4'
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
# - name: Go mod verify
|
||||
# run: go mod verify
|
||||
|
||||
- name: Build Docker Image for amd64
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64
|
||||
push: false
|
||||
load: true
|
||||
tags: samwaf/samwaf:ci-test
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
# - name: Go vet
|
||||
# run: go vet ./...
|
||||
|
||||
- name: Test Docker Image
|
||||
timeout-minutes: 2
|
||||
run: |
|
||||
echo "Testing Docker image..."
|
||||
docker run -d --name=samwaf-ci-test \
|
||||
-p 26666:26666 \
|
||||
samwaf/samwaf:ci-test
|
||||
# - name: Install staticcheck
|
||||
# run: go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
|
||||
# 等待服务启动(最多等待30秒)
|
||||
echo "Waiting for service to start..."
|
||||
for i in {1..30}; do
|
||||
if curl -f http://localhost:26666 2>/dev/null; then
|
||||
echo "Service is up and running!"
|
||||
break
|
||||
fi
|
||||
if [ $i -eq 30 ]; then
|
||||
echo "Service failed to start within 30 seconds"
|
||||
docker logs samwaf-ci-test
|
||||
docker stop samwaf-ci-test
|
||||
docker rm samwaf-ci-test
|
||||
exit 1
|
||||
fi
|
||||
echo "Attempt $i/30: Service not ready yet, waiting..."
|
||||
sleep 1
|
||||
done
|
||||
# - name: Run staticcheck
|
||||
# run: staticcheck ./...
|
||||
# continue-on-error: true
|
||||
|
||||
# 执行健康检查
|
||||
echo "Performing health check..."
|
||||
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:26666)
|
||||
echo "HTTP Status Code: $HTTP_CODE"
|
||||
|
||||
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 500 ]; then
|
||||
echo "Health check passed!"
|
||||
else
|
||||
echo "Health check failed with status code: $HTTP_CODE"
|
||||
docker logs samwaf-ci-test
|
||||
docker stop samwaf-ci-test
|
||||
docker rm samwaf-ci-test
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 查看日志
|
||||
echo "=== Docker Container Logs ==="
|
||||
docker logs samwaf-ci-test
|
||||
|
||||
# 停止并移除容器
|
||||
docker stop samwaf-ci-test
|
||||
docker rm samwaf-ci-test
|
||||
echo "Docker test completed successfully"
|
||||
|
||||
# 代码质量检查
|
||||
code-quality:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.21.4'
|
||||
|
||||
- name: Go mod verify
|
||||
run: go mod verify
|
||||
|
||||
- name: Go vet
|
||||
run: go vet ./...
|
||||
|
||||
- name: Install staticcheck
|
||||
run: go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
|
||||
- name: Run staticcheck
|
||||
run: staticcheck ./...
|
||||
continue-on-error: true
|
||||
|
||||
- name: Check formatting
|
||||
run: |
|
||||
if [ -n "$(gofmt -s -l .)" ]; then
|
||||
echo "以下文件需要格式化:"
|
||||
gofmt -s -l .
|
||||
exit 1
|
||||
fi
|
||||
continue-on-error: true
|
||||
# - name: Check formatting
|
||||
# run: |
|
||||
# if [ -n "$(gofmt -s -l .)" ]; then
|
||||
# echo "以下文件需要格式化:"
|
||||
# gofmt -s -l .
|
||||
# exit 1
|
||||
# fi
|
||||
# continue-on-error: true
|
||||
|
||||
|
||||
@@ -175,7 +175,6 @@ func search(I []int, obuf, nbuf []byte, st, en int) (pos, n int) {
|
||||
} else {
|
||||
return search(I, obuf, nbuf, st, x)
|
||||
}
|
||||
panic("unreached")
|
||||
}
|
||||
|
||||
// Diff computes the difference between old and new, according to the bsdiff
|
||||
|
||||
Reference in New Issue
Block a user