Permalink
Browse files

Create QA jenkins jobs per package

All packages listed on that project will automatically monitor github
for changes and report back to the commits itself about the result of code analysis.
  • Loading branch information...
gforcada committed Jan 28, 2016
1 parent 8508247 commit 13c1c1fd00b8966379b357079db5f231f97db321
Showing with 129 additions and 37 deletions.
  1. +6 −37 jobs.yml
  2. +115 −0 scripts/pkg-qa-report.py
  3. +8 −0 scripts/pkg-qa.sh
View
@@ -208,26 +208,8 @@
- project:
name: per-package job
package:
- plone.app.discussion
- plone.autoform
- plone.batching
- plone.behavior
- plone.browserlayer
- plone.cachepurging
- plone.caching
- plone.contentrules
- plone.dexterity
- plone.directives.form
- plone.directives.tiles
- plone.event
- plone.folder
- plone.formwidget.autocomplete
- plone.formwidget.contenttree
- plone.formwidget.datetime
- plone.formwidget.namedfile
- plone.formwidget.querystring
- plone.formwidget.recurrence
- plone.i18n
- plone.app.discussion:
top-level: 'plone'
jobs:
- 'package-{package}'
@@ -849,23 +831,10 @@
wipe-workspace: false
builders:
- shell: |
wget https://raw.githubusercontent.com/plone/buildout.coredev/5.0/bootstrap.py -O bootstrap.py
cat > jenkins.cfg << EOF
[buildout]
develop = .
parts =
code-analysis
[code-analysis]
recipe = plone.recipe.codeanalysis
directory = .
pre-commit-hook = False
jenkins = True
EOF
$PYTHON27 bootstrap.py --setuptools-version 19.4 -c jenkins.cfg
bin/buildout -c jenkins.cfg
bin/code-analysis
- shell:
!include-raw: scripts/pkg-qa.sh
- python:
!include-raw: scripts/pkg-qa-report.py
publishers:
- violations:
View
@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*-
from github import Github
from github.GithubException import BadCredentialsException
from github.GithubException import UnknownObjectException
import os
import re
import sys
with open('parts/code-analysis/flake8.log') as flake8_log:
flake8_errors = flake8_log.read()
if flake8_errors == '':
print('No flake8 errors found, nothing to report')
sys.exit(0)
try:
github_api_key = os.environ['GITHUB_API_KEY']
except KeyError:
print(
'\n\n\n'
'GITHUB_API_KEY does not exist, package QA job can not run. '
'\n'
'Please contact the testing team: '
'https://github.com/orgs/plone/teams/testing-team'
'\n'
'Fill an issue as well: '
'https://github.com/plone/jenkins.plone.org/issues/new'
'\n\n\n'
)
sys.exit(1)
GIT_URL_RE = r'github\.com/(.*)/(.*).git'
build_url = os.environ['BUILD_URL']
job_name = os.environ['JOB_NAME']
git_url = os.environ['GIT_URL']
git_commit = os.environ['GIT_COMMIT']
g = Github(github_api_key)
try:
org, repo = re.search(GIT_URL_RE, git_url).groups()
except AttributeError, ValueError:
msg = (
'\n\n\n'
'Error on trying to get info from the git URL %s'
'\n\n\n'
)
print(msg % git_url)
sys.exit(1)
# get the organization
try:
g_org = g.get_organization(org)
except BadCredentialsException:
print(
'\n\n\n'
'The API key used seems to not be valid any longer.'
'\n'
'Please contact the testing team: '
'https://github.com/orgs/plone/teams/testing-team'
'\n'
'Fill an issue as well: '
'https://github.com/plone/jenkins.plone.org/issues/new'
'\n\n\n'
)
sys.exit(1)
except UnknownObjectException:
msg = (
'\n\n\n'
'Error: the organization "%s" does not seem to exist.'
'\n\n\n'
)
print(msg % org)
sys.exit(1)
# get the repo
try:
g_repo = g_org.get_repo(repo)
except UnknownObjectException:
msg = (
'\n\n\n'
'Error: the repository "%s" does not seem to exist.'
'\n\n\n'
)
print(msg % repo)
sys.exit(1)
# get the commit
try:
g_commit = g_repo.get_commit(git_commit)
except UnknownObjectException:
msg = (
'\n\n\n'
'Error: the commit "%s" does not seem to exist.'
'\n\n\n'
)
print(msg % git_commit)
sys.exit(1)
author = g_commit.author.login
header = '@%s Jenkins CI reporting about code analysis\n' % author
footer = 'You can run that yourself using buildout.coredev ``experimental/qa.cfg`` config file.'
comment = '%s```\n%s```\n%s' % (
header,
flake8_errors,
footer
)
g_commit.create_comment(
body=comment
)
View
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
wget https://raw.githubusercontent.com/plone/buildout.coredev/5.0/bootstrap.py -O bootstrap.py
wget https://raw.githubusercontent.com/plone/buildout.coredev/5.0/experimental/qa.cfg -O qa.cfg
wget https://raw.githubusercontent.com/plone/plone.recipe.codeanalysis/master/.isort.cfg -O .isort.cfg
sed -i 's#directory = src#directory = {top-level}#' qa.cfg
$PYTHON27 bootstrap.py --setuptools-version 19.4 -c qa.cfg
bin/buildout -c qa.cfg
bin/code-analysis

0 comments on commit 13c1c1f

Please sign in to comment.