Commit 46744b1e authored by Maximilian Dolling's avatar Maximilian Dolling
Browse files

Merge branch 'dev'

parents 36c2a134 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:
......
......@@ -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"
......
......@@ -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:
......
......@@ -43,6 +43,7 @@
> **Description: Lists all people that committed to this config.**
* [Daniel Eggert](mailto:eggi@gfz-potsdam.de)
* [GitLab CI:hifis/software-services/fair/ci-services](mailto:ci-services@gitext.gfz-potsdam.de)
* [GitLab CI:id2/software/services/fair/software-quality-assurance](mailto:software-quality-assurance@gitext.gfz-potsdam.de)
* [GitLab CI:software/services/fair/ci-services](mailto:ci-services@gitext.gfz-potsdam.de)
......@@ -57,10 +58,17 @@
|Language|Percentage|
|---|---|
<<<<<<< HEAD
|Python|93.40|
|Shell|3.93|
|Dockerfile|1.43|
|Jinja|1.17|
=======
|Python|93.22|
|Shell|4.04|
|Dockerfile|1.47|
|HTML|1.20|
>>>>>>> dev
|Ruby|0.07|
### List Used Licenses
......@@ -93,6 +101,14 @@
> **Description: Prints the result of the [reuse](https://reuse.software/spec/) linter.**
#### MISSING COPYRIGHT AND LICENSING INFORMATION
The following files have no copyright and licensing information:
* /repo/tests/test_project/QUALITY.md
* /repo/tests/test_project/meta/check_credentials.json
* /repo/tests/test_project/test_report.md
#### SUMMARY
* Bad licenses:
......@@ -102,8 +118,13 @@
* Unused licenses:
* Used licenses: CC0-1.0, GPL-3.0-or-later
* Read errors: 0
<<<<<<< HEAD
* Files with copyright information: 73 / 73
* Files with license information: 73 / 73
=======
* Files with copyright information: 92 / 95
* Files with license information: 92 / 95
>>>>>>> dev
Congratulations! Your project is compliant with version 3.0 of the REUSE Specification :-)
Unfortunately, your project is not compliant with version 3.0 of the REUSE Specification :-(
# 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>"
......
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
# 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>"
......
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
......@@ -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
......
......@@ -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)
......@@ -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"]:
......
......@@ -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'
......
......@@ -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:
......
......@@ -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:
"""
......
......@@ -44,6 +44,7 @@ class Service(ABC):
"""
def __init__(self, sqa):
self.exit_code = 0
self.sqa = sqa
self.service_config: object
......
Subproject commit e3f54b61affba6f62a010a235630f9a741289a1e
Subproject commit f9063b6476d3e4663f6e0bf1e1d35aa66adb49ce
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment