ci: only run spotbugs for changed modules #2650
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: verify | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| jobs: | |
| # Job 1: PMD (runs independently and in parallel) | |
| pmd: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: PMD | |
| uses: pmd/pmd-github-action@v2.0.0 | |
| id: pmd | |
| with: | |
| version: '7.17.0' | |
| rulesets: 'ddk-configuration/pmd/ruleset.xml' | |
| analyzeModifiedFilesOnly: false | |
| - name: Fail build if there are violations | |
| if: steps.pmd.outputs.violations != 0 | |
| run: exit 1 | |
| # Job 2: Code Quality Checks (runs in parallel with PMD) | |
| code-quality: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Set up Maven | |
| uses: stCarolas/setup-maven@v5 | |
| with: | |
| maven-version: 3.9.11 | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Set up Workspace Environment Variable | |
| run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV | |
| - name: Cache Maven dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: /home/runner/.m2/repository | |
| key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }} | |
| - name: Run checkstyle, pmd, and cpd | |
| run: mvn -T 1.5C checkstyle:check pmd:check pmd:cpd-check -f ./ddk-parent/pom.xml --batch-mode --fail-at-end | |
| # Job 3: Compile (produces artifacts for verify and spotbugs) | |
| compile: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Set up Maven | |
| uses: stCarolas/setup-maven@v5 | |
| with: | |
| maven-version: 3.9.11 | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Set up Workspace Environment Variable | |
| run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV | |
| - name: Cache Maven dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: /home/runner/.m2/repository | |
| key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }} | |
| - name: Compile all modules | |
| run: mvn -T 1.5C clean test-compile -f ./ddk-parent/pom.xml --batch-mode | |
| - name: Upload compiled artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: compiled-classes | |
| path: | | |
| **/target/classes | |
| **/target/test-classes | |
| retention-days: 1 | |
| # Job 4: Maven verify (runs tests using compiled artifacts) | |
| maven-verify: | |
| runs-on: ubuntu-24.04 | |
| needs: compile | |
| steps: | |
| - name: Set up Maven | |
| uses: stCarolas/setup-maven@v5 | |
| with: | |
| maven-version: 3.9.11 | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Set up Workspace Environment Variable | |
| run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV | |
| - name: Cache Maven dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: /home/runner/.m2/repository | |
| key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }} | |
| - name: Download compiled artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: compiled-classes | |
| - name: Run tests with Maven within a virtual X Server Environment | |
| run: xvfb-run mvn -T 1.5C verify -f ./ddk-parent/pom.xml --batch-mode --fail-at-end | |
| - name: Archive Tycho Surefire Plugin logs | |
| if: ${{ failure() }} | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: tycho-surefire-plugin | |
| path: ${{ env.GITHUB_WORKSPACE }}/com.avaloq.tools.ddk.xtext.test/target/work/data/.metadata/.log | |
| # Job 5: SpotBugs (uses compiled artifacts, only on changed modules for PRs) | |
| spotbugs: | |
| runs-on: ubuntu-24.04 | |
| needs: compile | |
| steps: | |
| - name: Set up Maven | |
| uses: stCarolas/setup-maven@v5 | |
| with: | |
| maven-version: 3.9.11 | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Set up Workspace Environment Variable | |
| run: echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV | |
| - name: Cache Maven dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: /home/runner/.m2/repository | |
| key: ${{ runner.os }}-maven-0-${{ hashFiles('**/pom.xml') }} | |
| - name: Download compiled artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: compiled-classes | |
| - name: Enable SpotBugs for changed modules (PR only) | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| chmod +x .github/scripts/enable-spotbugs-for-changed-modules.sh | |
| .github/scripts/enable-spotbugs-for-changed-modules.sh "${{ github.event.pull_request.base.sha }}" | |
| - name: Enable SpotBugs for all modules (push to master) | |
| if: github.event_name == 'push' | |
| run: | | |
| echo "Running SpotBugs on all modules (push to master)" | |
| # Set spotbugs.skip=false in parent POM | |
| sed -i 's/<spotbugs.skip>true<\/spotbugs.skip>/<spotbugs.skip>false<\/spotbugs.skip>/' ddk-parent/pom.xml | |
| - name: Run SpotBugs | |
| run: mvn -T 1.5C spotbugs:check -f ./ddk-parent/pom.xml --batch-mode --fail-at-end |