|
| 1 | +# Please do not attempt to edit this flow without the direct consent from the DevOps team. This file is managed centrally. |
| 2 | +# Contact @moabu |
| 3 | +name: Code quality check |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - 'community-edition-setup/**' |
| 11 | + - 'oxAuth/**' |
| 12 | + - '!**/CHANGELOG.md' |
| 13 | + - '!**.txt' |
| 14 | + |
| 15 | + pull_request: |
| 16 | + branches: |
| 17 | + - master |
| 18 | + - main |
| 19 | + - '!update-pycloud-in-**' |
| 20 | + types: |
| 21 | + - opened |
| 22 | + - synchronize |
| 23 | + paths: |
| 24 | + - 'community-edition-setup/**' |
| 25 | + - 'oxAuth/**' |
| 26 | + - '!**/CHANGELOG.md' |
| 27 | + - '!**.txt' |
| 28 | + |
| 29 | + workflow_dispatch: |
| 30 | + |
| 31 | +jobs: |
| 32 | + sonar-scan: |
| 33 | + name: sonar scan |
| 34 | + runs-on: ubuntu-latest |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + module: [jans-keycloak-link, jans-keycloak-integration, jans-auth-server, agama, jans-config-api, jans-core, jans-linux-setup, jans-cli-tui, jans-fido2, jans-orm, jans-scim, jans-pycloudlib, jans-link, jans-casa, jans-lock] |
| 39 | + env: |
| 40 | + JVM_PROJECTS: | |
| 41 | + oxAuth |
| 42 | + jans-keycloak-link |
| 43 | + jans-link |
| 44 | + jans-auth-server |
| 45 | + jans-lock |
| 46 | + jans-orm |
| 47 | + jans-config-api |
| 48 | + jans-scim |
| 49 | + jans-core |
| 50 | + jans-fido2 |
| 51 | + jans-casa |
| 52 | + agama |
| 53 | + NON_JVM_PROJECTS: | |
| 54 | + community-edition-setup |
| 55 | + steps: |
| 56 | + - name: Harden Runner |
| 57 | + uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 |
| 58 | + with: |
| 59 | + egress-policy: audit |
| 60 | + |
| 61 | + - name: check out code |
| 62 | + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 |
| 63 | + with: |
| 64 | + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of sonarqube analysis |
| 65 | + |
| 66 | + - name: find changed directories |
| 67 | + run: | |
| 68 | + if [ $GITHUB_BASE_REF ]; then |
| 69 | + # Pull Request |
| 70 | + echo "Triggering event: pull request" |
| 71 | + echo Pull request base ref: $GITHUB_BASE_REF |
| 72 | + git fetch origin $GITHUB_BASE_REF --depth=1 |
| 73 | + if [ ${{ github.event.action }} = "opened" ]; then |
| 74 | + echo "Triggering action: opened" |
| 75 | + echo "CHANGED_DIR=$( git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | cut -d/ -f1 | sort -u | sed -z 's/\n/,/g;s/^/[/;s/,$/]/;s/$/\n/')" >> ${GITHUB_ENV} |
| 76 | + fi |
| 77 | + if [ ${{ github.event.action }} = "synchronize" ]; then |
| 78 | + echo "Triggering action: synchronize" |
| 79 | + echo "CHANGED_DIR=$( git diff --name-only ${{ github.event.before }} ${{ github.event.pull_request.head.sha }} | cut -d/ -f1 | sort -u | sed -z 's/\n/,/g;s/^/[/;s/,$/]/;s/$/\n/')" >>${GITHUB_ENV} |
| 80 | + fi |
| 81 | + else |
| 82 | + # Push |
| 83 | + echo "Triggerring event: push" |
| 84 | + git fetch origin ${{ github.event.before }} --depth=1 |
| 85 | + echo "CHANGED_DIR=$( git diff --name-only ${{ github.event.before }} $GITHUB_SHA | cut -d/ -f1 | sort -u | sed -z 's/\n/,/g;s/^/[/;s/,$/]/;s/$/\n/')" >> ${GITHUB_ENV} |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: check env |
| 89 | + run: | |
| 90 | + echo changed dir list: ${{ env.CHANGED_DIR }} |
| 91 | + echo Matrix module: ${{ matrix.module }} |
| 92 | + echo GH event action: ${{ github.event.action }} |
| 93 | + echo PR base sha: ${{ github.event.pull_request.base.sha }} |
| 94 | + echo PR head sha: ${{ github.event.pull_request.head.sha }} |
| 95 | + echo event before: ${{ github.event.before }} |
| 96 | + echo GH sha: $GITHUB_SHA |
| 97 | +
|
| 98 | + - name: Set up JDK 17 |
| 99 | + if: contains(env.CHANGED_DIR, matrix.module) && contains(env.JVM_PROJECTS, matrix.module) |
| 100 | + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 |
| 101 | + with: |
| 102 | + java-version: '11' |
| 103 | + distribution: 'adopt' |
| 104 | + |
| 105 | + - name: Cache SonarCloud packages for JVM based project |
| 106 | + if: contains(env.CHANGED_DIR, matrix.module) && contains(env.JVM_PROJECTS, matrix.module) |
| 107 | + uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0 |
| 108 | + with: |
| 109 | + path: ~/.sonar/cache |
| 110 | + key: ${{ runner.os }}-sonar |
| 111 | + restore-keys: ${{ runner.os }}-sonar |
| 112 | + |
| 113 | + - name: Build and analyze JVM based project |
| 114 | + if: contains(env.CHANGED_DIR, matrix.module) && contains(env.JVM_PROJECTS, matrix.module) |
| 115 | + env: |
| 116 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
| 117 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 118 | + run: | |
| 119 | + cd ${{ matrix.module }} |
| 120 | + case ${{ matrix.module }} in |
| 121 | + "opendj4") |
| 122 | + echo "Build opendj-sdk first for gluu-opendj4" |
| 123 | + mvn -B -f opendj-sdk/pom.xml -DskipTests clean install |
| 124 | + ;& |
| 125 | + "oxAuth") |
| 126 | + ;& |
| 127 | + "oxTrust") |
| 128 | + ;& |
| 129 | + "scim") |
| 130 | + ;& |
| 131 | + "casa") |
| 132 | + ;& |
| 133 | + "oxd") |
| 134 | + echo "Run Sonar analysis without test execution" |
| 135 | + mvn -B -DskipTests=true install org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
| 136 | + ;; |
| 137 | + *) |
| 138 | + echo "Run Sonar analysis with test execution" |
| 139 | + mvn -B install org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
| 140 | + ;; |
| 141 | + echo "Run Sonar analysis with test execution" |
| 142 | + mvn -B install org.sonarsource.scanner.maven:sonar-maven-plugin:sonar |
| 143 | + ;; |
| 144 | + esac |
| 145 | +
|
| 146 | +
|
| 147 | + - name: Convert repo org name to lowercase for non JVM projects |
| 148 | + if: contains(env.CHANGED_DIR, matrix.module) && contains(env.NON_JVM_PROJECTS, matrix.module) |
| 149 | + env: |
| 150 | + REPO_OWNER: ${{ github.repository_owner }} |
| 151 | + run: | |
| 152 | + echo "REPO_ORG=${REPO_OWNER,,}" >>${GITHUB_ENV} |
| 153 | +
|
| 154 | + - name: SonarCloud Scan for non-JVM project |
| 155 | + if: contains(env.CHANGED_DIR, matrix.module) && contains(env.NON_JVM_PROJECTS, matrix.module) |
| 156 | + uses: SonarSource/sonarcloud-github-action@49e6cd3b187936a73b8280d59ffd9da69df63ec9 # master |
| 157 | + with: |
| 158 | + args: > |
| 159 | + -Dsonar.organization=${{ env.REPO_ORG }} |
| 160 | + -Dsonar.projectKey=${{ github.repository_owner }}_${{ matrix.module }} |
| 161 | + projectBaseDir: ${{ matrix.module }} |
| 162 | + env: |
| 163 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
| 164 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
0 commit comments