Skip to content

Commit c43516e

Browse files
committed
feat: add automatic unit tests for pull requests apache#762
1 parent 5675b29 commit c43516e

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

.github/workflows/build.yml

-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,5 @@ jobs:
6161
- name: "run go build"
6262
run: go build -v ./...
6363

64-
- name: "run go test and out codecov"
65-
run: go test -v ./... -race -coverprofile=coverage.out -covermode=atomic
66-
6764
- name: "upload coverage"
6865
uses: codecov/codecov-action@v3

.github/workflows/integrate-test.yml

+29-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ on:
2323
branches: [ master ]
2424
pull_request:
2525
branches: "*"
26+
types: [opened, synchronize, reopened] # 明确指定 PR 事件类型
2627

2728
permissions:
2829
contents: read
@@ -61,15 +62,32 @@ jobs:
6162
restore-keys: |
6263
${{ runner.os }}-go-
6364
65+
# add Unit Test
66+
- name: "Run Unit Tests"
67+
run: |
68+
echo "Running unit tests..."
69+
go test -v ./... -coverprofile=coverage.txt -covermode=atomic
70+
if [ $? -ne 0 ]; then
71+
echo "Unit tests failed"
72+
exit 1
73+
fi
74+
echo "Unit tests completed successfully"
75+
76+
# Upload Coverage
77+
- name: "Upload Coverage"
78+
uses: codecov/codecov-action@v3
79+
with:
80+
file: ./coverage.txt
81+
flags: unittests
82+
6483
# This step only runs when the event type is a pull_request
65-
# - name: Integrate Test
66-
# if: ${{ github.event_name == 'pull_request' }}
67-
# run: |
68-
# chmod +x integrate_test.sh && [[ -n "${{github.event.pull_request.head.repo.full_name}}" ]] && [[ -n "${{github.event.pull_request.head.sha}}" ]] && [[ -n "${{github.base_ref}}" ]] && ./integrate_test.sh ${{github.event.pull_request.head.repo.full_name}} ${{github.event.pull_request.head.sha}} ${{github.base_ref}}
69-
#
70-
# # This step only runs when the event type is a push
71-
# - name: Integrate Test
72-
# if: ${{ github.event_name == 'push' }}
73-
# run: |
74-
# chmod +x integrate_test.sh && ./integrate_test.sh $GITHUB_REPOSITORY $GITHUB_SHA $GITHUB_BASE_REF
75-
#
84+
- name: Integrate Test
85+
if: ${{ github.event_name == 'pull_request' }}
86+
run: |
87+
chmod +x integrate_test.sh && [[ -n "${{github.event.pull_request.head.repo.full_name}}" ]] && [[ -n "${{github.event.pull_request.head.sha}}" ]] && [[ -n "${{github.base_ref}}" ]] && ./integrate_test.sh ${{github.event.pull_request.head.repo.full_name}} ${{github.event.pull_request.head.sha}} ${{github.base_ref}}
88+
89+
# This step only runs when the event type is a push
90+
- name: Integrate Test
91+
if: ${{ github.event_name == 'push' }}
92+
run: |
93+
chmod +x integrate_test.sh && ./integrate_test.sh $GITHUB_REPOSITORY $GITHUB_SHA $GITHUB_BASE_REF

0 commit comments

Comments
 (0)