Makefile: Making it easier to create releases

Related: rhbz#2071074
This commit is contained in:
Brian C. Lane 2022-04-05 10:07:56 -07:00
parent 1f69df73fa
commit 63d7f7ca04
4 changed files with 161 additions and 76 deletions

62
.gitignore vendored
View File

@ -1,61 +1,3 @@
/lorax-templates-rhel-8.0-0.tar.gz clog-spec
/lorax-templates-rhel-8.0-3.tar.gz clog
/lorax-templates-rhel-8.0-4.tar.gz
/lorax-templates-rhel-8.0-5.tar.gz
/lorax-templates-rhel-8.0-6.tar.gz
/lorax-templates-rhel-8.0-7.tar.gz
/lorax-templates-rhel-8.0-8.tar.gz
/lorax-templates-rhel-8.0-9.tar.gz
/lorax-templates-rhel-8.0-10.tar.gz
/lorax-templates-rhel-8.0-11.tar.gz
/lorax-templates-rhel-8.0-12.tar.gz
/lorax-templates-rhel-8.0-13.tar.gz
/lorax-templates-rhel-8.0-14.tar.gz
/lorax-templates-rhel-8.0-15.tar.gz
/lorax-templates-rhel-8.0-16.tar.gz
/lorax-templates-rhel-8.0-17.tar.gz
/lorax-templates-rhel-8.0-18.tar.gz
/lorax-templates-rhel-8.0-19.tar.gz
/lorax-templates-rhel-8.1-1.tar.gz
/lorax-templates-rhel-8.1-2.tar.gz
/lorax-templates-rhel-8.1-3.tar.gz
/lorax-templates-rhel-8.2-1.tar.gz
/lorax-templates-rhel-8.2-2.tar.gz
/lorax-templates-rhel-8.2-3.tar.gz
/lorax-templates-rhel-8.2-4.tar.gz
/lorax-templates-rhel-8.2-5.tar.gz
/lorax-templates-rhel-8.2-6.tar.gz
/lorax-templates-rhel-8.3-1.tar.gz
/lorax-templates-rhel-8.3-2.tar.gz
/lorax-templates-rhel-8.3-3.tar.gz
/lorax-templates-rhel-8.3-4.tar.gz
/lorax-templates-rhel-9.0-1.tar.gz
/lorax-templates-rhel-9.0-4.tar.gz
/lorax-templates-rhel-9.0-5.tar.gz
/lorax-templates-rhel-9.0-6.tar.gz
/lorax-templates-rhel-9.0-7.tar.gz
/lorax-templates-rhel-9.0-8.tar.gz
/lorax-templates-rhel-9.0-9.tar.gz
/lorax-templates-rhel-9.0-10.tar.gz
/lorax-templates-rhel-9.0-11.tar.gz
/lorax-templates-rhel-9.0-12.tar.gz
/lorax-templates-rhel-9.0-14.tar.gz
/lorax-templates-rhel-9.0-15.tar.gz
/lorax-templates-rhel-9.0-16.tar.gz
/lorax-templates-rhel-9.0-17.tar.gz
/lorax-templates-rhel-9.0-18.tar.gz
/lorax-templates-rhel-9.0-19.tar.gz
/lorax-templates-rhel-9.0-20.tar.gz
/lorax-templates-rhel-9.0-21.tar.gz
/lorax-templates-rhel-9.0-22.tar.gz
/lorax-templates-rhel-9.0-24.tar.gz
/lorax-templates-rhel-9.0-25.tar.gz
/lorax-templates-rhel-9.0-26.tar.gz
/lorax-templates-rhel-9.0-27.tar.gz
/lorax-templates-rhel-9.0-28.tar.gz
/lorax-templates-rhel-9.0-29.tar.gz
/lorax-templates-rhel-9.0-30.tar.gz
/lorax-templates-rhel-9.0-31.tar.gz
/lorax-templates-rhel-9.0-32.tar.gz
/lorax-templates-rhel-9.0-33.tar.gz
/lorax-templates-rhel-9.0-34.tar.gz /lorax-templates-rhel-9.0-34.tar.gz

View File

@ -1,6 +1,12 @@
NAME=lorax-templates-rhel NAME=lorax-templates-rhel
# RHEL version these templates are designed for # RHEL version these templates are designed for
RHELVER=9.0 RHELVER=9.0
RHPKG=centpkg --release=c9s
# git user.email and user.name must be setup
GITEMAIL := $(shell git config user.email)
GITNAME := $(shell git config user.name)
# Serial number for this release # Serial number for this release
SERIAL=$(shell [ -f SERIAL ] && cat SERIAL || echo 0) SERIAL=$(shell [ -f SERIAL ] && cat SERIAL || echo 0)
@ -18,13 +24,26 @@ bump-serial:
echo $$((${SERIAL}+1)) > SERIAL echo $$((${SERIAL}+1)) > SERIAL
git add SERIAL git add SERIAL
update-spec: update-spec: clog
sed -r -i \ sed -r -i \
-e 's/^(Release:\s+)[^%]+(%.*)$$/\1${SERIAL}\2/' \ -e 's/^(Release:\s+)[^%]+(%.*)$$/\1${SERIAL}\2/' \
-e 's/^(Version:\s+).*$$/\1${RHELVER}/' \ -e 's/^(Version:\s+).*$$/\1${RHELVER}/' \
-e 's/^(Source0:\s+).*$$/\1${TARBALL}/' \ -e 's/^(Source0:\s+).*$$/\1${TARBALL}/' \
-e '/%changelog/ r clog-spec' \
${SPEC} ${SPEC}
release: tar update-spec clog:
@echo "* $(shell date '+%a %b %d %Y') ${GITNAME} <${GITEMAIL}> - ${RHELVER}-${SERIAL}" > clog-spec
./tools/git-changelog -t origin/c9s > clog
cat clog >> clog-spec
.PHONY: tar ${TARBALL} bump-serial update-spec release # These need to rerun make to pick up the bumped serial number
release:
$(MAKE) bump-serial && $(MAKE) tar && $(MAKE) update-spec && $(MAKE) commit
commit:
$(RHPKG) new-sources ${TARBALL}
git add -u
git commit -F clog
.PHONY: tar ${TARBALL} bump-serial update-spec release clog commit

21
README
View File

@ -1,16 +1,11 @@
Hi there! If you're trying to fix something here, do the following: Hi there! If you're trying to fix something here, do the following:
1. Make whatever edits you need to in 80-rhel/ 1. Make whatever edits you need to in 80-rhel/
2. `git commit` the changes 2. `git commit` the changes with the relevant 'Resolves/Related' bug reference
3. `make bump` to bump SERIAL 3. `make release`
4. `make tar` to make a new tarball This will bump the release, update the spec with changes in this branch,
5. `make update-spec` to update specfile create a new tarball, upload it, and commit the changes.
6. Add changelog entry to .spec 4. Examine the changes with 'git show' and make sure they look ok.
7. `rhpkg-sha512 new-sources` the new tarball 5. Push the changes to your fork of the project with:
8. `git add lorax-templates-rhel.spec SERIAL` 'git push REMOTE BRANCHNAME' and follow the instructions to
9. `git commit` create a merge request in gitlab.
Steps 8 and 9 can be combined as:
`rhpkg-sha512 clog && rhpkg-sha512 ci -F clog`
You're now ready to do a new build. Isn't spec wonderful?

129
tools/git-changelog Executable file
View File

@ -0,0 +1,129 @@
#!/usr/bin/python3
#
# git-changelog - Output a rpm changelog
#
# Copyright (C) 2009 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author: David Cantrell <dcantrell@redhat.com>
# Author: Brian C. Lane <bcl@redhat.com>
import os
import re
import subprocess
import sys
import textwrap
from argparse import ArgumentParser
class ChangeLog:
def __init__(self, tag):
self.tag = tag
self.ignore = None
def _getCommitDetail(self, commit, field, long=False):
proc = subprocess.Popen(['git', 'log', '-1',
"--pretty=format:%s" % field, commit],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
ret = proc[0].decode("utf8").strip("\n").split('\n')
if long:
return ret
if len(ret) == 1 and ret[0].find('@') != -1:
ret = ret[0].split('@')[0]
elif len(ret) == 1:
ret = ret[0]
else:
ret = filter(lambda x: x != '', ret)
return ret
def getBugs(self, msg):
"""Get the Resolves/Related bugs from the commit.
Bug in first line is considered Resolves
"""
bugs = []
if not msg:
return []
# summary line format is ^.*#([0-9]+).*
# Make sure the bz# isn't likely to be a github issue
for line in msg:
m = re.match(r"^(Resolves|Related|Conflicts):\ +rhbz#(\d+)", line)
if m and m.group(1) and m.group(2):
bugs.append((m.group(1), m.group(2)))
else:
m = re.match(r"^.*#(\d+).*", line)
if m and m.group(1) and int(m.group(1)) > 100000:
bugs.append(("Resolves", m.group(1)))
return bugs
def getLog(self):
rev_range = "%s.." % (self.tag)
proc = subprocess.Popen(['git', 'log', '--pretty=oneline', rev_range],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
lines = filter(lambda x: x.find('l10n: ') != 41 and \
x.find('Merge commit') != 41 and \
x.find('Merge branch') != 41,
proc[0].decode("utf8").strip('\n').split('\n'))
if self.ignore and self.ignore != '':
for commit in self.ignore.split(','):
lines = filter(lambda x: not x.startswith(commit), lines)
log = []
for line in lines:
fields = line.split(' ')
commit = fields[0]
summary = self._getCommitDetail(commit, "%s")
long = self._getCommitDetail(commit, "%b", True)
author = self._getCommitDetail(commit, "%aE")
msg = ["%s (%s)" % (summary.strip(), author)]
for r, bz in self.getBugs(long):
msg.append("%s: rhbz#%s" % (r, bz))
log.append(msg)
return log
def formatLog(self):
s = ""
for msg in self.getLog():
sublines = textwrap.wrap(msg[0], 77)
s = s + "- %s\n" % sublines[0]
for line in sublines[1:] + msg[1:]:
s = s + " %s\n" % line
return s
def main():
parser = ArgumentParser(description="Generate changelog entries from git commits")
parser.add_argument("-t", "--tag", dest="tag",
help="Last tag, changelog is commits after this tag")
args = parser.parse_args()
cl = ChangeLog(args.tag)
print(cl.formatLog())
if __name__ == "__main__":
main()