diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d7111c..d77861a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,34 +1,56 @@ name: build on: + schedule: + - cron: "0 8 * * *" push: branches: - '**' pull_request: branches: - main - jobs: - build: + build-images: + strategy: + matrix: + version: ['3.7', '3.8', '3.9', '3.10'] + name: Build Python Docker images runs-on: ubuntu-20.04 - container: python:3.9-slim - steps: - - uses: actions/checkout@v2 - - - name: Install pybuilder - run: pip install pybuilder - - - name: Execute build - run: pyb - - - name: Install Codecov requirements - run: | - apt-get update - apt-get install -y bash curl - sed -e 's,filename="pybuilder-radon/,filename="src/main/python/pybuilder_radon/,g' target/reports/pybuilder-radon_coverage.xml > coverage.xml - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: coverage.xml \ No newline at end of file + - uses: actions/checkout@v3 + - name: build pybradon ${{ matrix.version }} image + run: + docker image build --build-arg PYTHON_VERSION=${{ matrix.version }} -t pybradon:${{ matrix.version }} . + - name: save pybradon ${{ matrix.version }} image + if: ${{ matrix.version == '3.9' }} + run: | + mkdir -p images + docker save --output images/pybradon-${{ matrix.version }}.tar pybradon:${{ matrix.version }} + - name: upload pybradon ${{ matrix.version }} image artifact + if: ${{ matrix.version == '3.9' }} + uses: actions/upload-artifact@v2 + with: + name: image + path: images/pybradon-${{ matrix.version }}.tar + coverage: + name: Publish Code Coverage Report + needs: build-images + runs-on: ubuntu-20.04 + steps: + - name: download image artifact + uses: actions/download-artifact@v2 + with: + name: image + path: images/ + - name: load image + run: + docker load --input images/pybradon-3.9.tar + - name: prepare report + run: | + ID=$(docker create pybradon:3.9) + docker cp $ID:/code/target/reports/pybuilder-radon_coverage.xml pybradon_coverage.xml + sed -i -e 's,filename="pybradon/,filename="src/main/python/pybradon/,g' pybradon_coverage.xml + - name: upload report + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: pybradon_coverage.xml diff --git a/Dockerfile b/Dockerfile index ef450e0..c8cffae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ -FROM python:3.9-slim +ARG PYTHON_VERSION=3.9 +FROM python:${PYTHON_VERSION}-slim ENV PYTHONDONTWRITEBYTECODE 1 WORKDIR /code COPY . /code/ -RUN pip install pybuilder -RUN pyb \ No newline at end of file +RUN pip install --upgrade pip && pip install pybuilder +RUN pyb -X \ No newline at end of file diff --git a/README.md b/README.md index 31db617..0a96eac 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# pybuilder-radon # +# pybuilder-radon [![GitHub Workflow Status](https://github.com/soda480/pybuilder-radon/workflows/build/badge.svg)](https://github.com/soda480/pybuilder-radon/actions) [![Code Coverage](https://codecov.io/gh/soda480/pybuilder-radon/branch/main/graph/badge.svg)](https://codecov.io/gh/soda480/pybuilder-radon) [![Code Grade](https://api.codiga.io/project/19887/status/svg)](https://app.codiga.io/public/project/19887/pybuilder-radon/dashboard) [![PyPI version](https://badge.fury.io/py/pybuilder-radon.svg)](https://badge.fury.io/py/pybuilder-radon) -[![python](https://img.shields.io/badge/python-3.9-teal)](https://www.python.org/downloads/) +[![python](https://img.shields.io/badge/python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10-teal)](https://www.python.org/downloads/) A pybuilder plugin that checks the cyclomatic complexity of your project using `radon`. For more information about radon refer to the [radon pypi page](https://pypi.org/project/radon/). @@ -17,7 +17,7 @@ use_plugin('pypi:pybuilder_radon') use_plugin('pypi:pybuilder_radon', '~=0.1.2') ``` -### cyclomatic complexity ### +### cyclomatic complexity Cyclomatic complexity is a software metric used to indicate the complexity of a program. It is a quantitative measure of the number of linearly independent paths through a program's source code. Cyclomatic complexity can be used to measure code complexity. The higher the complexity score the more complex the code, which typically translates to the code being more difficult to understand, maintain and to test. The number of the Cyclomatic complexity depends on how many different execution paths or control flow of your code can execute depending on various inputs. The metrics for Cyclomatic Complexity are: @@ -30,7 +30,7 @@ more than 50 | very complex | unable to test, high risk Refer to [cyclomatic complexity](https://www.c-sharpcorner.com/article/code-metrics-cyclomatic-complexity/) for more information. -### Pybuilder radon properties ### +### Pybuilder radon properties The pybuilder task `pyb radon` will use radon to to analyze your project and display the average cyclomatic complexity, verbose mode will display complexity of all classes, functions and methods analyzed. The following plugin properties are available to further configure the plugin's execution. @@ -46,7 +46,7 @@ project.set_property('radon_break_build_average_complexity_threshold', 4) project.set_property('radon_break_build_complexity_threshold', 10) ``` -### Development ### +### Development Clone the repository and ensure the latest version of Docker is installed on your development server. @@ -64,7 +64,7 @@ docker container run \ -it \ -v $PWD:/code \ pybradon:latest \ -/bin/bash +bash ``` Execute the build: diff --git a/build.py b/build.py index e852234..5607984 100644 --- a/build.py +++ b/build.py @@ -11,16 +11,20 @@ use_plugin('python.flake8') use_plugin('python.coverage') use_plugin('python.distutils') - +use_plugin('pypi:pybuilder_bandit') +use_plugin('pypi:pybuilder_anybadge') name = 'pybuilder-radon' authors = [Author('Emilio Reyes', 'soda480@gmail.com')] summary = 'Pybuilder plugin for radon cyclomatic complexity' url = 'https://github.com/soda480/pybuilder-radon' -version = '0.3.0' +version = '0.3.1' default_task = [ 'clean', - 'publish' + 'analyze', + 'publish', + 'bandit', + 'anybadge' ] license = 'Apache License, Version 2.0' description = summary @@ -36,7 +40,7 @@ def set_properties(project): project.set_property('flake8_include_scripts', True) project.set_property('flake8_include_test_sources', True) project.set_property('flake8_ignore', 'F401, E501') - project.build_depends_on_requirements('requirements-build.txt') + project.build_depends_on('mock') project.depends_on_requirements('requirements.txt') project.set_property('distutils_readme_description', True) project.set_property('distutils_description_overwrite', True) @@ -50,11 +54,12 @@ def set_properties(project): 'License :: OSI Approved :: Apache Software License', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Topic :: Software Development :: Build Tools']) + project.set_property('anybadge_exclude', 'vulnerabilities, coverage') # only for functional testing plugin # project.set_property('radon_break_build_average_complexity_threshold', 2.74) # project.set_property('radon_break_build_complexity_threshold', 4) diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..f4eacea --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +versions=( '3.7' '3.8' '3.9' '3.10' ) +for version in "${versions[@]}"; +do + docker image build --build-arg PYTHON_VERSION=$version -t pybradon:$version . +done \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..950f549 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["pybuilder>=0.12.0"] +build-backend = "pybuilder.pep517" diff --git a/requirements-build.txt b/requirements-build.txt deleted file mode 100644 index 1e15c6e..0000000 --- a/requirements-build.txt +++ /dev/null @@ -1,2 +0,0 @@ -mock -flake8_polyfill \ No newline at end of file