From 8dd994e4690f5e508372637587094245fa13cc89 Mon Sep 17 00:00:00 2001 From: Danila Vershinin <250071+dvershinin@users.noreply.github.com> Date: Wed, 14 Jul 2021 22:15:39 +0300 Subject: [PATCH] Update spec files #26 WIP --- .github/workflows/pythonpackage.yml | 8 ++ lastversion/lastversion.py | 75 +++++++++-- tests/brotli.spec | 38 +++++- tests/libmozjpeg.spec | 187 ++++++++++++++++++++++++++++ 4 files changed, 291 insertions(+), 17 deletions(-) create mode 100644 tests/libmozjpeg.spec diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 021c1dbd..9b1f4895 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -33,3 +33,11 @@ jobs: pytest -v -n auto env: GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Update spec + run: | + cd tests + lastversion tests/brotli.spec + lastversion tests/nginx-module-immutanle + lastversion tests/libmozjpeg.spec + - name: Build updated specs + uses: docker://getpagespeed/rpmbuilder:centos-8 \ No newline at end of file diff --git a/lastversion/lastversion.py b/lastversion/lastversion.py index 21d8b827..3b0d1267 100644 --- a/lastversion/lastversion.py +++ b/lastversion/lastversion.py @@ -19,6 +19,7 @@ import yaml from appdirs import user_cache_dir +from os.path import expanduser from cachecontrol import CacheControl from cachecontrol.caches.file_cache import FileCache # from cachecontrol.heuristics import ExpiresAfter @@ -96,14 +97,14 @@ def latest(repo, output_format='version', pre_ok=False, assets_filter=None, elif l.startswith('%global upstream_name'): upstream_name = l.split(' ')[2].strip() elif l.startswith('Name:'): - name = l.split(' ')[1].strip() + name = l.split('Name:')[1].strip() elif l.startswith('%global upstream_version '): current_version = l.split(' ')[2].strip() elif l.startswith('Version:') and not current_version: - current_version = l.split(' ')[1].strip() + current_version = l.split('Version:')[1].strip() if not upstream_github: log.critical('%upstream_github macro not found. Please prepare your spec file ' - 'using instructions: ') + 'using instructions: https://github.com/dvershinin/lastversion/wiki/Preparing-RPM-spec-files') if not current_version: log.critical('Did not find neither Version: nor %upstream_version in the spec file') sys.exit(1) @@ -121,7 +122,7 @@ def latest(repo, output_format='version', pre_ok=False, assets_filter=None, repo_data['name'] = name repo_data['spec_name'] = '%{name}' repo = "{}/{}".format(upstream_github, repo_data['name']) - + log.info('Discovered GitHub repo {} from .spec file'.format(repo)) if (not at or '/' in repo) and at != 'helm_chart': # find the right hosting for this repo @@ -263,13 +264,39 @@ def parse_version(tag): return h.sanitize_version(tag, pre_ok=True) -def update_spec(repo, res): +def get_rpm_packager(): + rpmmacros = expanduser("~") + "/.rpmmacros" + with open(rpmmacros) as f: + for ln in f.readlines(): + if ln.startswith('%packager'): + return ln.split('%packager')[1].strip() + return None + + +def update_spec(repo, res, sem='minor'): if 'current_version' not in res or res['current_version'] < res['version']: - log.warning('Updating spec {}'.format(repo)) + log.info('Updating spec {} with semantic {}'.format(repo, sem)) + if 'current_version' in res and len(res['version'].release) >= 3: + current_major = res['current_version'].release[0] + latest_major = res['version'].release[0] + current_minor = res['current_version'].release[1] + latest_minor = res['version'].release[1] + if sem in ['minor', 'patch']: + fail_fmt = 'Latest v{} fails semantic {} constraint against current v{}' + if latest_major != current_major: + log.warning( + fail_fmt.format(res['version'], sem, res['current_version'])) + sys.exit(4) + if sem == 'patch' and latest_minor != current_minor: + log.warning( + fail_fmt.format(res['version'], sem, res['current_version'])) + sys.exit(4) else: - log.warning('No newer version than already present in spec file') + log.info('No newer version than already present in spec file') + sys.exit(2) # update %lastversion_tag and %lastversion_dir, Version (?), Release out = [] + packager = get_rpm_packager() with open(repo) as f: for ln in f.readlines(): if ln.startswith('%global lastversion_tag '): @@ -280,11 +307,28 @@ def update_spec(repo, res): elif ln.startswith('%global upstream_version '): out.append('%global upstream_version {}'.format(res['version'])) elif ln.startswith('Version:') and ('module_of' not in res or not res['module_of']): - out.append('Version: {}'.format(res['version'])) + version_tag_regex = r'^Version:(\s+)(\S+)' + m = re.match(version_tag_regex, ln) + out.append('Version:' + m.group(1) + str(res['version'])) + elif ln.startswith('%changelog') and packager: + import datetime + today = datetime.date.today() + today = today.strftime('%a %b %d %Y') + out.append(ln.rstrip()) + out.append('* {} {}'.format(today, packager)) + out.append('- upstream release v{}'.format(res['version'])) + out.append("\n") + elif ln.startswith('Release:'): + release_tag_regex = r'^Release:(\s+)(\S+)' + m = re.match(release_tag_regex, ln) + release = m.group(2) + from string import digits + release = release.lstrip(digits) + out.append('Release:' + m.group(1) + '1' + release) else: out.append(ln.rstrip()) - print("\n".join(out)) - + with open(repo, "w") as f: + f.write("\n".join(out)) def main(): @@ -302,6 +346,8 @@ def main(): # affects what is considered last release parser.add_argument('--pre', dest='pre', action='store_true', help='Include pre-releases in potential versions') + parser.add_argument('--sem', dest='sem', choices=['major', 'minor', 'patch'], + help='Semantic version constraint against compared version') parser.add_argument('-v', '--verbose', action='count', default=0, help='Will give you an idea of what is happening under the hood, ' '-vv to increase verbosity level') @@ -399,11 +445,16 @@ def main(): if args.action == 'install': # we can only install assets args.format = 'json' - + if args.repo.endswith('.spec'): args.action = 'update-spec' args.format = 'dict' + if not args.sem: + if args.action == 'update-spec': + args.sem = 'minor' + else: + args.sem = 'any' # imply source download, unless --assets specified # --download is legacy flag to specify download action or name of desired download file # --download == None indicates download intent where filename is based on upstream @@ -433,7 +484,7 @@ def main(): if res: if args.action == 'update-spec': - return update_spec(args.repo, res) + return update_spec(args.repo, res, sem=args.sem) if args.action == 'download': # download command if args.format == 'source': diff --git a/tests/brotli.spec b/tests/brotli.spec index e4a0bc32..33caa62c 100644 --- a/tests/brotli.spec +++ b/tests/brotli.spec @@ -17,9 +17,9 @@ %global python3_pkgversion 3 %endif -Name: brotli -Version: 2.0.0 -Release: 1%{?dist} +Name: brotli +Version: x +Release: 1%{?dist} Summary: Lossless compression algorithm License: MIT @@ -76,7 +76,7 @@ This package installs a Python 3 module. %package -n %{name}-devel Summary: Lossless compression algorithm (development files) -Requires: %{name}%{?_isa} = %{version}-%{release} +Requires: %{name}%{?_isa} = %{version}-%{release} %description -n %{name}-devel Brotli is a generic-purpose lossless compression algorithm that compresses @@ -180,6 +180,34 @@ cd .. %changelog +* Wed Jul 14 2021 Danila Vershinin +- upstream release v1.0.9 + + +* Wed Jul 14 2021 Danila Vershinin +- upstream release v1.0.9 + + +* Wed Jul 14 2021 Danila Vershinin +- upstream release v1.0.9 + + +* Wed Jul 14 2021 Danila Vershinin +- upstream release v1.0.9 + + +* Wed Jul 14 2021 Danila Vershinin +- upstream release v1.0.9 + + +* Wed Jul 14 2021 Danila Vershinin +- upstream release v1.0.9 + + +* Wed Jul 14 2021 Danila Vershinin +- upstream release v1.0.9 + + * Thu Aug 27 2020 Danila Vershinin 1.0.8-1 - release 1.0.8 @@ -235,4 +263,4 @@ cd .. - include libraries and development files * Sat May 06 2017 Travis Kendrick - 0.6.0-1 -- Initial build +- Initial build \ No newline at end of file diff --git a/tests/libmozjpeg.spec b/tests/libmozjpeg.spec new file mode 100644 index 00000000..9f817e12 --- /dev/null +++ b/tests/libmozjpeg.spec @@ -0,0 +1,187 @@ +%global upstream_github mozilla +%global upstream_name mozjpeg +%global lastversion_tag x +%global lastversion_dir x + +Name: libmozjpeg +Version: 3.3.1 +Release: 5%{?dist} +Summary: MozJPEG, the improved JPEG encoder. Drop-in library + +# Disable automatic .so provides like 'libjpeg.so.62(LIBJPEGTURBO_6.2)(64bit)' +# so that this package is not installed by accident by dependent programs +# this package must be explicitly installed by a user +AutoReqProv: no + +License: BSD +URL: https://github.com/%{upstream_github}/%{name} +Source0: %{url}/archive/%{lastversion_tag}/%{name}-%{lastversion_tag}.tar.gz + +BuildRequires: autoconf +BuildRequires: automake +BuildRequires: libtool + +%ifarch %{ix86} x86_64 +BuildRequires: nasm +%endif + +%description +%{name} reduces file sizes of JPEG images while retaining quality and +compatibility with the vast majority of the world's deployed decoders. + +%{name} is a JPEG image codec that uses SIMD instructions (MMX, SSE2, +NEON) to accelerate baseline JPEG compression and decompression on x86, x86-64, +and ARM systems. On such systems, %{name} is generally 2-4x as fast as +libjpeg, all else being equal. On other types of systems, %{name} can +still outperform libjpeg by a significant amount, by virtue of its +highly-optimized Huffman coding routines. In many cases, the performance of +%{name} rivals that of proprietary high-speed JPEG codecs. + +%{name} implements both the traditional libjpeg API as well as the less +powerful but more straightforward TurboJPEG API. %{name} also features +colorspace extensions that allow it to compress from/decompress to 32-bit and +big-endian pixel buffers (RGBX, XBGR, etc.), as well as a full-featured Java +interface. + +%{name} was forked from libjpeg-turbo. + + +%package utils +Summary: Utilities for manipulating JPEG images +Requires: %{name}%{?_isa} = %{version}-%{release} + + +%description utils +The %{name}-utils package contains simple client programs for accessing +the libjpeg functions. It contains cjpeg, djpeg, jpegtran, rdjpgcom and +wrjpgcom (with "moz" prefix, e.g. mozcjpeg). +Cjpeg compresses an image file into JPEG format. Djpeg decompresses a +JPEG file into a regular image file. Jpegtran can perform various useful +transformations on JPEG files. Rdjpgcom displays any text comments included in a +JPEG file. Wrjpgcom inserts text comments into a JPEG file. + + +%package devel +Summary: Development files for %{name} +Requires: %{name}%{?_isa} = %{version}-%{release} +AutoReqProv: no + + +%description devel +The %{name}-devel package contains libraries and header files for +developing applications that use %{name}. + + +%package static +Summary: Static libraries for %{name} +Requires: %{name}-devel%{?_isa} = %{version}-%{release} + + +%description static +The %{name}-static package contains static libraries for +developing applications that use %{name}. + + +%prep +%setup -q -n %{upstream_name}-%{version} +sed -i 's@27-Mar-1998@17-Mar-2018 MozJPEG, GetPageSpeed@' jversion.h + + +%build +autoreconf -fiv +#%%configure --disable-static +%configure --libdir=%{_libdir}/%{name} \ + --includedir=%{_includedir}/%{name} --prefix=%{_prefix} \ + --program-prefix=moz +make %{?_smp_mflags} + + +%install +rm -rf %{buildroot} +%make_install docdir=%{_pkgdocdir} exampledir=%{_pkgdocdir} +find %{buildroot} -name '*.la' -exec rm -f {} ';' +# the magic: +mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/ld.so.conf.d +echo "%{_libdir}/%{name}" > %{buildroot}%{_sysconfdir}/ld.so.conf.d/%{name}-%{_arch}.conf + +# Fix perms +chmod -x README-turbo.txt + + +%check +#make test + + +%post +/sbin/ldconfig +# New install +if [ $1 -eq 1 ]; then + # print site info + cat < - 3.3.1-4 +- Drop-in library + +* Sun Mar 10 2019 Danila Vershinin - 3.3.1-1 +- Rebuild for 3.3.1 + +* Fri Oct 17 2014 Rahul Sundaram - 2.1-1 +- initial spec