Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NodeClientSharedCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Shared
NodeClientSharedCode
Commits
41b3d885
Commit
41b3d885
authored
10 months ago
by
joel.vonderwe
Browse files
Options
Downloads
Patches
Plain Diff
Create SonarAnalyzer
parent
6ca55f11
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
helpers/Dojo/AssignmentValidator.ts
+8
-16
8 additions, 16 deletions
helpers/Dojo/AssignmentValidator.ts
helpers/Dojo/SonarAnalyzer.ts
+54
-0
54 additions, 0 deletions
helpers/Dojo/SonarAnalyzer.ts
types/Dojo/ApiRoute.ts
+1
-0
1 addition, 0 deletions
types/Dojo/ApiRoute.ts
with
63 additions
and
16 deletions
helpers/Dojo/AssignmentValidator.ts
+
8
−
16
View file @
41b3d885
...
...
@@ -15,6 +15,7 @@ import Assignment, { Language } from '../../models/Assignment';
import
ClientsSharedAssignmentHelper
from
'
./ClientsSharedAssignmentHelper
'
;
import
{
spawnSync
}
from
'
node:child_process
'
;
import
SharedConfig
from
'
../../../shared/config/SharedConfig
'
;
import
SonarAnalyzer
from
'
./SonarAnalyzer
'
;
const
execAsync
=
util
.
promisify
(
exec
);
...
...
@@ -281,35 +282,27 @@ class AssignmentValidator {
{
this
.
newStep
(
'
ASSIGNMENT_SONAR
'
,
'
Please wait while we are running Sonar analysis on the assignment...
'
);
let
additionalParams
:
string
[]
=
[];
this
.
newSubStep
(
'
SONAR_BUILD
'
,
'
Build files
'
);
const
build
Pro
cess
=
spawnSync
(
'
docker
'
,
[
'
build
'
,
'
--tag
'
,
'
dojo-sonar-scanner
'
,
'
/sonar
'
]);
if
(
build
Pro
cess
.
status
!==
0
)
{
const
build
Suc
cess
=
SonarAnalyzer
.
buildDocker
()
if
(
!
build
Suc
cess
)
{
this
.
emitError
(
`Build sonar image failed`
,
'
Sonar analysis failure
'
,
AssignmentCheckerError
.
SONAR_ANALYSIS_FAILED
);
console
.
log
(
buildProcess
.
stdout
.
toString
())
console
.
log
(
buildProcess
.
stderr
.
toString
())
return
;
}
if
(
[
Language
.
c
,
Language
.
cpp
,
Language
.
objc
].
includes
(
assignment
.
language
)
&&
assignmentFile
.
buildLine
!=
undefined
)
{
const
process
=
spawnSync
(
'
docker run -v ./:/usr/src dojo-sonar-scanner /usr/local/bin/build-wrapper-linux-x86-64 --out-dir bw-output
'
+
assignmentFile
.
buildLine
,
[],
{
shell
:
true
})
if
(
process
.
status
!==
0
)
{
if
(
SonarAnalyzer
.
mustRunBuild
(
assignment
.
language
,
assignmentFile
.
buildLine
)
)
{
const
buildSuccess
=
SonarAnalyzer
.
runBuildStep
(
assignmentFile
.
buildLine
!
);
if
(
!
buildSuccess
)
{
this
.
emitError
(
`Failed to build files using buildLine`
,
'
Sonar analysis failure
'
,
AssignmentCheckerError
.
SONAR_ANALYSIS_FAILED
);
console
.
log
(
process
.
stdout
.
toString
())
console
.
log
(
process
.
stderr
.
toString
())
return
;
}
additionalParams
=
[
'
-Dsonar.cfamily.build-wrapper-output=/usr/src/bw-output
'
];
}
this
.
endSubStep
(
'
Sonar files build success
'
,
false
);
this
.
newSubStep
(
'
SONAR_RUN
'
,
'
Run sonar analysis
'
);
const
process
=
spawnSync
(
'
docker
'
,
[
'
run
'
,
'
-v
'
,
'
./:/usr/src
'
,
'
dojo-sonar-scanner
'
,
'
sonar-scanner
'
,
'
-Dsonar.qualitygate.wait=true
'
,
'
-Dsonar.projectKey=
'
+
assignment
.
sonarKey
,
'
-Dsonar.sources=.
'
,
'
-Dsonar.host.url=
'
+
SharedConfig
.
sonar
.
url
,
'
-Dsonar.login=
'
+
SharedConfig
.
sonar
.
token
,
...
additionalParams
])
if
(
process
.
status
!==
0
)
{
const
runSuccess
=
SonarAnalyzer
.
runAnalysis
(
assignment
.
sonarKey
,
assignment
.
language
,
assignmentFile
.
buildLine
);
if
(
runSuccess
)
{
this
.
emitError
(
`Sonar gate failed`
,
'
Sonar analysis failure
'
,
AssignmentCheckerError
.
SONAR_ANALYSIS_FAILED
);
return
;
}
...
...
@@ -326,7 +319,6 @@ class AssignmentValidator {
{
this
.
newStep
(
'
ASSIGNMENT_RUN
'
,
'
Please wait while we are running the assignment...
'
);
const
exerciseDockerCompose
=
new
ExerciseDockerCompose
(
ClientsSharedConfig
.
dockerCompose
.
projectName
,
assignmentFile
,
this
.
folderAssignment
);
try
{
...
...
This diff is collapsed.
Click to expand it.
helpers/Dojo/SonarAnalyzer.ts
0 → 100644
+
54
−
0
View file @
41b3d885
import
{
spawnSync
}
from
'
node:child_process
'
;
import
{
Language
}
from
'
../../models/Assignment
'
;
import
SharedConfig
from
'
../../../shared/config/SharedConfig
'
;
const
IMAGE_NAME
=
'
dojo-sonar-scanner
'
const
OUT_DIR
=
'
bw-output
'
;
class
SonarAnalyzer
{
buildDocker
=
()
=>
{
const
buildProcess
=
spawnSync
(
'
docker
'
,
[
'
build
'
,
'
--tag
'
,
IMAGE_NAME
,
'
/sonar
'
]);
if
(
buildProcess
.
status
!==
0
)
{
console
.
log
(
buildProcess
.
stdout
.
toString
())
console
.
log
(
buildProcess
.
stderr
.
toString
())
return
false
;
}
return
true
;
}
mustRunBuild
=
(
language
:
Language
,
buildLine
:
string
|
undefined
)
=>
{
return
[
Language
.
c
,
Language
.
cpp
,
Language
.
objc
].
includes
(
language
)
&&
buildLine
!=
undefined
;
}
runBuildStep
=
(
buildLine
:
string
)
=>
{
const
process
=
spawnSync
(
`docker run -v ./:/usr/src
${
IMAGE_NAME
}
/usr/local/bin/build-wrapper-linux-x86-64 --out-dir
${
OUT_DIR
}
`
+
buildLine
,
[],
{
shell
:
true
})
if
(
process
.
status
!==
0
)
{
console
.
log
(
process
.
stdout
.
toString
())
console
.
log
(
process
.
stderr
.
toString
())
return
false
;
}
return
true
;
}
runAnalysis
=
(
sonarKey
:
string
,
language
:
Language
,
buildLine
:
string
|
undefined
)
=>
{
let
addParam
:
string
[]
=
[];
if
(
this
.
mustRunBuild
(
language
,
buildLine
))
{
addParam
=
[
`-Dsonar.cfamily.build-wrapper-output=/usr/src/
${
OUT_DIR
}
`
];
}
const
process
=
spawnSync
(
'
docker
'
,
[
'
run
'
,
'
-v
'
,
'
./:/usr/src
'
,
IMAGE_NAME
,
'
sonar-scanner
'
,
'
-Dsonar.qualitygate.wait=true
'
,
'
-Dsonar.projectKey=
'
+
sonarKey
,
'
-Dsonar.sources=.
'
,
'
-Dsonar.host.url=
'
+
SharedConfig
.
sonar
.
url
,
'
-Dsonar.login=
'
+
SharedConfig
.
sonar
.
token
,
...
addParam
])
return
process
.
status
===
0
;
}
}
export
default
new
SonarAnalyzer
();
\ No newline at end of file
This diff is collapsed.
Click to expand it.
types/Dojo/ApiRoute.ts
+
1
−
0
View file @
41b3d885
...
...
@@ -13,6 +13,7 @@ enum ApiRoute {
ASSIGNMENT_CORRECTION_LINK
=
'
/assignments/{{assignmentNameOrUrl}}/corrections
'
,
ASSIGNMENT_CORRECTION_UPDATE
=
'
/assignments/{{assignmentNameOrUrl}}/corrections/{{exerciseIdOrUrl}}
'
,
EXERCISE_CREATE
=
'
/assignments/{{nameOrUrl}}/exercises
'
,
EXERCISE_GET
=
'
/exercises/{{id}}
'
,
EXERCISE_ASSIGNMENT
=
'
/exercises/{{id}}/assignment
'
,
EXERCISE_RESULTS
=
'
/exercises/{{id}}/results
'
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment