feat(环境): 添加单元测试 CI #32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Checker | |
on: | |
push: | |
pull_request: | |
branches: [ "dev" ] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
java: [ '8', '11', '17' ] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK ${{ matrix.java }} | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ matrix.java }} | |
distribution: 'temurin' | |
cache: maven | |
- name: Check Code Style | |
run: ./mvnw checkstyle:check | |
- name: Check Spotbugs | |
run: ./mvnw spotbugs:check | |
# 添加单元测试步骤 | |
- name: Run Unit Tests | |
run: ./mvnw -B test | |
# 生成测试覆盖率报告 | |
- name: Generate Test Coverage Report | |
run: ./mvnw -B verify jacoco:report | |
- name: Build with Maven | |
run: ./mvnw -B clean package | |
# 使用 actions/test-reporter 展示测试结果 | |
- name: Publish Test Results | |
uses: dorny/test-reporter@v1 | |
if: always() | |
with: | |
name: JUnit Tests (${{ matrix.java }}) | |
path: target/surefire-reports/*.xml | |
reporter: java-junit | |
fail-on-error: true | |
- name: Upload Test Results | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: test-results-${{ matrix.java }} | |
path: target/surefire-reports/ | |
- name: Upload Coverage Report | |
if: matrix.java == '8' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-report | |
path: target/site/jacoco/ | |
- name: Report Coverage to Codecov | |
if: matrix.java == '8' | |
uses: codecov/codecov-action@v3 | |
with: | |
file: target/site/jacoco/jacoco.xml | |
dependency-check: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '8' | |
distribution: 'temurin' | |
cache: maven | |
- name: Run Dependency Check | |
run: ./mvnw org.owasp:dependency-check-maven:check | |
- name: Upload Dependency Check Results | |
if: always() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dependency-check-report | |
path: target/dependency-check-report.html |