Skip to content

Commit

Permalink
ci: add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Aug 28, 2024
1 parent 1b77703 commit 6a1c1cc
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 3 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion biz/service/blog/delete_blog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion biz/service/blog_comment/delete_comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion biz/service/blog_comment/like_comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions script/build.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions script/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# 运行构建脚本
sh ./script/build.sh

# 测试 ./xzdp 是否能正常运行,运行2秒后退出
timeout 2s ./xzdp &
sleep 2
kill $!

# 单元测试未编写,暂时只测试能否正确运行
# go test -v -cover ./...

0 comments on commit 6a1c1cc

Please sign in to comment.