diff --git a/migration/build.sh b/migration/build.sh new file mode 100755 index 000000000..fa94662eb --- /dev/null +++ b/migration/build.sh @@ -0,0 +1,57 @@ +#!/bin/bash +# +# sonar-tools +# Copyright (C) 2025 Olivier Korach +# mailto:olivier.korach AT gmail DOT com +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" +CONF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +build_image=1 +release=0 +release_docker=0 + +while [[ $# -ne 0 ]]; do + case "${1}" in + nodocker) + build_image=0 + ;; + pypi) + release=1 + ;; + dockerhub) + release_docker=1 + ;; + *) + ;; + esac + shift +done + +rm -rf "${ROOT_DIR}/build/lib/migration" "${ROOT_DIR}/build/lib/cli" "${ROOT_DIR}/build/lib/sonar" "${ROOT_DIR}"/build/scripts*/sonar_migration "${ROOT_DIR}"/dist/sonar_migration* +mv "${ROOT_DIR}/pyproject.toml" "${ROOT_DIR}/pyproject.toml.sonar-tools" +cp "${ROOT_DIR}/migration/pyproject.toml" "${ROOT_DIR}" +poetry build +mv "${ROOT_DIR}/pyproject.toml.sonar-tools" "${ROOT_DIR}/pyproject.toml" + +# Deploy locally for tests +pip install --upgrade --force-reinstall "${ROOT_DIR}"/dist/sonar_migration-*-py3-*.whl + +if [[ "${build_image}" == "1" ]]; then + docker build -t olivierkorach/sonar-migration:latest -f migration/snapshot.Dockerfile "${ROOT_DIR}" --load +fi \ No newline at end of file diff --git a/migration/pyproject.toml b/migration/pyproject.toml index 5f17b3255..1384fd8cb 100644 --- a/migration/pyproject.toml +++ b/migration/pyproject.toml @@ -65,7 +65,7 @@ requires = [ ] [tool.poetry] -packages = [{include = "sonar"}, {include = "migration"}] +packages = [{include = "sonar"}, {include = "migration"}, {include = "cli"}] [dependency-groups] test = [ diff --git a/migration/release.Dockerfile b/migration/release.Dockerfile index 95cf1ce22..d52026124 100644 --- a/migration/release.Dockerfile +++ b/migration/release.Dockerfile @@ -22,16 +22,14 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" WORKDIR /opt/sonar-migration COPY ./sonar sonar -COPY ./requirements.txt . COPY ./cli cli -COPY ./setup_migration.py . COPY ./migration migration COPY ./migration/README.md . COPY ./LICENSE . COPY ./sonar/audit sonar/audit RUN pip install --upgrade pip \ -&& pip install sonar-migration==0.4 --force-reinstall +&& pip install sonar-migration==0.6 --force-reinstall USER ${USERNAME} WORKDIR /home/${USERNAME} diff --git a/migration/snapshot.Dockerfile b/migration/snapshot.Dockerfile index af947163d..c79c3be28 100644 --- a/migration/snapshot.Dockerfile +++ b/migration/snapshot.Dockerfile @@ -22,16 +22,15 @@ ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" WORKDIR /opt/sonar-migration COPY ./sonar sonar -COPY ./requirements.txt . +COPY ./migration/pyproject.toml . COPY ./migration migration +COPY ./migration/README.md . COPY ./LICENSE . COPY ./cli cli -COPY ./setup_migration.py . RUN pip install --upgrade pip \ -&& pip install --no-cache-dir -r requirements.txt \ -&& pip install --no-cache-dir --upgrade pip setuptools wheel \ -&& python setup_migration.py bdist_wheel \ +&& pip install --no-cache-dir poetry \ +&& poetry build \ && pip install dist/sonar_migration-*-py3-*.whl --force-reinstall USER ${USERNAME} diff --git a/requirements-to-build.txt b/requirements-to-build.txt deleted file mode 100644 index 85f8ede55..000000000 --- a/requirements-to-build.txt +++ /dev/null @@ -1,12 +0,0 @@ -setuptools -black -wheel -sphinx -sphinx_rtd_theme -sphinx-autodoc-typehints -twine -pytest -coverage -flake8 -pylint -get_pypi_latest_version diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 23c786459..000000000 --- a/requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -argparse -datetime -python-dateutil -requests -jprops -levenshtein -PyYAML diff --git a/setup.py b/setup.py deleted file mode 100644 index 5999febd0..000000000 --- a/setup.py +++ /dev/null @@ -1,84 +0,0 @@ -# -# sonar-tools -# Copyright (C) 2019-2025 Olivier Korach -# mailto:olivier.korach AT gmail DOT com -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -""" - -Package setup - -""" - -import setuptools -from sonar import version - - -with open("README.md", "r", encoding="utf-8") as fh: - long_description = fh.read() -setuptools.setup( - name="sonar-tools", - version=version.PACKAGE_VERSION, - scripts=["sonar-tools"], - author="Olivier Korach", - author_email="olivier.korach@gmail.com", - description="A collection of utility scripts for SonarQube Server or Cloud", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/okorach/sonar-tools", - project_urls={ - "Bug Tracker": "https://github.com/okorach/sonar-tools/issues", - "Documentation": "https://github.com/okorach/sonar-tools/README.md", - "Source Code": "https://github.com/okorach/sonar-tools", - }, - packages=setuptools.find_packages(), - package_data={"sonar": ["LICENSE", "audit/rules.json", "config.json", "audit/sonar-audit.properties"]}, - install_requires=[ - "argparse", - "datetime", - "python-dateutil", - "requests", - "jprops", - "levenshtein", - "PyYAML ", - ], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", - "Operating System :: OS Independent", - ], - entry_points={ - "console_scripts": [ - "sonar-audit = cli.audit:main", - "sonar-projects-export = cli.projects_export:main", - "sonar-projects-import = cli.projects_import:main", - "sonar-projects = cli.projects_cli:main", - "sonar-measures-export = cli.measures_export:main", - "sonar-housekeeper = cli.housekeeper:main", - "sonar-issues-sync = cli.findings_sync:main", - "sonar-findings-sync = cli.findings_sync:main", - "sonar-custom-measures = cli.cust_measures:main", - "sonar-issues-export = cli.findings_export:main", - "sonar-findings-export = cli.findings_export:main", - "sonar-loc = cli.loc:main", - "sonar-config = cli.config:main", - "support-audit = cli.support:main", - "sonar-rules = cli.rules_cli:main", - ] - }, - python_requires=">=3.8", -) diff --git a/setup_migration.py b/setup_migration.py deleted file mode 100644 index d2314bb57..000000000 --- a/setup_migration.py +++ /dev/null @@ -1,67 +0,0 @@ -# -# sonar-tools -# Copyright (C) 2019-2025 Olivier Korach -# mailto:olivier.korach AT gmail DOT com -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 3 of the License, or (at your option) any later version. -# -# 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -""" - -Package setup - -""" - -import setuptools -from sonar import version - -with open("migration/README.md", "r", encoding="utf-8") as fh: - long_description = fh.read() -setuptools.setup( - name="sonar-migration", - version=version.MIGRATION_TOOL_VERSION, - scripts=["migration/sonar_migration"], - author="Olivier Korach", - author_email="olivier.korach@gmail.com", - description="A SonarQube collection tool to use in the context of SonarQube Server to SonarQube Cloud migration", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/okorach/sonar-tools", - project_urls={ - "Bug Tracker": "https://github.com/okorach/sonar-tools/issues", - "Documentation": "https://github.com/okorach/sonar-tools/migration/README.md", - "Source Code": "https://github.com/okorach/sonar-tools", - }, - packages=setuptools.find_packages(), - package_data={"sonar": ["LICENSE", "audit/rules.json", "audit/sonar-audit.properties"]}, - install_requires=[ - "argparse", - "datetime", - "python-dateutil", - "requests", - "jprops", - ], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", - "Operating System :: OS Independent", - ], - entry_points={ - "console_scripts": [ - "sonar-migration = migration.migration:main", - ] - }, - python_requires=">=3.8", -) diff --git a/sonar-project.properties b/sonar-project.properties index 56eb03a5a..5e1a9984b 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -4,7 +4,7 @@ sonar.projectName=Sonar Tools sonar.python.version=3.9 # Comma-separated paths to directories with sources (required) -sonar.sources=sonar, cli, migration, conf, setup.py, setup_migration.py +sonar.sources=sonar, cli, migration, conf # Encoding of the source files sonar.sourceEncoding=UTF-8 @@ -16,6 +16,5 @@ sonar.sarifReportPaths=build/results_sarif.sarif # sonar.python.bandit.reportPaths=build/bandit-report.json sonar.tests=test/gen/latest, test/gen/lts, test/gen/9, test/gen/9-ce, test/gen/cb -sonar.coverage.exclusions=setup*.py, test/**/*, conf/*2sonar.py, cli/cust_measures.py, sonar/custom_measures.py, cli/support.py, cli/projects_export.py, cli/projects_import.py, **/*.sh +sonar.coverage.exclusions=test/**/*, conf/*2sonar.py, cli/cust_measures.py, sonar/custom_measures.py, cli/support.py, cli/projects_export.py, cli/projects_import.py, **/*.sh -sonar.cpd.exclusions=setup*.py