name: bld-ci

on: [push, pull_request, workflow_dispatch]

jobs:
  build-bld-project:
    runs-on: ubuntu-latest

    env:
      COVERAGE_SDK: "17"

    strategy:
      matrix:
        java-version: [17, 21, 22]

    steps:
      - name: Checkout source repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up JDK ${{ matrix.java-version }}
        uses: actions/setup-java@v4
        with:
          distribution: "zulu"
          java-version: ${{ matrix.java-version }}

      - name: Grant bld execute permission
        run: chmod +x bld

      - name: Download the bld dependencies
        run: ./bld download

      - name: Compile source with bld
        run: ./bld compile

      - name: Run tests with bld
        env:
          AKISMET_BLOG: ${{ secrets.AKISMET_BLOG }}
          AKISMET_API_KEY: ${{ secrets.AKISMET_API_KEY }}
        run: ./bld jacoco

      - name: Remove pom.xml
        if: success() && matrix.java-version == env.COVERAGE_SDK
        run: rm -rf pom.xml

      - name: SonarCloud Scan
        uses: sonarsource/sonarcloud-github-action@master
        if: success() && matrix.java-version == env.COVERAGE_SDK
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
