Commit 26a2cb6d authored by Jon's avatar Jon
Browse files

Merge branch '10-unit-testing' into 'development'

Resolve "Unit Testing"

See merge request !8
parents 10d461bb 9b573944
Loading
Loading
Loading
Loading
Loading
+8 −0
Changes for .gitignore: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -21,3 +21,11 @@ pyvenv.cfg
#Don't include the autogenerated Module docs
docs/module/*
docs/includes/*

# Don't track JUnit Test or coverage Reports from unittests
*.JUnit.xml
.coverage*
*,cover
public/*
htmlcov/*
UnitTesting_coverage.xml
 No newline at end of file
+212 −8
Changes for .gitlab-ci.yml: 212 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@


stages:
    - Verify
    - Unit Testing
    - package
    - build
    - test
@@ -11,20 +13,189 @@ stages:
    - publish


.PythonImageBuildModuleBefore_Script: &PythonImageBuildModuleBefore_Script |
    pip install --user --upgrade setuptools wheel
    pip install -r requirements.txt
    pip install -r test/requirements_unittest.pip
    apt-get update && apt-get install -y --no-install-recommends git
    git --version
    GIT_PYTHON_GIT_EXECUTABLE=$(which git)
    echo $GIT_PYTHON_GIT_EXECUTABLE
    echo $PATH
    PATH=$PATH:$GIT_PYTHON_GIT_EXECUTABLE


PyLint:
    stage: Verify
    image: python:3.6.9-slim
    before_script:
        - *PythonImageBuildModuleBefore_Script
        - python3 setup.py egg_info sdist bdist_wheel
    script:
          - python3 -m pylint --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter gitlab_management test *.py > gl-code-quality-report.json
          - python3 -m pylint --exit-zero --output-format=pylint_gitlab.GitlabPagesHtmlReporter gitlab_management test *.py > gl-code-quality-report.html
          - PyPIScore=$(python3 -m pylint --exit-zero  gitlab_management test *.py | sed -n 's/^Your code has been rated at \([-0-9./]*\).*/\1/p')
          - |
            echo "{
            \"PyLintScore\": \"$PyPIScore\"
            }            
            " > badge_pylint.json
    rules:
          - if: $CI_COMMIT_TAG
            when: never
          - if: $CI_MERGE_REQUEST_IID
            when: never
          - if: '$CI_COMMIT_BRANCH'
            changes:
            - gitlab_management/*.py
            - test/*.py
            - ./*.py
            when: always
    artifacts:
        expire_in: 60 days
        paths:
            - gl-code-quality-report.json
            - gl-code-quality-report.html
            - badge_pylint.json
        reports:
            codequality: gl-code-quality-report.json

Unit Test:
    stage: Unit Testing
    image: python:3.6.9-slim
    before_script:
        - *PythonImageBuildModuleBefore_Script
        - python3 setup.py egg_info sdist bdist_wheel
    script:
        - coverage run --parallel-mode --branch --context=Unit_Testing --source gitlab_management test/test_unit.py
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH'
          changes:
          - gitlab_management/*.py
          - test/test_*.py
          - setup.py
          when: always
    artifacts:
      expire_in: 3 days
      paths:
          - Unit.JUnit.xml
          - gitlab_management/*.cover
          - .coverage*
      reports:
          junit: Unit.JUnit.xml


Function Test:
    stage: Unit Testing
    image: python:3.6.9-slim
    before_script:
        - *PythonImageBuildModuleBefore_Script
        - python3 setup.py egg_info sdist bdist_wheel
    script:
        - coverage run --parallel-mode --branch --context=Function_Testing --source gitlab_management test/test_function.py
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH'
          changes:
          - gitlab_management/*.py
          - test/test_*.py
          - setup.py
          when: always
    artifacts:
      expire_in: 3 days
      paths:
          - Function.JUnit.xml
          - gitlab_management/*.cover
          - .coverage*
      reports:
          junit: Function.JUnit.xml


Integration Test:
    stage: Unit Testing
    image: python:3.6.9-slim
    before_script:
        - *PythonImageBuildModuleBefore_Script
        - python3 setup.py egg_info sdist bdist_wheel
    script:
        - coverage run --parallel-mode --branch --context=Integration_Testing --source gitlab_management test/test_integration.py
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH'
          changes:
          - gitlab_management/*.py
          - test/test_*.py
          - setup.py
          when: always
    artifacts:
      expire_in: 3 days
      paths:
          - Integration.JUnit.xml
          - gitlab_management/*.cover
          - .coverage*
      reports:
          junit: Integration.JUnit.xml



Coverage:
    stage: package
    image: python:3.6.9-slim
    variables:
        COVERAGE_DIR: public/$CI_COMMIT_BRANCH/coverage
    before_script:
        - *PythonImageBuildModuleBefore_Script
        - python3 setup.py egg_info sdist bdist_wheel
    script:
        - coverage combine --append
        - coverage report
        - coverage html --show-contexts -d public/$CI_COMMIT_BRANCH/coverage
        - coverage json -o badge_coverage.json
        - coverage xml -o UnitTesting_coverage.xml
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH'
          changes:
          - gitlab_management/*.py
          - setup.py
          - test/*.py
          when: on_success
    dependencies:
        - Unit Test
        - Function Test
        - Integration Test
    artifacts:
        expire_in: 60 days
        when: on_success
        paths:
            - UnitTesting_coverage.xml
            - public/*
            - badge_coverage.json
        reports:
          cobertura: UnitTesting_coverage.xml


gitlab-management_package:
    stage: package
    image: python:3.6.9-slim
    variables:
        GIT_PYTHON_GIT_EXECUTABLE: /bin/git
    before_script:
        - apt-get update && apt-get install -y --no-install-recommends git
        - *PythonImageBuildModuleBefore_Script
        - git --version
        - GIT_PYTHON_GIT_EXECUTABLE=$(which git)
        - echo $GIT_PYTHON_GIT_EXECUTABLE
        - echo $PATH
        - PATH=$PATH:$GIT_PYTHON_GIT_EXECUTABLE
        - python3 -m pip install --user --upgrade setuptools wheel
        - python3 -m pip install -r requirements.txt
    script:
        - python3 setup.py egg_info sdist bdist_wheel
    rules:
@@ -38,7 +209,7 @@ gitlab-management_package:
          - setup.py
          - README.md
          - CONTRIBUTING.md
          when: always
          when: on_success
    artifacts:
        expire_in: 3 days
        when: on_success
@@ -85,6 +256,31 @@ include:
  - template: SAST.gitlab-ci.yml



pages:
    stage: test
    dependencies:
        - Coverage
    script:
        - echo coverage reports to gitlab pages
    artifacts:
        paths:
            - public
        expire_in: 3 days
    rules:
        - if: $CI_COMMIT_TAG
          when: never
        - if: $CI_MERGE_REQUEST_IID
          when: never
        - if: '$CI_COMMIT_BRANCH'
          changes:
          - gitlab_management/*.py
          - setup.py
          - README.md
          - CONTRIBUTING.md
          when: on_success

          
variables:
    SAST_DEFAULT_ANALYZERS: "bandit"

@@ -151,8 +347,16 @@ gemnasium-python-dependency_scanning:
          changes:
          - gitlab_management/*.py
          - setup.py
          - requirements.txt
          - requirements.pip
          when: on_success
          allow_failure: false
    artifacts:
        paths:
            - gl-dependency-scanning-report.json
        reports:
            dependency_scanning: gl-dependency-scanning-report.json


# to activate licence approvals: https://docs.gitlab.com/ee/user/application_security/#enabling-license-approvals-within-a-project
license_scanning:
+43 −5
Changes for CONTRIBUTING.md: 43 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -48,6 +48,49 @@ python3 setup.py sdist bdist_wheel

>**Note:** you must increment the version in the build script (`buildinit.py`) prior to committing your final changes to the repo.

## running builds
Prior to committing to the repo, test builds need to be conducted. we have designed this to replicate gitlabs CI. Each stage of the `.gitlab-ci.yml` can be run from the command line using the following docker command


``` bash
docker run --privileged -w $PWD -v $PWD:$PWD -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:ubuntu-v13.0.0 exec docker ${Gitlab-CI Stage} -env "CI_COMMIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)" --docker-privileged --docker-volumes '/var/run/docker.sock:/var/run/docker.sock'
```
>**tip:** substitute `{Gitlab-CI Stage}` with one of the available stages below before running this command

Tested and confirmed `.gitlab-ci.yml` tasks as working with the above command
- **Verify**
    * PyLint
- **Unit Testing**
    * Unit Test
    * Function Test
- **package**
    * Coverage *- Not Working*
    * gitlab-management_package
- **build**
    * ~~Docker_Build-Alpine~~ *- not working*
- **test**
    * ~~pages~~ *- Only usable on GitLab*
    * ~~bandit-sast~~ *- Not Tested*
    * ~~Scan gitlab-management-Alpine~~ *- Not Tested*
    * ~~gemnasium-python-dependency_scanning~~ *- Not Tested*
    * ~~license_scanning~~ *- Not Tested*
- **validate**
    * ~~Documentation~~ *- Not Working*   
      **Tip:** use this command to build/test the docs 
      ```bash
      cd {Repo Directory}

      rm -Rf build bin docs/_build gitlab_management.egg-info lib include pyvenv.cfg

      CI_PROJECT_DIR=/Repository && docker run -e CI_PROJECT_DIR=$CI_PROJECT_DIR -w $CI_PROJECT_DIR -v $PWD:$CI_PROJECT_DIR readthedocs/build:latest bash test/validation-build-docs.sh
      ```
- **release**
    * ~~GitLab-Release~~ *- Only usable on GitLab*
- **publish**
    * ~~Publish~~ *- Only usable on GitLab*



### Version Changes
Every change, prior to being committed to the `development` branch, must have it's version incremented. In most cases only the `{newfeature}` number will need to be incremented.

@@ -171,11 +214,6 @@ Clean-up the environment prior to building the documentation, with:
rm -Rf build bin docs/_build gitlab_management.egg-info lib include pyvenv.cfg
```

To build the documentation run:
``` bash
cd {Repo Directory}
CI_PROJECT_DIR=/Repository && docker run -e CI_PROJECT_DIR=$CI_PROJECT_DIR -w $CI_PROJECT_DIR -v $PWD:$CI_PROJECT_DIR readthedocs/build:latest bash test/validation-build-docs.sh
```


>**Tip:**
+13 −3
Changes for README.md: 13 added lines, 3 removed lines.
Original line number Diff line number Diff line
# Python Gitlab Management

[![Pipelien Status - Stable](https://img.shields.io/badge/dynamic/json.svg?label=Pipeline-Stable&query=0.status&url=https://gitlab.com/api/v4/projects/19099644/pipelines?ref=master&color=ff782e&logo=gitlab&style=plastic)](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/) 
[![Pipelien Status - Dev](https://img.shields.io/badge/dynamic/json.svg?label=Pipeline-Dev&query=0.status&url=https://gitlab.com/api/v4/projects/19099644/pipelines/?ref=development&color=ff782e&logo=gitlab&style=plastic)](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/) 
![PyPi Version](https://img.shields.io/badge/dynamic/json?label=PyPi%20Package&query=$.info.version&url=https://pypi.org/pypi/gitlab-management/json&logo=python&logoColor=white&style=plastic) 
[![PyPi Version](https://img.shields.io/badge/dynamic/json?label=PyPi%20Package&query=$.info.version&url=https://pypi.org/pypi/gitlab-management/json&logo=pypi&logoColor=white&style=plastic)](https://pypi.org/project/gitlab-management/)
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-green.svg?style=plastic&logo=gnu&logocolor=white)](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/blob/master/LICENCE)



[![Pipelien Status - Stable](https://img.shields.io/badge/dynamic/json.svg?label=Pipeline%20%5Bstable%5D&query=0.status&url=https://gitlab.com/api/v4/projects/19099644/pipelines?ref=master&color=ff782e&logo=gitlab&style=plastic)](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/) 
[![Code Coverage - Stable](https://img.shields.io/badge/dynamic/json?color=F01F7A&label=Coverage%20%5Bstable%5D&query=%24.totals.percent_covered&suffix=%&logo=codecov&style=plastic&url=https%3A%2F%2Fnofusscomputing.gitlab.io%2Fprojects%2Fpython-gitlab-management%2Fmaster%2Fcoverage.json)](https://nofusscomputing.gitlab.io/projects/python-gitlab-management/master/coverage/) 
[![PyLint Score Master](https://img.shields.io/badge/dynamic/json?color=73398D&label=PyLint%20Score%20%5Bstable%5D&query=%24.PyLintScore&style=plastic&url=https:%2F%2Fgitlab.com%2Fnofusscomputing%2Fprojects%2Fpython-gitlab-management%2F-%2Fjobs%2Fartifacts%2Fmaster%2Ffile%2Fbadge_pylint.json?job=PyLint)](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/jobs/artifacts/master/file/gl-code-quality-report.html?job=PyLint)
[![Read the Docs (version)](https://img.shields.io/readthedocs/python-gitlab-management/stable?label=Docs%20stable&logo=readthedocs&style=plastic)](https://python-gitlab-management.readthedocs.io/en/stable/)


[![Pipelien Status - Dev](https://img.shields.io/badge/dynamic/json.svg?label=Pipeline%20%5BDev%5D&query=0.status&url=https://gitlab.com/api/v4/projects/19099644/pipelines/?ref=development&color=ff782e&logo=gitlab&style=plastic)](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/)
[![Code Coverage - dev](https://img.shields.io/badge/dynamic/json?color=F01F7A&label=Coverage%20%5BDev%5D&query=%24.totals.percent_covered&suffix=%&logo=codecov&style=plastic&url=https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/jobs/artifacts/development/file/badge_coverage.json?job=Coverage)](https://nofusscomputing.gitlab.io/projects/python-gitlab-management/development/coverage/)
[![PyLint Score Dev](https://img.shields.io/badge/dynamic/json?color=73398D&label=PyLint%20Score%20%5BDev%5D&query=%24.PyLintScore&style=plastic&url=https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/jobs/artifacts/development/file/badge_pylint.json?job=PyLint)](https://gitlab.com/nofusscomputing/projects/python-gitlab-management/-/jobs/artifacts/development/file/gl-code-quality-report.html?job=PyLint)
[![Read the Docs (version)](https://img.shields.io/readthedocs/python-gitlab-management/development?label=Docs%20devel&logo=readthedocs&style=plastic)](https://python-gitlab-management.readthedocs.io/en/development/)


Gitlab-management is python module that enables GitLab group configuration from code. By design it's intended to be setup to run on a schedule. 

## How to Use
+1 −1
Changes for buildinit.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ __license__ = "GNU LGPLv3"
__copyright__ = "(C) All Rights reserved"
__source__ = ''
__title__ = "gitlab-management"
__version__ = "0.1.4"
__version__ = "0.1.5"
__doc__ = "https://gitlab.com/nofusscomputing/projects/python-gitlab-management"

CurrentDirectory = './'
Loading