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