refactor(ci): update sonar-cloud workflow to support runner size sele… #2
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: Build and test (Kotlin) | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| runner-size: | ||
| required: false | ||
| description: "Runner to use for the job" | ||
| default: "normal" | ||
| type: choice | ||
| options: | ||
| - "normal" | ||
| - "large" | ||
| java-distribution: | ||
| required: false | ||
| type: string | ||
| default: 'corretto' | ||
| java-version: | ||
| required: false | ||
| type: string | ||
| default: '21' | ||
| gradle-module: | ||
| required: false | ||
| type: string | ||
| description: "Name of the gradle module being tested - only needed if you want to test one module in a multi-module project" | ||
| kover-report-path: | ||
| required: false | ||
| type: string | ||
| description: "Path to the Kover report XML file for code coverage (relative to workspace or absolute)" | ||
| default: 'build/reports/kover/report.xml' | ||
| test-timeout-minutes: | ||
| required: false | ||
| type: number | ||
| description: "Timeout for the test job in minutes" | ||
| default: 30 | ||
| secrets: | ||
| GHL_USERNAME: | ||
| required: true | ||
| description: "Github Username (Gradle plugin)" | ||
| GHL_PASSWORD: | ||
| required: true | ||
| description: "Github Password (Gradle plugin)" | ||
| SONAR_TOKEN: | ||
| required: true | ||
| description: "SonarCloud token" | ||
| jobs: | ||
| get-runner: | ||
| uses: ./.github/workflows/components/runner-size-converter.yaml | ||
|
Check failure on line 47 in .github/workflows/pull-request-kotlin.yaml
|
||
| with: | ||
| runner-size: ${{ inputs.runner-size }} | ||
| pr_title_checker: | ||
| name: Check PR title | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - uses: Slashgear/action-check-pr-title@v4 | ||
| with: | ||
| regexp: '^(\[(develop|development|staging)\]\s)?(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test|release|ignore)(\([\w\- ]+\))?!?: (.+)' | ||
| helpMessage: "Example: 'feat(app-api): Add new vehicle integration (SERVER-123)'" | ||
| test: | ||
| name: Test with code coverage | ||
| needs: get-runner | ||
| runs-on: ${{ needs.get-runner.outputs.runner-name }} | ||
| timeout-minutes: ${{ inputs.test-timeout-minutes }} | ||
| steps: | ||
| # Checkout | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # to check out the actual pull request commit, not the merge commit | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| fetch-depth: 0 | ||
| # Set up JDK | ||
| - name: Set up JDK | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: ${{ inputs.java-distribution }} | ||
| java-version: ${{ inputs.java-version }} | ||
| cache: 'gradle' | ||
| # Cache SonarCloud packages | ||
| - name: Cache SonarCloud packages | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.sonar/cache | ||
| key: ${{ runner.os }}-sonar | ||
| restore-keys: ${{ runner.os }}-sonar | ||
| # Run tests with coverage | ||
| - name: Run tests with coverage | ||
| env: | ||
| GHL_USERNAME: ${{ secrets.GHL_USERNAME }} | ||
| GHL_PASSWORD: ${{ secrets.GHL_PASSWORD }} | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # Check if gradle-module is provided and format the command accordingly | ||
| run: | | ||
| if [ -z "${{ inputs.gradle-module }}" ]; then | ||
| # For root project (no module specified) | ||
| ./gradlew --no-daemon ktlintCheck koverXmlReport koverHtmlReport --parallel | ||
| else | ||
| # For specific module | ||
| ./gradlew --no-daemon ${{ format('{0}:ktlintCheck {0}:koverXmlReport {0}:koverHtmlReport', inputs.gradle-module) }} --parallel | ||
| fi | ||
| shell: bash | ||
| # Upload test results | ||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: test-result | ||
| path: | | ||
| ${{ github.workspace }}/build/reports/kover | ||
| **/reports/tests/test | ||
| /home/runner/.gradle/daemon/**/daemon-*.out.log | ||
| retention-days: 2 | ||
| overwrite: true | ||
| # Upload results to SonarCloud | ||
| - name: Upload results to SonarCloud | ||
| env: | ||
| GHL_USERNAME: ${{ secrets.GHL_USERNAME }} | ||
| GHL_PASSWORD: ${{ secrets.GHL_PASSWORD }} | ||
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
| run: ./gradlew --no-daemon sonar | ||
| - name: Add code coverage to PR | ||
| uses: mi-kas/kover-report@v1 | ||
| with: | ||
| title: Code Coverage ${{ inputs.gradle-module }} | ||
| path: ${{ inputs.kover-report-path }} | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| min-coverage-overall: 70 | ||
| min-coverage-changed-files: 70 | ||
| update-comment: true | ||
| coverage-counter-type: LINE | ||
| # Publish test results | ||
| - name: Publish test results | ||
| uses: EnricoMi/publish-unit-test-result-action@v2 | ||
| if: always() | ||
| with: | ||
| files: | | ||
| **/build/test-results/**/*.xml | ||
| **/build/test-results/**/*.trx | ||
| **/build/test-results/**/*.json | ||