From 6a1c1cc6b65c2521698b7fa6bf9015a52d530b48 Mon Sep 17 00:00:00 2001 From: lhpqaq <657407891@qq.com> Date: Wed, 28 Aug 2024 14:25:14 +0800 Subject: [PATCH] ci: add ci --- .github/workflows/ci.yml | 72 +++++++++++++++++++ biz/service/blog/delete_blog_test.go | 1 - .../blog_comment/delete_comment_test.go | 1 - biz/service/blog_comment/like_comment_test.go | 1 - script/build.sh | 7 ++ script/test.sh | 12 ++++ 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100755 script/build.sh create mode 100755 script/test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3a13885 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,72 @@ +name: xzdp CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + fmt: + name: Run go fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.22 + + - name: Run go fmt + run: | + fmt_output=$(go fmt ./...) + if [ -n "$fmt_output" ]; then + echo "The following files need to be formatted:" + echo "$fmt_output" + exit 1 + fi + + build: + name: Build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.22 + + - name: Install dependencies + run: go mod tidy + + - name: Build + run: ./script/build.sh + + test: + name: Run tests + runs-on: ubuntu-latest + needs: build + services: + redis: + image: redis:latest + ports: + - 6379:6379 + + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.22 + + - name: Install dependencies + run: go mod tidy + + - name: Run tests + env: + REDIS_HOST: 127.0.0.1 + REDIS_PORT: 6379 + run: ./script/test.sh \ No newline at end of file diff --git a/biz/service/blog/delete_blog_test.go b/biz/service/blog/delete_blog_test.go index a09a496..30f2458 100644 --- a/biz/service/blog/delete_blog_test.go +++ b/biz/service/blog/delete_blog_test.go @@ -6,7 +6,6 @@ import ( "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/common/test/assert" - blog "xzdp/biz/model/blog" ) func TestDeleteBlogService_Run(t *testing.T) { diff --git a/biz/service/blog_comment/delete_comment_test.go b/biz/service/blog_comment/delete_comment_test.go index da39f39..9171acf 100644 --- a/biz/service/blog_comment/delete_comment_test.go +++ b/biz/service/blog_comment/delete_comment_test.go @@ -6,7 +6,6 @@ import ( "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/common/test/assert" - blog_comment "xzdp/biz/model/blog_comment" ) func TestDeleteCommentService_Run(t *testing.T) { diff --git a/biz/service/blog_comment/like_comment_test.go b/biz/service/blog_comment/like_comment_test.go index cd7991e..7161c17 100644 --- a/biz/service/blog_comment/like_comment_test.go +++ b/biz/service/blog_comment/like_comment_test.go @@ -6,7 +6,6 @@ import ( "github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/common/test/assert" - blog_comment "xzdp/biz/model/blog_comment" ) func TestLikeCommentService_Run(t *testing.T) { diff --git a/script/build.sh b/script/build.sh new file mode 100755 index 0000000..e289bbe --- /dev/null +++ b/script/build.sh @@ -0,0 +1,7 @@ +#!/bin/bash +if [ ! -f conf/test/conf.yaml ]; then + cp conf/test/conf.example.yaml conf/test/conf.yaml + echo "conf/test/conf.yaml has been created from conf/test/conf.example.yaml" +fi + +go build -v xzdp \ No newline at end of file diff --git a/script/test.sh b/script/test.sh new file mode 100755 index 0000000..4bbb2da --- /dev/null +++ b/script/test.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# 运行构建脚本 +sh ./script/build.sh + +# 测试 ./xzdp 是否能正常运行,运行2秒后退出 +timeout 2s ./xzdp & +sleep 2 +kill $! + +# 单元测试未编写,暂时只测试能否正确运行 +# go test -v -cover ./... \ No newline at end of file