ci: 更新CI/CD工作流配置并移除旧的工作流 #1
Workflow file for this run
This file contains hidden or 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: Backend CI | |
| # Trigger: PR to main/develop branches, only when backend files change | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| paths: | |
| - 'himarket-dal/**' | |
| - 'himarket-server/**' | |
| - 'himarket-bootstrap/**' | |
| - 'pom.xml' | |
| - '.github/workflows/backend-ci.yml' | |
| # Avoid duplicate runs: new commits to the same PR will cancel previous runs | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| # Limit workflow permissions (security best practice) | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| checks: write | |
| jobs: | |
| # Job 1: Code Format Check | |
| code-format-check: | |
| name: Code Format Check (Spotless) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Run Spotless format check | |
| run: mvn spotless:check | |
| continue-on-error: false | |
| - name: PR Comment - Format check failed | |
| if: failure() && github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: '## ❌ Code Format Check Failed\n\n' + | |
| 'Your code does not follow the project formatting standards.\n\n' + | |
| '**Please run the following command to fix formatting issues:**\n' + | |
| '```bash\n' + | |
| 'mvn spotless:apply\n' + | |
| '```\n\n' + | |
| '**Then commit the changes:**\n' + | |
| '```bash\n' + | |
| 'git add .\n' + | |
| 'git commit -m "style: format code with spotless"\n' + | |
| 'git push\n' + | |
| '```\n\n' + | |
| 'The format check will automatically re-run after you push.' | |
| }); | |
| # Job 2: Maven Build Check (skip tests) | |
| build-check: | |
| name: Maven Build Check | |
| runs-on: ubuntu-latest | |
| needs: code-format-check # Ensure format check passes before building | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Maven build (skip tests) | |
| run: mvn clean package -DskipTests -B | |
| - name: Upload build artifacts | |
| if: success() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: backend-build-artifacts | |
| path: | | |
| himarket-bootstrap/target/*.jar | |
| !himarket-bootstrap/target/*-sources.jar | |
| !himarket-bootstrap/target/*-javadoc.jar | |
| retention-days: 7 | |
| # Job 3: Unit Tests | |
| unit-tests: | |
| name: Unit Tests | |
| runs-on: ubuntu-latest | |
| needs: build-check | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| cache: 'maven' | |
| - name: Run unit tests | |
| run: mvn test -B | |
| - name: Generate test report | |
| if: always() | |
| uses: dorny/test-reporter@v1 | |
| with: | |
| name: Backend Test Report | |
| path: '**/target/surefire-reports/*.xml' | |
| reporter: java-junit | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: backend-test-results | |
| path: | | |
| **/target/surefire-reports/ | |
| **/target/test-results/ | |
| retention-days: 7 | |
| # Summary of all check results | |
| backend-ci-summary: | |
| name: Backend CI Summary | |
| runs-on: ubuntu-latest | |
| needs: [code-format-check, build-check, unit-tests] | |
| if: always() | |
| steps: | |
| - name: Check all task status | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const jobs = [ | |
| { name: 'Code Format Check', status: '${{ needs.code-format-check.result }}' }, | |
| { name: 'Maven Build Check', status: '${{ needs.build-check.result }}' }, | |
| { name: 'Unit Tests', status: '${{ needs.unit-tests.result }}' } | |
| ]; | |
| let summary = '## 🔍 Backend CI Check Summary\n\n'; | |
| let allPassed = true; | |
| jobs.forEach(job => { | |
| const icon = job.status === 'success' ? '✅' : '❌'; | |
| summary += `${icon} **${job.name}**: ${job.status}\n`; | |
| if (job.status !== 'success') { | |
| allPassed = false; | |
| } | |
| }); | |
| summary += '\n---\n\n'; | |
| if (allPassed) { | |
| summary += '🎉 **All checks passed!** Your PR is ready for review.\n'; | |
| } else { | |
| summary += '⚠️ **Some checks failed**. Please review the failed tasks above and fix the issues.\n'; | |
| } | |
| await core.summary | |
| .addRaw(summary) | |
| .write(); | |
| console.log(summary); | |
| if (!allPassed) { | |
| core.setFailed('Some backend CI checks failed'); | |
| } | |