Skip to content

Commit d3fab0f

Browse files
dcantrellppisar
authored andcommitted
copr: Add Copr build files
Support automatic builds on git commits. Used to generate up to date RPMs of dnf for testing and development purposes.
1 parent c1f8aee commit d3fab0f

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.copr/Makefile

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright David Cantrell <dcantrell@redhat.com>
2+
# SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
# Set the top level source directory
5+
topdir := $(shell realpath $(dir $(lastword $(MAKEFILE_LIST)))/..)
6+
7+
# Install packages before anything else
8+
_install := $(shell dnf install -y git)
9+
_safedir := $(shell git config --global --add safe.directory $(topdir))
10+
11+
# Pass BUILDTYPE=release to generate a release SRPM
12+
BUILDTYPE ?= copr
13+
14+
# Spec file and template
15+
SPEC_TEMPLATE = $(shell ls -1 $(topdir)/*.spec)
16+
SPEC = $(topdir)/$(shell basename $(SPEC_TEMPLATE))
17+
18+
# Replace placeholders in the spec file template
19+
RPMDATE = $(shell date +'%a %b %d %Y')
20+
#RPMAUTHOR = $(shell git log | grep ^Author: | head -n 1 | cut -d ' ' -f 2,3,4)
21+
RPMAUTHOR = David Cantrell <dcantrell@redhat.com>
22+
23+
# Various things we need to generate a tarball
24+
PKG = $(shell rpmspec -P "$(SPEC_TEMPLATE)" | grep ^Name: | awk '{ print $$2; }')
25+
VER = $(shell rpmspec -P "$(SPEC_TEMPLATE)" | grep ^Version: | awk '{ print $$2; }')
26+
27+
ifeq ($(BUILDTYPE),copr)
28+
GITDATE = $(shell date +'%Y%m%d%H%M')
29+
GITHASH = $(shell git rev-parse --short HEAD)
30+
TARBALL_BASENAME = $(PKG)-$(VER)-$(GITDATE)git$(GITHASH)
31+
TAG = HEAD
32+
else
33+
TAG = $(shell git describe --tags --abbrev=0)
34+
endif
35+
36+
ifeq ($(BUILDTYPE),release)
37+
TARBALL_BASENAME = $(PKG)-$(VER)
38+
endif
39+
40+
# Where to insert the changelog entry
41+
STARTING_POINT = $(shell expr $(shell grep -n ^%changelog "$(SPEC)" | cut -d ':' -f 1) + 1)
42+
43+
srpm:
44+
sed -i -e '1i %global source_date_epoch_from_changelog 0' "$(SPEC)"
45+
sed -e 's|%%VERSION%%|$(VER)|g' < "$(SPEC_TEMPLATE)" > "$(SPEC)".new
46+
mv "$(SPEC)".new "$(SPEC)"
47+
ifeq ($(BUILDTYPE),copr)
48+
sed -i -e '/^Release:/ s/1[^%]*/0.1.$(GITDATE)git$(GITHASH)/' "$(SPEC)"
49+
sed -i -e 's|^Source0:.*$$|Source0: $(TARBALL_BASENAME).tar.gz|g' "$(SPEC)"
50+
sed -i -e 's|^%autosetup.*$$|%autosetup -n $(TARBALL_BASENAME)|g' "$(SPEC)"
51+
sed -i -e '$(STARTING_POINT)a\\' "$(SPEC)"
52+
sed -i -e '$(STARTING_POINT)a - Build $(PKG)-$(VER)-$(GITDATE)git$(GITHASH) snapshot' "$(SPEC)"
53+
sed -i -e '$(STARTING_POINT)a * $(RPMDATE) $(RPMAUTHOR) - $(VER)-$(GITDATE)git$(GITHASH)' "$(SPEC)"
54+
endif
55+
git archive \
56+
--format=tar \
57+
--output='$(topdir)/$(TARBALL_BASENAME).tar' \
58+
--prefix='$(TARBALL_BASENAME)/' $(TAG) $(topdir)
59+
gzip -9f $(topdir)/$(TARBALL_BASENAME).tar
60+
rpmbuild \
61+
-bs --nodeps \
62+
--define "_sourcedir $(topdir)" \
63+
--define "_srcrpmdir $(outdir)" \
64+
--define "_rpmdir $(outdir)" "$(SPEC)"

0 commit comments

Comments
 (0)