Skip to content

Commit

Permalink
feat: add automatic unit tests for pull requests apache#762
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterZephyr committed Jan 12, 2025
1 parent 5675b29 commit c43516e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@ jobs:
- name: "run go build"
run: go build -v ./...

- name: "run go test and out codecov"
run: go test -v ./... -race -coverprofile=coverage.out -covermode=atomic

- name: "upload coverage"
uses: codecov/codecov-action@v3
40 changes: 29 additions & 11 deletions .github/workflows/integrate-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
branches: [ master ]
pull_request:
branches: "*"
types: [opened, synchronize, reopened] # 明确指定 PR 事件类型

permissions:
contents: read
Expand Down Expand Up @@ -61,15 +62,32 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
# add Unit Test
- name: "Run Unit Tests"
run: |
echo "Running unit tests..."
go test -v ./... -coverprofile=coverage.txt -covermode=atomic
if [ $? -ne 0 ]; then
echo "Unit tests failed"
exit 1
fi
echo "Unit tests completed successfully"
# Upload Coverage
- name: "Upload Coverage"
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
flags: unittests

# This step only runs when the event type is a pull_request
# - name: Integrate Test
# if: ${{ github.event_name == 'pull_request' }}
# run: |
# 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}}
#
# # This step only runs when the event type is a push
# - name: Integrate Test
# if: ${{ github.event_name == 'push' }}
# run: |
# chmod +x integrate_test.sh && ./integrate_test.sh $GITHUB_REPOSITORY $GITHUB_SHA $GITHUB_BASE_REF
#
- name: Integrate Test
if: ${{ github.event_name == 'pull_request' }}
run: |
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}}
# This step only runs when the event type is a push
- name: Integrate Test
if: ${{ github.event_name == 'push' }}
run: |
chmod +x integrate_test.sh && ./integrate_test.sh $GITHUB_REPOSITORY $GITHUB_SHA $GITHUB_BASE_REF

0 comments on commit c43516e

Please sign in to comment.