From 5ff9b6851226e39744b37c3399d0c2c716a3a6e5 Mon Sep 17 00:00:00 2001 From: Matt Jia Date: Jun 28 2017 04:18:33 +0000 Subject: add Jenkinsfile --- diff --git a/.gitignore b/.gitignore index c52bac5..fc35049 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ docs/_build/ eggs/ *egg-info/ *.egg +/rpmbuild-output/ # Vim temporary files *~ diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..33ae28a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,92 @@ +/* + * SPDX-License-Identifier: GPL-2.0+ +*/ + +try { // massive try{} catch{} around the entire build for failure notifications + +node('fedora') { + checkout scm + sh 'sudo dnf -y builddep greenwave.spec' + sh 'sudo dnf -y install python2-flake8 pylint python2-sphinx python-sphinxcontrib-httpdomain' + stage('Invoke Flake8') { + sh 'flake8' + } + stage('Invoke Pylint') { + sh 'pylint --reports=n greenwave' + } + stage('Build Docs') { + sh 'make -C docs html' + archiveArtifacts artifacts: 'docs/_build/html/**' + } + /* Can't use GIT_BRANCH because of this issue https://issues.jenkins-ci.org/browse/JENKINS-35230 */ + def git_branch = sh(returnStdout: true, script: 'git rev-parse --abbrev-ref HEAD').trim() + if (git_branch == 'master') { + stage('Publish Docs') { + sshagent (credentials: ['pagure-greenwave-deploy-key']) { + sh ''' + mkdir -p ~/.ssh/ + touch ~/.ssh/known_hosts + ssh-keygen -R pagure.io + echo 'pagure.io,140.211.169.204 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC198DWs0SQ3DX0ptu+8Wq6wnZMrXUCufN+wdSCtlyhHUeQ3q5B4Hgto1n2FMj752vToCfNTn9mWO7l2rNTrKeBsELpubl2jECHu4LqxkRVihu5UEzejfjiWNDN2jdXbYFY27GW9zymD7Gq3u+T/Mkp4lIcQKRoJaLobBmcVxrLPEEJMKI4AJY31jgxMTnxi7KcR+U5udQrZ3dzCn2BqUdiN5dMgckr4yNPjhl3emJeVJ/uhAJrEsgjzqxAb60smMO5/1By+yF85Wih4TnFtF4LwYYuxgqiNv72Xy4D/MGxCqkO/nH5eRNfcJ+AJFE7727F7Tnbo4xmAjilvRria/+l' >>~/.ssh/known_hosts + git clone ssh://git@pagure.io/docs/greenwave.git docs-on-pagure + rm -r docs-on-pagure/* + cp -r docs/_build/html/* docs-on-pagure/ + cd docs-on-pagure + git add -A . + if [[ "$(git diff --cached --numstat | wc -l)" -eq 0 ]] ; then + exit 0 # No changes, nothing to commit + fi + git commit -m 'Automatic commit of docs built by Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER}' + git push origin master + ''' + } + } + } + stage('Build SRPM') { + sh './rpmbuild.sh -bs' + archiveArtifacts artifacts: 'rpmbuild-output/**' + } + /* We take a flock on the mock configs, to avoid multiple unrelated jobs on + * the same Jenkins slave trying to use the same mock root at the same + * time, which will error out. */ + stage('Build RPM') { + parallel ( + 'EPEL7': { + sh """ + mkdir -p mock-result/el7 + flock /etc/mock/epel-7-x86_64.cfg \ + /usr/bin/mock --resultdir=mock-result/el7 -r epel-7-x86_64 --clean --rebuild rpmbuild-output/*.src.rpm + """ + archiveArtifacts artifacts: 'mock-result/el7/**' + }, + 'F25': { + sh """ + mkdir -p mock-result/f25 + flock /etc/mock/fedora-25-x86_64.cfg \ + /usr/bin/mock --resultdir=mock-result/f25 -r fedora-25-x86_64 --clean --rebuild rpmbuild-output/*.src.rpm + """ + archiveArtifacts artifacts: 'mock-result/f25/**' + }, + ) + } + stage('Invoke Rpmlint') { + parallel ( + 'EPEL7': { + sh 'rpmlint -f rpmlint-config.py mock-result/el7/*.rpm' + }, + 'F25': { + sh 'rpmlint -f rpmlint-config.py mock-result/f25/*.rpm' + }, + ) + } + /* XXX: run functional tests in OpenShift when UpShift is ready */ +} +} catch (e) { + if (ownership.job.ownershipEnabled) { + mail to: ownership.job.primaryOwnerEmail, + cc: ownership.job.secondaryOwnerEmails.join(', '), + subject: "Jenkins job ${env.JOB_NAME} #${env.BUILD_NUMBER} failed", + body: "${env.BUILD_URL}\n\n${e}" + } + throw e +} diff --git a/MANIFEST.in b/MANIFEST.in index 14a820d..1f707df 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,4 @@ include COPYING README.md requirements.txt dev-requirements.txt +include pytest.ini +recursive-include conf * +recursive-include docs *.py *.rst *.inv Makefile diff --git a/docs/conf.py b/docs/conf.py index 336a242..e084209 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Greenwave documentation build configuration file, created by @@ -20,7 +19,6 @@ import os import sys sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../'))) - import greenwave # noqa: E402 @@ -183,4 +181,4 @@ epub_exclude_files = ['search.html'] # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/': None} +intersphinx_mapping = {'https://docs.python.org/2/': 'python-intersphinx.inv'} diff --git a/greenwave.spec b/greenwave.spec new file mode 100644 index 0000000..825531e --- /dev/null +++ b/greenwave.spec @@ -0,0 +1,64 @@ + +%global upstream_version 0.0 + +Name: greenwave +Version: 0.0 +Release: 1%{?dist} +Summary: Service for gating on automated tests +License: GPLv2+ +URL: https://pagure.io/greenwave +Source0: https://files.pythonhosted.org/packages/source/w/%{name}/%{name}-%{upstream_version}.tar.gz + +BuildRequires: python2-devel +%if 0%{?fedora} || 0%{?rhel} > 7 +BuildRequires: python2-setuptools +BuildRequires: python2-sphinx +BuildRequires: python-sphinxcontrib-httpdomain +BuildRequires: python2-flask +BuildRequires: python2-pytest +BuildRequires: python2-requests +%else # EPEL7 uses python- naming +BuildRequires: python-setuptools +BuildRequires: python-flask +BuildRequires: pytest +BuildRequires: python-requests +%endif +BuildArch: noarch +%if 0%{?fedora} || 0%{?rhel} > 7 +Requires: python2-flask +Requires: python2-requests +%else # EPEL7 uses python- naming +Requires: python-flask +Requires: python-requests +%endif + +%description +Greenwave is a service for gating on automated tests by querying ResultsDB and +WaiverDB. + +%prep +%setup -q -n %{name}-%{upstream_version} + +%build +%py2_build +%if 0%{?fedora} +make -C docs html text +%endif + +%install +%py2_install + +%check +export PYTHONPATH=%{buildroot}/%{python2_sitelib} +py.test greenwave/tests/ + +%files +%license COPYING +%doc README.md conf +%if 0%{?fedora} +%doc docs/_build/html docs/_build/text +%endif +%{python2_sitelib}/%{name} +%{python2_sitelib}/%{name}*.egg-info + +%changelog diff --git a/greenwave/__init__.py b/greenwave/__init__.py index f29e19c..208c2ed 100644 --- a/greenwave/__init__.py +++ b/greenwave/__init__.py @@ -8,5 +8,4 @@ It provides a :ref:`http-api` for applications to use. .. _Flask: http://flask.pocoo.org/ .. _SQLAlchemy: http://sqlalchemy.org/ """ - -__version__ = '0.1.0' +__version__ = '0.0.1' diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..bfe20a0 --- /dev/null +++ b/pylintrc @@ -0,0 +1,2 @@ +[MESSAGES CONTROL] +disable=R,C,no-member,fixme,W0622 diff --git a/rpmbuild.sh b/rpmbuild.sh new file mode 100755 index 0000000..9dabcb9 --- /dev/null +++ b/rpmbuild.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# SPDX-License-Identifier: GPL-2.0+ + +# Builds a development (S)RPM from the current git revision. + +set -e + +if [ $# -eq 0 ] ; then + echo "Usage: $1 -bs|-bb " >&2 + echo "Hint: -bs builds SRPM, -bb builds RPM, refer to rpmbuild(8)" >&2 + exit 1 +fi + +name=greenwave +if [ "$(git tag | wc -l)" -eq 0 ] ; then + # never been tagged since the project is just starting out + lastversion="0.0" + revbase="" +else + lasttag="$(git describe --abbrev=0 HEAD)" + lastversion="${lasttag##${name}-}" + revbase="^$lasttag" +fi +if [ "$(git rev-list $revbase HEAD | wc -l)" -eq 0 ] ; then + # building a tag + rpmver="" + rpmrel="" + version="$lastversion" +else + # git builds count as a pre-release of the next version + version="$lastversion" + version="${version%%[a-z]*}" # strip non-numeric suffixes like "rc1" + # increment the last portion of the version + version="${version%.*}.$((${version##*.} + 1))" + commitcount=$(git rev-list $revbase HEAD | wc -l) + commitsha=$(git rev-parse --short HEAD) + rpmver="${version}" + rpmrel="0.git.${commitcount}.${commitsha}" + version="${version}.dev${commitcount}+git.${commitsha}" +fi + +workdir="$(mktemp -d)" +trap "rm -rf $workdir" EXIT +outdir="$(readlink -f ./rpmbuild-output)" +mkdir -p "$outdir" + +git archive --format=tar HEAD | tar -C "$workdir" -xf - +if [ -n "$rpmrel" ] ; then + # need to hack the version in the spec + sed --regexp-extended --in-place \ + -e "/%global upstream_version /c\%global upstream_version ${version}" \ + -e "/^Version:/cVersion: ${rpmver}" \ + -e "/^Release:/cRelease: ${rpmrel}%{?dist}" \ + "$workdir/${name}.spec" + # also hack the Python module version + sed --regexp-extended --in-place \ + -e "/^__version__ = /c\\__version__ = '$version'" \ + "$workdir/greenwave/__init__.py" +fi +( cd "$workdir" && python setup.py sdist ) +mv "$workdir"/dist/*.tar.gz "$workdir" + +rpmbuild \ + --define "_topdir $workdir" \ + --define "_sourcedir $workdir" \ + --define "_specdir $workdir" \ + --define "_rpmdir $outdir" \ + --define "_srcrpmdir $outdir" \ + "$@" "$workdir/${name}.spec" diff --git a/rpmlint-config.py b/rpmlint-config.py new file mode 100644 index 0000000..833daa9 --- /dev/null +++ b/rpmlint-config.py @@ -0,0 +1,5 @@ +from Config import addFilter +# RPMs built from git have no %changelog, the proper ones maintained from dist-git do though +addFilter(r'no-changelogname-tag') +# RPMs built from git have no source tarball uploaded to PYPI +addFilter(r'invalid-url') diff --git a/setup.py b/setup.py index 7f23873..2f5a0ea 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ import os import re - from setuptools import setup, find_packages @@ -21,13 +20,13 @@ def get_project_version(version_file='greenwave/__init__.py'): be in the format ``__version__ = ''`` and the file must be UTF-8 encoded. """ - with open(version_file, "rb") as f: - version_pattern = b"^__version__ = '(.+)'$" + with open(version_file, 'r') as f: + version_pattern = "^__version__ = '(.+)'$" match = re.search(version_pattern, f.read(), re.MULTILINE) if match is None: - err_msg = "No line matching %r found in %r" + err_msg = 'No line matching %r found in %r' raise ValueError(err_msg % (version_pattern, version_file)) - return match.groups()[0].decode("utf-8") + return match.group(1) def get_requirements(requirements_file='requirements.txt'): @@ -88,7 +87,7 @@ setup( maintainer_email='infrastructure@lists.fedoraproject.org', platforms=['Fedora', 'GNU/Linux'], url='https://pagure.io/greenwave/', - packages=find_packages(exclude=('greenwave.tests', 'greenwave.tests.*')), + packages=find_packages(), include_package_data=True, zip_safe=False, install_requires=get_requirements(),