Browse Source

CI with Azure Pipelines (#198)

Enhances issue #180
Vince Salvino 5 years ago
parent
commit
82414acca2
7 changed files with 120 additions and 29 deletions
  1. 2 1
      .coveragerc
  2. 17 4
      .gitignore
  3. 0 18
      .travis.yml
  4. 65 0
      azure-pipelines.yml
  5. 19 0
      ci/run_flake8.ps1
  6. 10 2
      docs/contributing/index.rst
  7. 7 4
      setup.py

+ 2 - 1
.coveragerc

@@ -10,4 +10,5 @@ exclude_lines =
     if __name__ == .__main__.:
 ignore_errors = True
 omit =
-    */migrations/*
+    */migrations/*
+    */project_template/*

+ 17 - 4
.gitignore

@@ -1,15 +1,28 @@
-*.pyc
+# Randoms
 *Thumbs.db
-*~
-*.sqlite3
 *.txz
+*.tar.xz
 *.tgz
-media/
+*.tar.gz
+*.sqlite3
+*.sql
+
+# Python
+*.pyc
 build/
 _build/
 dist/
 __pycache__
 codered_cms.egg-info/
 coderedcms.egg-info/
+
+# Editors
 .vscode/
+*~
+
+# Development & testing
+.coverage
+htmlcov/
+junit/
+coverage.xml
 testproject*/

+ 0 - 18
.travis.yml

@@ -1,18 +0,0 @@
-dist: xenial
-language: python
-python:
-  - "3.4"
-  - "3.5"
-  - "3.6"
-  - "3.7"
-install:
-  - pip install -e './[ci]'
-  - pip install codecov
-before_script:
-  - coderedcms start testproject
-# command to run tests
-script:
-  - coverage run testproject/manage.py test coderedcms --settings=coderedcms.tests.settings
-  - flake8 coderedcms testproject --exit-zero
-after_success:
-  - codecov

+ 65 - 0
azure-pipelines.yml

@@ -0,0 +1,65 @@
+# Python Django
+# Test a Django project on multiple versions of Python.
+# Add steps that analyze code, save build artifacts, deploy, and more:
+# https://docs.microsoft.com/azure/devops/pipelines/languages/python
+
+# NTOES:
+#
+# Display name of each step should be prefixed with one of the following:
+#   CR-QC: for quality control measures.
+#   CR-BUILD: for build-related tasks.
+#   CR-DEPLOY: for publication or deployment.
+#   [no prefix]: for unrelated CI setup/tooling.
+#
+# Use PowerShell Core for any scripts so they are re-usable across windows/mac/linux.
+#
+
+trigger:
+  - master
+
+pool:
+  vmImage: 'ubuntu-latest'
+strategy:
+  matrix:
+    py3.5:
+      PYTHON_VERSION: '3.5'
+    py3.6:
+      PYTHON_VERSION: '3.6'
+    py3.7:
+      PYTHON_VERSION: '3.7'
+
+steps:
+- task: UsePythonVersion@0
+  displayName: 'Use Python version'
+  inputs:
+    versionSpec: '$(PYTHON_VERSION)'
+    architecture: 'x64'
+
+- script: |
+    python -m pip install -e ./[ci]
+  displayName: 'CR-QC: Install coderedcms from local repo'
+
+- script: |
+    coderedcms start testproject --name="Test Project" --domain="www.example.com"
+  displayName: 'CR-QC: Create starter project from template'
+
+- script: |
+    pytest coderedcms/ --ds=coderedcms.tests.settings --junitxml=junit/test-results.xml --cov=coderedcms --cov-report=xml --cov-report=html
+  displayName: 'CR-QC: Run unit tests'
+
+- pwsh: |
+    & ci/run_flake8.ps1
+  displayName: 'CR-QC: Static analysis'
+
+- task: PublishTestResults@2
+  displayName: 'Publish unit test report'
+  condition: succeededOrFailed()
+  inputs:
+    testResultsFiles: '**/test-*.xml'
+    testRunTitle: 'Publish test results for Python $(python.version)'
+
+- task: PublishCodeCoverageResults@1
+  displayName: 'Publish code coverage report'
+  inputs:
+    codeCoverageTool: Cobertura
+    summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml'

+ 19 - 0
ci/run_flake8.ps1

@@ -0,0 +1,19 @@
+$ExitCode = 0
+# If we're on master then flake8 everything.
+$GitBranch = git rev-parse --abbrev-ref HEAD
+if ( $GitBranch -eq "master") {
+    flake8 coderedcms testproject
+    if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
+}
+# Else flake8 just the diff.
+else {
+    git diff origin/master | flake8 --diff
+    if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
+    # If the project_template changed, then flake8 the testproject too.
+    $GitDiffTempl = git diff origin/master | Select-String -Pattern "^diff .*/project_template/.*"
+    if ( $GitDiffTempl -ne $null ) {
+        flake8 testproject
+        if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
+    }
+}
+exit $ExitCode

+ 10 - 2
docs/contributing/index.rst

@@ -92,11 +92,19 @@ license header comment states copyright, ownership, license, and also provides c
 Testing CodeRed CMS
 -------------------
 
-To run the built in tests for CodeRed CMS, run the following in your test project's directory:
+To run the built in tests for CodeRed CMS using Django, run the following:
 
 .. code-block:: console
 
-    $ python manage.py test coderedcms --settings=coderedcms.tests.settings
+    $ python testproject/manage.py test coderedcms --settings=coderedcms.tests.settings
+
+Or, to use ``pytest`` and output a unit test report and code coverage report (this how CI runs the tests):
+
+.. code-block:: console
+
+    $ pytest coderedcms/ --ds=coderedcms.tests.settings --junitxml=junit/test-results.xml --cov=coderedcms --cov-report=xml --cov-report=html
+
+Detailed test coverage reports are now available by opening ``htmlcov/index.html`` in your browser (which is ignored by version control)
 
 
 Adding New Tests

+ 7 - 4
setup.py

@@ -54,15 +54,18 @@ setup(
     ],
     extras_require={
         'dev': [
-            'libsass',
             'flake8',
+            'libsass',
+            'pytest-cov',
+            'pytest-django',
             'sphinx',
             'twine',
             'wheel'
         ],
-        'ci' : [
-            'coverage',
-            'flake8'
+        'ci': [
+            'flake8',
+            'pytest-cov',
+            'pytest-django',
         ]
     },
     entry_points="""