|
| 1 | +name: Backend build, format check, and coverage |
| 2 | + |
| 3 | +# Reusable workflow called from build.yml. Runs the full backend build matrix |
| 4 | +# (JDK 21/25 × spring-security on/off), Spotless formatting check, JUnit, and |
| 5 | +# posts Jacoco coverage to PRs. |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + actions: read |
| 12 | + security-events: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + jdk-version: [21, 25] |
| 22 | + spring-security: [true, false] |
| 23 | + steps: |
| 24 | + - name: Harden Runner |
| 25 | + uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1 |
| 26 | + with: |
| 27 | + egress-policy: audit |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 30 | + |
| 31 | + - name: Set up JDK ${{ matrix.jdk-version }} |
| 32 | + uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 |
| 33 | + with: |
| 34 | + java-version: ${{ matrix.jdk-version }} |
| 35 | + distribution: "temurin" |
| 36 | + |
| 37 | + - name: Cache Gradle dependency artifacts |
| 38 | + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4 |
| 39 | + with: |
| 40 | + path: | |
| 41 | + ~/.gradle/wrapper |
| 42 | + ~/.gradle/caches/modules-2/files-2.1 |
| 43 | + ~/.gradle/caches/modules-2/metadata-2.* |
| 44 | + key: gradle-deps-${{ runner.os }}-jdk-${{ matrix.jdk-version }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties', '**/*.gradle', '**/*.gradle.kts', 'settings.gradle', 'settings.gradle.kts', 'gradle/libs.versions.toml') }} |
| 45 | + |
| 46 | + - name: Setup Gradle |
| 47 | + uses: gradle/actions/setup-gradle@f29f5a9d7b09a7c6b29859002d29d24e1674c884 # v5.0.1 |
| 48 | + with: |
| 49 | + gradle-version: 9.3.1 |
| 50 | + cache-disabled: true |
| 51 | + |
| 52 | + - name: Install Task |
| 53 | + uses: go-task/setup-task@3be4020d41929789a01026e0e427a4321ce0ad44 # v2.0.0 |
| 54 | + - name: Check Java formatting (Spotless) |
| 55 | + if: matrix.jdk-version == 25 && matrix.spring-security == false |
| 56 | + id: spotless-check |
| 57 | + run: task backend:format:check |
| 58 | + continue-on-error: true |
| 59 | + env: |
| 60 | + MAVEN_USER: ${{ secrets.MAVEN_USER }} |
| 61 | + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} |
| 62 | + MAVEN_PUBLIC_URL: ${{ secrets.MAVEN_PUBLIC_URL }} |
| 63 | + |
| 64 | + - name: Comment on Java formatting failure |
| 65 | + # Only post a comment on PRs. github-script's PR helpers need an |
| 66 | + # issue/PR number, which doesn't exist on merge_group runs. |
| 67 | + if: steps.spotless-check.outcome == 'failure' && github.event_name == 'pull_request' |
| 68 | + continue-on-error: true |
| 69 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 |
| 70 | + with: |
| 71 | + script: | |
| 72 | + const marker = '<!-- java-formatting-check -->'; |
| 73 | + const body = [ |
| 74 | + marker, |
| 75 | + '### Java Formatting Check Failed', |
| 76 | + '', |
| 77 | + 'Your code has formatting issues. Run the following command to fix them:', |
| 78 | + '', |
| 79 | + '```bash', |
| 80 | + 'task backend:format', |
| 81 | + '```', |
| 82 | + '', |
| 83 | + 'Then commit and push the changes.', |
| 84 | + ].join('\n'); |
| 85 | + const { data: comments } = await github.rest.issues.listComments({ |
| 86 | + owner: context.repo.owner, |
| 87 | + repo: context.repo.repo, |
| 88 | + issue_number: context.issue.number, |
| 89 | + }); |
| 90 | + const existing = comments.find(c => c.body.includes(marker)); |
| 91 | + if (existing) { |
| 92 | + await github.rest.issues.updateComment({ |
| 93 | + owner: context.repo.owner, |
| 94 | + repo: context.repo.repo, |
| 95 | + comment_id: existing.id, |
| 96 | + body, |
| 97 | + }); |
| 98 | + } else { |
| 99 | + await github.rest.issues.createComment({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + issue_number: context.issue.number, |
| 103 | + body, |
| 104 | + }); |
| 105 | + } |
| 106 | +
|
| 107 | + - name: Fail if Java formatting issues found |
| 108 | + if: steps.spotless-check.outcome == 'failure' |
| 109 | + run: | |
| 110 | + echo "============================================" |
| 111 | + echo " Java Formatting Check Failed" |
| 112 | + echo "============================================" |
| 113 | + echo "" |
| 114 | + echo "Your code has formatting issues." |
| 115 | + echo "Run the following command to fix them:" |
| 116 | + echo "" |
| 117 | + echo " task backend:format" |
| 118 | + echo "" |
| 119 | + echo "Then commit and push the changes." |
| 120 | + echo "============================================" |
| 121 | + exit 1 |
| 122 | +
|
| 123 | + - name: Build with Gradle and spring security ${{ matrix.spring-security }} |
| 124 | + run: task backend:build:ci |
| 125 | + env: |
| 126 | + MAVEN_USER: ${{ secrets.MAVEN_USER }} |
| 127 | + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} |
| 128 | + MAVEN_PUBLIC_URL: ${{ secrets.MAVEN_PUBLIC_URL }} |
| 129 | + DISABLE_ADDITIONAL_FEATURES: ${{ matrix.spring-security }} |
| 130 | + |
| 131 | + - name: Check Test Reports Exist |
| 132 | + if: always() |
| 133 | + run: | |
| 134 | + declare -a dirs=( |
| 135 | + "app/core/build/reports/tests/" |
| 136 | + "app/core/build/test-results/" |
| 137 | + "app/common/build/reports/tests/" |
| 138 | + "app/common/build/test-results/" |
| 139 | + "app/proprietary/build/reports/tests/" |
| 140 | + "app/proprietary/build/test-results/" |
| 141 | + ) |
| 142 | + for dir in "${dirs[@]}"; do |
| 143 | + if [ ! -d "$dir" ]; then |
| 144 | + echo "Missing $dir" |
| 145 | + exit 1 |
| 146 | + fi |
| 147 | + done |
| 148 | +
|
| 149 | + - name: Upload Test Reports |
| 150 | + if: always() |
| 151 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 152 | + with: |
| 153 | + name: test-reports-jdk-${{ matrix.jdk-version }}-spring-security-${{ matrix.spring-security }} |
| 154 | + path: | |
| 155 | + app/**/build/reports/jacoco/test |
| 156 | + app/**/build/reports/tests/ |
| 157 | + app/**/build/test-results/ |
| 158 | + app/**/build/reports/problems/ |
| 159 | + build/reports/problems/ |
| 160 | + retention-days: 3 |
| 161 | + if-no-files-found: warn |
| 162 | + |
| 163 | + - name: Add coverage to PR with spring security ${{ matrix.spring-security }} and JDK ${{ matrix.jdk-version }} |
| 164 | + # The action only supports the pull_request event (it posts a PR comment), |
| 165 | + # so skip it for merge_group runs and workflow_dispatch. |
| 166 | + if: github.event_name == 'pull_request' |
| 167 | + id: jacoco |
| 168 | + uses: madrapps/jacoco-report@50d3aff4548aa991e6753342d9ba291084e63848 # v1.7.2 |
| 169 | + with: |
| 170 | + paths: | |
| 171 | + ${{ github.workspace }}/**/build/reports/jacoco/test/jacocoTestReport.xml |
| 172 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 173 | + min-coverage-overall: 10 |
| 174 | + min-coverage-changed-files: 0 |
| 175 | + comment-type: summary |
0 commit comments