From 7d83a21d03127219c60897ade1025c6bb0937f44 Mon Sep 17 00:00:00 2001 From: Dan Callaghan Date: Mar 02 2017 19:46:15 +0000 Subject: RPM spec file --- diff --git a/.gitignore b/.gitignore index d7cbf6c..c35f24c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ conf/settings.py /env*/ test_env .cache +/rpmbuild-output/ diff --git a/Jenkinsfile b/Jenkinsfile index 6fedc2a..1fac7dc 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,12 +12,27 @@ node('rcm-tools-jslave-rhel-7') { checkout scm - stage('Test') { + 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 (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/**' + } + stage('Build RPM (F25)') { sh """ - virtualenv . - source bin/activate - pip install -r requirements.txt - py.test tests/ + 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/**' } } diff --git a/rpmbuild.sh b/rpmbuild.sh new file mode 100755 index 0000000..fadeddf --- /dev/null +++ b/rpmbuild.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# 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=waiverdb +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 --prefix="${name}-${version}/" HEAD | gzip >"$workdir/${name}-${version}.tar.gz" +git show HEAD:${name}.spec >"$workdir/${name}.spec" + +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" + # inject %prep commands to also hack the Python module versions + # (beware the precarious quoting here...) + commands=$(cat <"$workdir/${name}.spec.injected" + mv "$workdir/${name}.spec.injected" "$workdir/${name}.spec" +fi + +rpmbuild \ + --define "_topdir $workdir" \ + --define "_sourcedir $workdir" \ + --define "_specdir $workdir" \ + --define "_rpmdir $outdir" \ + --define "_srcrpmdir $outdir" \ + "$@" "$workdir/${name}.spec" diff --git a/setup.py b/setup.py index c306a87..5a80156 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -version = '1.0.0' +version = '0.0' setup(name='waiverdb', version=version, diff --git a/waiverdb.spec b/waiverdb.spec new file mode 100644 index 0000000..9b00bda --- /dev/null +++ b/waiverdb.spec @@ -0,0 +1,47 @@ + +%global upstream_version 0.0 + +Name: waiverdb +Version: 0.0 +Release: 1%{?dist} +Summary: Service for waiving results in ResultsDB +License: GPLv2+ +URL: https://pagure.io/waiverdb +Source0: %{name}-%{upstream_version}.tar.gz + +BuildRequires: python2-devel +BuildRequires: python-setuptools +BuildRequires: python-flask +BuildRequires: python-sqlalchemy +BuildRequires: python-flask-restful +BuildRequires: python-flask-sqlalchemy +BuildRequires: pytest +BuildArch: noarch +Requires: python-flask +Requires: python-sqlalchemy +Requires: python-flask-restful +Requires: python-flask-sqlalchemy + +%description +. + +%prep +%setup -q -n %{name}-%{upstream_version} + +%build +%py2_build + +%install +%py2_install + +%check +export PYTHONPATH=%{buildroot}/%{python2_sitelib} +py.test tests/ + +%files +%license COPYING +%doc README.md +%{python2_sitelib}/%{name} +%{python2_sitelib}/%{name}*.egg-info + +%changelog