Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add automatic unit tests for pull requests #762 #1

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading