Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
id2
Software
services
FAIR
Software Quality Assurance
Commits
022469e7
Commit
022469e7
authored
Apr 20, 2021
by
Maximilian Dolling
Browse files
Merge branch 'add-exit-code' into 'dev'
add exit codes See merge request
!66
parents
cfb07dbd
b133999e
Changes
15
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
022469e7
...
...
@@ -13,7 +13,7 @@ stages:
variables
:
DOCKER_DST_IMAGE_NAME
:
software-quality-assurance
SQA_VERSION
:
'
0.7.
0
'
SQA_VERSION
:
'
0.7.
1
'
GIT_SUBMODULE_STRATEGY
:
recursive
include
:
...
...
.gitlab/ci/build-deploy.gitlab-ci.yml
View file @
022469e7
...
...
@@ -9,7 +9,7 @@ build-deploy:dep:
variables
:
DOCKER_FILE
:
build/docker/dep/Dockerfile
before_script
:
-
echo "$CI_BUILD_TOKEN" |
docker login -u
"
$CI_REGISTRY_USER
" --password-stdin "
$CI_REGISTRY
"
-
docker login -u $CI_REGISTRY_USER
-p $CI_REGISTRY_PASSWORD
$CI_REGISTRY
script
:
-
docker build --pull -t "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:latest-dep" -f $DOCKER_FILE ${DOCKER_BUILD_PATH:-.}
-
docker push "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:latest-dep"
...
...
@@ -27,7 +27,7 @@ build-deploy:dep-dev:
variables
:
DOCKER_FILE
:
build/docker/dep/Dockerfile
before_script
:
-
echo "$CI_BUILD_TOKEN" |
docker login -u
"
$CI_REGISTRY_USER
" --password-stdin "
$CI_REGISTRY
"
-
docker login -u $CI_REGISTRY_USER
-p $CI_REGISTRY_PASSWORD
$CI_REGISTRY
script
:
-
docker build --pull -t "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:latest-dep-dev" -f $DOCKER_FILE ${DOCKER_BUILD_PATH:-.}
-
docker push "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:latest-dep-dev"
...
...
@@ -48,7 +48,7 @@ build-deploy:dev:
variables
:
DOCKER_FILE
:
build/docker/app/Dockerfile_dev
before_script
:
-
echo "$CI_BUILD_TOKEN" |
docker login -u
"
$CI_REGISTRY_USER
" --password-stdin "
$CI_REGISTRY
"
-
docker login -u $CI_REGISTRY_USER
-p $CI_REGISTRY_PASSWORD
$CI_REGISTRY
script
:
-
docker build --pull -t "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:latest-dev" -f $DOCKER_FILE ${DOCKER_BUILD_PATH:-.}
-
docker push "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:latest-dev"
...
...
@@ -69,7 +69,7 @@ build-deploy:production:
variables
:
DOCKER_FILE
:
build/docker/app/Dockerfile_prod
before_script
:
-
echo "$CI_BUILD_TOKEN" |
docker login -u
"
$CI_REGISTRY_USER
" --password-stdin "
$CI_REGISTRY
"
-
docker login -u $CI_REGISTRY_USER
-p $CI_REGISTRY_PASSWORD
$CI_REGISTRY
script
:
-
docker build --pull -t "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:$SQA_VERSION" -f $DOCKER_FILE ${DOCKER_BUILD_PATH:-.}
-
docker push "${CI_REGISTRY_IMAGE}/$DOCKER_DST_IMAGE_NAME:$SQA_VERSION"
...
...
.sqa/apply_license/config.yml
View file @
022469e7
...
...
@@ -13,7 +13,7 @@ comment in file:
-
'
.*\.css$'
-
'
.*\.gitignore$'
-
'
.*\.gitmodules$'
-
'
.*Dockerfile
.*
$'
-
'
.*Dockerfile$'
-
'
.*Makefile.*$'
description
:
'
This
Software
provides
services
to
check
and
improve
the
source
code
quality
of
software-projects'
ignore paths
:
...
...
build/docker/app/Dockerfile_dev
View file @
022469e7
# software-quality-assurance
# This Software provides services to check and improve the source code quality of software-projects
#
# SPDX-FileCopyrightText: 2020 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Parts of this program <(especially the code for whatever)>
# were developed within the context of the following publicly funded
# projects or measures:
# - Helmholtz Federated IT Services, Helmholtz Association of German Research Centres (https://software.hifis.net/)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3 or later.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find a copy of the license in the LICENSES folder.
# If not, see <http://www.gnu.org/licenses/>.
FROM git.gfz-potsdam.de:5000/id2/software/services/fair/software-quality-assurance/software-quality-assurance:latest-dep-dev
LABEL maintainer="Maximilian Dolling <mdolling@gfz-potsdam.de>"
...
...
build/docker/app/Dockerfile_dev.license
0 → 100644
View file @
022469e7
software-quality-assurance
This Software provides services to check and improve the source code quality of software-projects
SPDX-FileCopyrightText: 2021 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
SPDX-License-Identifier: GPL-3.0-or-later
Parts of this program <(especially the code for whatever)>
were developed within the context of the following publicly funded
projects or measures:
- Helmholtz Federated IT Services, Helmholtz Association of German Research Centres (https://software.hifis.net/)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, Version 3 or later.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You can find a copy of the license in the LICENSES folder.
If not, see <http://www.gnu.org/licenses/>.
\ No newline at end of file
build/docker/app/Dockerfile_prod
View file @
022469e7
# software-quality-assurance
# This Software provides services to check and improve the source code quality of software-projects
#
# SPDX-FileCopyrightText: 2020 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Parts of this program <(especially the code for whatever)>
# were developed within the context of the following publicly funded
# projects or measures:
# - Helmholtz Federated IT Services, Helmholtz Association of German Research Centres (https://software.hifis.net/)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3 or later.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find a copy of the license in the LICENSES folder.
# If not, see <http://www.gnu.org/licenses/>.
FROM git.gfz-potsdam.de:5000/id2/software/services/fair/software-quality-assurance/software-quality-assurance:latest-dep
LABEL maintainer="Maximilian Dolling <mdolling@gfz-potsdam.de>"
...
...
build/docker/app/Dockerfile_prod.license
0 → 100644
View file @
022469e7
software-quality-assurance
This Software provides services to check and improve the source code quality of software-projects
SPDX-FileCopyrightText: 2021 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
SPDX-License-Identifier: GPL-3.0-or-later
Parts of this program <(especially the code for whatever)>
were developed within the context of the following publicly funded
projects or measures:
- Helmholtz Federated IT Services, Helmholtz Association of German Research Centres (https://software.hifis.net/)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, Version 3 or later.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You can find a copy of the license in the LICENSES folder.
If not, see <http://www.gnu.org/licenses/>.
\ No newline at end of file
docs/pages/usage.md
View file @
022469e7
...
...
@@ -12,6 +12,7 @@ SPDX-License-Identifier: CC0-1.0
## General
The general syntax is as following:
`sqa [OPTIONS] COMMAND [ARGS]`
.
It will exit with status code
`1`
, if a service encountered an issue and exit with status code
`0`
otherwise.
## GitLab CI/CD
...
...
src/sqa/models.py
View file @
022469e7
...
...
@@ -61,10 +61,12 @@ class SQA:
Dispatcher for the different services
"""
exit_code
:
int
config
:
SQAConfig
services
:
{
Service
}
def
__init__
(
self
,
config
:
SQAConfig
,
**
kwargs
):
self
.
exit_code
=
0
self
.
config
=
config
self
.
services
=
get_services
(
self
,
**
kwargs
)
...
...
@@ -76,6 +78,7 @@ class SQA:
Main method of SQA, which will first load the config for every service
and then run all services
"""
Path
(
self
.
config
.
sub_report_dir
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
for
service
in
self
.
services
:
...
...
@@ -86,6 +89,7 @@ class SQA:
print
(
f
"
{
service
.
display_name
}
service done..."
)
self
.
__generate_report
()
self
.
__exit
()
def
quickstart
(
self
):
"""
...
...
@@ -211,3 +215,22 @@ class SQA:
for
service
in
self
.
services
:
md_report
.
write
(
f
"
\n
###
{
service
.
display_name
}
\n\n
"
)
md_report
.
write
(
service
.
generate_markdown_chapter
())
def
__exit
(
self
):
"""
determines the exit code of the application and exits with it
If in test mode, it always exists with status 0 and gives additional information.
"""
for
service
in
self
.
services
:
if
service
.
exit_code
!=
0
:
print
(
f
"Service '
{
service
.
display_name
}
' exited with
{
service
.
exit_code
}
"
)
self
.
exit_code
=
1
if
self
.
config
.
test_mode
:
print
(
"SQA is in test mode and will be exited with 0"
)
print
(
f
"It would have exited with
{
self
.
exit_code
}
"
)
exit
(
0
)
else
:
exit
(
self
.
exit_code
)
src/sqa/services/apply_license/apply_license.py
View file @
022469e7
...
...
@@ -199,7 +199,8 @@ class ApplyLicense(Service):
if
file
.
endswith
(
".license"
):
continue
filepath
=
os
.
path
.
join
(
root
,
file
)[
6
:]
filepath
=
os
.
path
.
join
(
root
,
file
)
exit_code
=
0
# check if file should be ignored
# priorities: (user keep >) user ignore > software keep > software ignore
...
...
@@ -228,7 +229,8 @@ class ApplyLicense(Service):
f
'reuse addheader --year="
{
date
.
today
().
year
}
" '
f
'--copyright="
{
self
.
service_config
[
"licenses"
][
"default"
][
"copyright"
]
}
" '
f
'--license="[<LICENSE>]" '
f
"--template=[<TEMPLATE>][<COMMENT_LOCATION>]
{
filepath
}
&>/dev/null"
f
"--template=[<TEMPLATE>][<COMMENT_LOCATION>]
{
filepath
}
"
f
">> '
{
self
.
sqa
.
config
.
sub_report_dir
}
/apply_license.log'"
)
comment_in_file
=
False
...
...
@@ -272,7 +274,7 @@ class ApplyLicense(Service):
)
else
:
command
=
command
.
replace
(
"[<TEMPLATE>]"
,
"default"
)
os
.
system
(
command
)
exit_code
=
os
.
system
(
command
)
type_found
=
True
break
if
type_found
:
...
...
@@ -296,7 +298,11 @@ class ApplyLicense(Service):
)
else
:
command
=
command
.
replace
(
"[<TEMPLATE>]"
,
"default"
)
os
.
system
(
command
)
exit_code
=
os
.
system
(
command
)
if
exit_code
!=
0
:
print
(
f
"Error during handing of
{
filepath
}
"
)
self
.
exit_code
=
exit_code
# download license texts
for
scope
in
self
.
service_config
[
"licenses"
]:
...
...
src/sqa/services/check_credentials/check_credentials.py
View file @
022469e7
...
...
@@ -84,18 +84,18 @@ class CheckCredentials(Service):
# 0 = OK, no leak
# 256 = ERROR
# 512 = OK, leak
self
.
result
[
"exit status"
]
=
os
.
system
(
gitleaks_command
)
self
.
exit_code
=
os
.
system
(
gitleaks_command
)
with
open
(
f
"
{
self
.
sqa
.
config
.
sub_report_dir
}
/check_credentials.log"
,
"r"
)
as
log
:
self
.
result
[
"log"
]
=
log
.
read
().
replace
(
"
\n
"
,
""
)
if
self
.
result
[
"exit status"
]
==
0
:
if
self
.
exit_code
==
0
:
self
.
result
[
"summary"
]
=
"No leaks detected."
elif
self
.
result
[
"exit status"
]
==
256
:
elif
self
.
exit_code
==
256
:
self
.
result
[
"summary"
]
=
"gitleaks had an error."
elif
self
.
result
[
"exit status"
]
==
512
:
elif
self
.
exit_code
==
512
:
with
open
(
f
"
{
self
.
sqa
.
config
.
sub_report_dir
}
/check_credentials.json"
)
as
cc_json_file
:
...
...
@@ -135,7 +135,7 @@ class CheckCredentials(Service):
md_result
+=
f
'**
{
self
.
result
[
"summary"
]
}
**
\n\n
'
if
self
.
result
[
"exit status"
]
==
256
:
if
self
.
exit_code
==
256
:
md_result
+=
"**gitleaks log**
\n\n
"
md_result
+=
f
'
{
self
.
result
[
"log"
]
}
\n\n
'
...
...
@@ -159,7 +159,7 @@ class CheckCredentials(Service):
cli_result
+=
f
'
{
self
.
result
[
"summary"
]
}
\n
'
if
self
.
result
[
"exit status"
]
==
256
:
if
self
.
exit_code
==
256
:
cli_result
+=
"gitleaks log:
\n\n
"
cli_result
+=
f
'
{
self
.
result
[
"log"
]
}
\n\n
'
...
...
src/sqa/services/list_used_licenses/list_used_licenses.py
View file @
022469e7
...
...
@@ -105,6 +105,8 @@ class ListUsedLicenses(Service):
# sort output
self
.
errors
=
order_dict
(
self
.
errors
)
if
len
(
self
.
errors
)
>
0
:
self
.
exit_code
=
1
self
.
libraries_per_license
=
order_dict
(
self
.
libraries_per_license
)
def
generate_markdown_chapter
(
self
)
->
str
:
...
...
src/sqa/services/reuse_lint/reuse_lint.py
View file @
022469e7
...
...
@@ -59,9 +59,12 @@ class ReuseLint(Service):
if
self
.
sqa
.
config
.
test_mode
:
print
(
"moved quality md"
)
result_raw
=
os
.
popen
(
f
'reuse --root "
{
self
.
sqa
.
config
.
repository_dir
}
" lint'
).
read
()
reuse_command
=
(
f
'reuse --root "
{
self
.
sqa
.
config
.
repository_dir
}
" lint '
f
'> "/tmp/sqa_report_dir/reuse_lint.log"'
)
self
.
exit_code
=
os
.
system
(
reuse_command
)
if
os
.
path
.
isdir
(
"/tmp/sqa_report_dir"
):
shutil
.
move
(
"/tmp/sqa_report_dir"
,
self
.
sqa
.
config
.
sub_report_dir
)
...
...
@@ -74,11 +77,13 @@ class ReuseLint(Service):
if
self
.
sqa
.
config
.
test_mode
:
print
(
"moved quality md back"
)
for
line
in
result_raw
.
split
(
"
\n
"
):
if
len
(
line
)
>
0
and
line
[
0
]
==
"#"
:
self
.
result
+=
f
"###
{
line
}
\n
"
else
:
self
.
result
+=
f
"
{
line
}
\n
"
with
open
(
f
"
{
self
.
sqa
.
config
.
sub_report_dir
}
/reuse_lint.log"
,
"r"
)
as
log
:
for
line
in
log
:
line
=
line
.
replace
(
"
\n
"
,
""
)
if
len
(
line
)
>
0
and
line
[
0
]
==
"#"
:
self
.
result
+=
f
"###
{
line
}
\n
"
else
:
self
.
result
+=
f
"
{
line
}
\n
"
def
generate_markdown_chapter
(
self
)
->
str
:
"""
...
...
src/sqa/services/service.py
View file @
022469e7
...
...
@@ -44,6 +44,7 @@ class Service(ABC):
"""
def
__init__
(
self
,
sqa
):
self
.
exit_code
=
0
self
.
sqa
=
sqa
self
.
service_config
:
object
...
...
test_project
@
f9063b64
Compare
e3f54b61
...
f9063b64
Subproject commit
e3f54b61affba6f62a010a235630f9a741289a1
e
Subproject commit
f9063b6476d3e4663f6e0bf1e1d35aa66adb49c
e
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment