update sonar configs (#14) #46
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 | |
| on: | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| PUSH_CLOJARS: | |
| description: 'Push test-jar to clojars' | |
| required: true | |
| type: boolean | |
| jobs: | |
| job-build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Disabling shallow clone is recommended for improving relevancy of reporting for sonar | |
| fetch-depth: 0 | |
| - name: Cache local Maven repository | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.m2/repository | |
| key: ${{ runner.os }}-lein-${{ hashFiles('**/project.clj') }} | |
| restore-keys: | | |
| ${{ runner.os }}-lein- | |
| - name: Cache local M2 repository | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Install clojure tools | |
| uses: DeLaGuardo/setup-clojure@12.5 | |
| with: | |
| lein: 2.11.2 | |
| # Ubuntu Repos on Azure fail often. Attempt to install before other | |
| # long-running operations. | |
| # xmllinter for tests checks | |
| # jq for SonarQube Quality Gate check | |
| - name: Install xmllinter and jq (for "Fail on failed tests") | |
| shell: bash | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libxml2-utils jq | |
| - name: Setup Sonar Scanner | |
| uses: warchant/setup-sonar-scanner@v7 | |
| with: | |
| version: 5.0.2.4997 | |
| - name: Run Sonar Scanner | |
| env: | |
| # provide GITHUB_TOKEN to get access to secrets.SONAR_TOKEN | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: sonar-scanner -X | |
| -Dsonar.token=${{ secrets.SONARQUBE_TOKEN}} | |
| -Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} | |
| - name: List test reports | |
| run: | | |
| pwd | |
| ls -lR test-reports | |
| - name: Get list of tests | |
| if: always() | |
| id: tests | |
| uses: Rishabh510/Path-lister-action@master | |
| with: | |
| path: "test-reports/xml" | |
| type: ".xml" | |
| - name: Fail on failed tests | |
| if: always() | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libxml2-utils | |
| echo "Found ${{ steps.tests.outputs.path_count }} test report(s)" | |
| if [[ ${{ steps.tests.outputs.path_count }} < 1 ]]; then | |
| echo "ERROR: No unit test reports collected." | |
| exit 1 | |
| fi | |
| for f in ${{ steps.tests.outputs.paths }}; do | |
| echo "=== $f ===" | |
| if [[ $(xmllint --xpath "string(//testsuite/@failures)" $f) > 1 ]]; then | |
| echo TEST FAILED: $f | |
| exit 1 | |
| fi | |
| if [[ $(xmllint --xpath "string(//testsuite/@errors)" $f) > 1 ]]; then | |
| echo TEST ERRORED: $f | |
| exit 1 | |
| fi | |
| done | |
| - name: SonarQube Quality Gate check | |
| uses: sonarsource/sonarqube-quality-gate-action@v1.0.0 | |
| # Force to fail step after specific time | |
| timeout-minutes: 5 | |
| with: | |
| scanMetadataReportFile: .scannerwork/report-task.txt | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }} | |
| SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | |
| - uses: s4u/maven-settings-action@v2.2.0 | |
| with: | |
| githubServer: false | |
| override: true | |
| servers: | | |
| [{ | |
| "id": "docker.io", | |
| "username": "${{ secrets.SIXSQ_DOCKER_USERNAME }}", | |
| "password": "${{ secrets.SIXSQ_DOCKER_PASSWORD }}" | |
| }] | |
| - name: Extract branch name | |
| shell: bash | |
| run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})" | |
| id: extract_branch | |
| - name: Build | |
| run: lein do clean, jar, install | |
| - name: Deploy to clojars | |
| run: lein deploy clojars | |
| if: ${{ inputs.PUSH_CLOJARS }} | |
| shell: bash | |
| env: | |
| CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }} | |
| CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} | |
| - name: Publish Unit Test Results | |
| uses: EnricoMi/publish-unit-test-result-action@v1 | |
| if: always() | |
| with: | |
| files: test-reports/TEST-*.xml | |
| job-notify: | |
| if: always() | |
| name: Post Workflow Status To Slack | |
| needs: | |
| - job-build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: Gamesight/slack-workflow-status@master | |
| with: | |
| repo_token: ${{secrets.GITHUB_TOKEN}} | |
| slack_webhook_url: ${{secrets.SLACK_WEBHOOK_URL}} |