Skip to content

Commit

Permalink
make: Release pipeline
Browse files Browse the repository at this point in the history
This commit adds new make targets for rpm, deb, and pacman packages.
It also adds a phony target that uploads tarballs of the packages,
along with their signed (and unsigned) checksums to the github release
page. Once the current commit is tagged as a release, run `make release`
to build the packages and upload them to github.
  • Loading branch information
emmmmygold committed Nov 30, 2018
1 parent cc02e96 commit 80931e1
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ mgmt.static
build/mgmt-*
mgmt.iml
rpmbuild/
*.deb
releases/
87 changes: 78 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

SHELL = /usr/bin/env bash
.PHONY: all art cleanart version program lang path deps run race bindata generate build build-debug crossbuild clean test gofmt yamlfmt format docs rpmbuild mkdirs rpm srpm spec tar upload upload-sources upload-srpms upload-rpms copr
.PHONY: all art cleanart version program lang path deps run race bindata generate build build-debug crossbuild clean test gofmt yamlfmt format docs rpmbuild mkdirs rpm srpm spec tar upload upload-sources upload-srpms upload-rpms copr release release/mkdirs
.SILENT: clean bindata

# a large amount of output from this `find`, can cause `make` to be much slower!
Expand Down Expand Up @@ -48,6 +48,10 @@ GOOSARCHES ?= linux/amd64 linux/ppc64 linux/ppc64le linux/arm64 darwin/amd64
GOHOSTOS = $(shell go env GOHOSTOS)
GOHOSTARCH = $(shell go env GOHOSTARCH)

DEB_TAR = releases/mgmt_$(VERSION)_deb_amd64.tar.gz
RPM_TAR = releases/mgmt_$(VERSION)_rpm_x86_64.tar.gz
PACMAN_TAR = releases/mgmt_$(VERSION)_pacman_x86_64.tar.gz

default: build

#
Expand Down Expand Up @@ -324,16 +328,81 @@ copr: upload-srpms ## build in copr
./misc/copr-build.py https://$(SERVER)/$(REMOTE_PATH)/SRPMS/$(SRPM_BASE)

#
# deb build
# release
#

deb: ## build debian package
./misc/gen-deb-changelog-from-git.sh
dpkg-buildpackage
# especially when building in Docker container, pull build artifact in project directory.
cp ../mgmt_*_amd64.deb ./
# cleanup
rm -rf debian/mgmt/
release: releases/mgmt-$(VERSION)-release.url

releases/mgmt-$(VERSION)-release.url: $(DEB_TAR) $(RPM_TAR) $(PACMAN_TAR)
@echo "Creating github release..."
hub release create \
-F <( echo -e "$(VERSION)\n";echo "License: GPLv3" ) \
-a $(DEB_TAR) \
-a $(RPM_TAR) \
-a $(PACMAN_TAR) \
$(VERSION) \
> releases/mgmt-$(VERSION)-release.url \
&& cat releases/mgmt-$(VERSION)-release.url \
|| rm -f releases/mgmt-$(VERSION)-release.url

release/mkdirs:
mkdir -p releases/{deb,rpm,pacman}

$(DEB_TAR): releases/deb/SHA256SUMS.asc
@echo -e "Archiving deb package..."
tar -zcf $(DEB_TAR) -C releases/deb .

releases/deb/SHA256SUMS.asc: releases/deb/SHA256SUMS
@echo "Signing sha256 sum..."
gpg2 --yes --clearsign releases/deb/SHA256SUMS

releases/deb/SHA256SUMS: releases/deb/mgmt_$(VERSION)_amd64.deb
@echo "Generating sha256 sum..."
sha256sum releases/deb/*.deb > releases/deb/SHA256SUMS

releases/deb/mgmt_$(VERSION)_amd64.deb: releases/deb/changelog
@echo "Building deb package..."
./misc/fpm-pack.sh deb libvirt-dev libaugeas-dev

releases/deb/changelog: $(PROGRAM) | release/mkdirs
@echo "Generating deb changelog..."
./misc/make-deb-changelog.sh

$(RPM_TAR): releases/rpm/SHA256SUMS.asc
@echo -e "Archiving rpm package..."
tar -zcf $(RPM_TAR) -C releases/rpm .

releases/rpm/SHA256SUMS.asc: releases/rpm/SHA256SUMS
@echo "Signing sha256 sum..."
gpg2 --yes --clearsign releases/rpm/SHA256SUMS

releases/rpm/SHA256SUMS: releases/rpm/mgmt-$(VERSION)-1.x86_64.rpm
@echo "Generating sha256 sum..."
sha256sum releases/rpm/*.rpm > releases/rpm/SHA256SUMS

releases/rpm/mgmt-$(VERSION)-1.x86_64.rpm: releases/rpm/changelog
@echo "Building rpm package..."
./misc/fpm-pack.sh rpm libvirt-devel augeas-devel

releases/rpm/changelog: $(PROGRAM) | release/mkdirs
@echo "Generating rpm changelog..."
./misc/make-rpm-changelog.sh

$(PACMAN_TAR): releases/pacman/SHA256SUMS.asc
@echo -e "Archiving pacman package..."
tar -zcf $(PACMAN_TAR) -C releases/pacman .

releases/pacman/SHA256SUMS.asc: releases/pacman/SHA256SUMS
@echo "Signing sha256 sum..."
gpg2 --yes --clearsign releases/pacman/SHA256SUMS

releases/pacman/SHA256SUMS: releases/pacman/mgmt-$(VERSION)-1-x86_64.pkg.tar.xz
@echo "Generating sha256 sum..."
sha256sum releases/pacman/*.pkg.tar.xz > releases/pacman/SHA256SUMS

releases/pacman/mgmt-$(VERSION)-1-x86_64.pkg.tar.xz: $(PROGRAM) | release/mkdirs
@echo "Building pacman package..."
./misc/fpm-pack.sh pacman libvirt augeas

build_container: ## builds the container
docker build -t purpleidea/mgmt-build -f docker/Dockerfile.build .
Expand Down
65 changes: 65 additions & 0 deletions misc/fpm-pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
# This script packages rpm, deb, and pacman packages of mgmt with fpm. The
# first argument is the package type, and all subsequent arguments are the
# dependencies. Example usage: `./fpm-pack.sh deb dependency1 dependency2`

# the binary to package
BINARY="mgmt"
# git tag pointing to the current commit
TAG=$(git tag -l --points-at HEAD)
# maintainer email
MAINTAINER="[email protected]"
# project url
URL="https://github.com/purpleidea/mgmt/"
# project description
DESCRIPTION="Next generation distributed, event-driven, parallel config management!"
# project license
LICENSE="GPLv3"
# location to install the binary
PREFIX="/usr/bin"
# release directory
DIR="releases"

# placeholder for dependencies to be read from arguments
DEPS=
# placeholder for changelog argument parsed from the package type
CHANGELOG=

# make sure we're on a tagged commit
if [ "$TAG" == "" ]; then
echo "cannot release an untagged commit"
exit 1
fi

# make sure the package type is valid
if [ "$1" != "deb" ] && [ "$1" != "rpm" ] && [ "$1" != "pacman" ]; then
echo "invalid package type"
exit 1
fi

# there are no changelogs for pacman packages
if [ "$1" != "pacman" ]; then
CHANGELOG="--${1}-changelog=${DIR}/${1}/changelog"
fi

# arguments after the first one are deps
for i in "${@:2}"; do
DEPS="$DEPS -d $i"
done

# build the package
fpm \
--log error \
--name "$BINARY" \
--version "$TAG" \
--maintainer "$MAINTAINER" \
--url "$URL" \
--description "$DESCRIPTION" \
--license "$LICENSE" \
--input-type dir \
--output-type "$1" \
--package "${DIR}/${1}/" \
${CHANGELOG} \
${DEPS} \
--prefix "$PREFIX" \
"$BINARY"
76 changes: 0 additions & 76 deletions misc/gen-deb-changelog-from-git.sh

This file was deleted.

46 changes: 46 additions & 0 deletions misc/make-deb-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# This script generates a deb changelog from the project's git history.

# path to store the changelog
CHANGELOG="releases/deb/changelog"
# input to format flag for git tag
TAG_FORMAT="-- %(creator) %(creatordate:format:%a, %d %b %Y %H:%M:%S %z) %(refname:lstrip=2)"
# a list of tags to be parsed in the loop
TAGS=$(git tag --sort=-creatordate --format="$TAG_FORMAT" | sed -r 's/[0-9]+ -[0-9]+ //')

# placeholder for the next line of the list
THIS_TAGLINE=

# parse the list
while read -r LAST_TAGLINE; do
# read ahead one tag
if [ "$THIS_TAGLINE" == "" ]; then
# store the tag for the next iteration
THIS_TAGLINE="$LAST_TAGLINE"
continue
fi

# grab the tags from the last column of the taglines
THIS_TAG=$(echo "$THIS_TAGLINE" | awk '{print $NF}')
LAST_TAG=$(echo "$LAST_TAGLINE" | awk '{print $NF}')

# print the release description
printf "mgmt (%s) unstable; priority=low\n\n" "$THIS_TAG" >> "$CHANGELOG"

# print all the commits between the tags
git shortlog -n "${LAST_TAG}...${THIS_TAG}" | sed -r '/\):/s/^/ * /' >> "$CHANGELOG"

# print the release signature
printf "%s\n\n\n" "$THIS_TAGLINE" | sed -r 's/[0-9]\.[0-9]\.[0-9]+//'>> "$CHANGELOG"

# first tag is special since there's no previous one
if [ "$LAST_TAG" == "0.0.1" ]; then
# print all the commits before the first tag
git shortlog -n "$LAST_TAG" | sed -r '/\):/s/^/ * /' >> "$CHANGELOG"
# print the release signature
printf "%s\n" "$LAST_TAGLINE" | sed -r 's/[0-9]\.[0-9]\.[0-9]+//'>> "$CHANGELOG"
fi

# store the tag for the next iteration
THIS_TAGLINE="$LAST_TAGLINE"
done <<< "$TAGS"
11 changes: 7 additions & 4 deletions misc/make-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ fi
if [ ! -z "$YUM" ]; then
$sudo_command $YUM install -y libvirt-devel
$sudo_command $YUM install -y augeas-devel
$sudo_command $YUM install -y rubygems
$sudo_command $YUM install -y ruby-devel rubygems
$sudo_command $YUM install -y time
# dependencies for building packages with fpm
$sudo_command $YUM install -y gcc make rpm-build libffi-devel bsdtar || true
fi
if [ ! -z "$APT" ]; then
$sudo_command $APT install -y libvirt-dev || true
$sudo_command $APT install -y libaugeas-dev || true
$sudo_command $APT install -y rubygems || true
$sudo_command $APT install -y ruby ruby-dev rubygems || true
$sudo_command $APT install -y libpcap0.8-dev || true
# dependencies for building debian packages with `make deb`
$sudo_command $APT install -y dpkg-dev devscripts debhelper dh-golang dh-systemd
# dependencies for building packages with fpm
$sudo_command $APT install -y build-essential rpm bsdtar || true
# `realpath` is a more universal alternative to `readlink -f` for absolute path resolution
# (-f is missing on BSD/macOS), but older Debian/Ubuntu's don't include it in coreutils yet.
# https://unix.stackexchange.com/a/136527
Expand Down Expand Up @@ -103,4 +105,5 @@ go get golang.org/x/lint/golint # for `golint`-ing
go get github.com/tmthrgd/go-bindata/go-bindata # for compiling in non golang files
go get -u gopkg.in/alecthomas/gometalinter.v1 && mv "$(dirname $(command -v gometalinter.v1))/gometalinter.v1" "$(dirname $(command -v gometalinter.v1))/gometalinter" && gometalinter --install # bonus
command -v mdl &>/dev/null || gem install mdl || true # for linting markdown files
command -v fpm &>/dev/null || gem install fpm || true # for cross distro packaging
cd "$XPWD" >/dev/null
46 changes: 46 additions & 0 deletions misc/make-rpm-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# This script generates an rpm changelog from the project's git history.

# path to store the changelog
CHANGELOG="releases/rpm/changelog"
# input to format flag for git tag
TAG_FORMAT="* %(creatordate:format:%a %b %d %Y) %(creator) %(refname:lstrip=2)"
# a list of tags to be parsed in the loop
TAGS=$(git tag --sort=-creatordate --format="$TAG_FORMAT" | sed -r 's/[0-9]+ -[0-9]+ //')

# placeholder for the next line of the list
THIS_TAGLINE=

# parse the list
while read -r LAST_TAGLINE; do
# read ahead one tag
if [ "$THIS_TAGLINE" == "" ]; then
# store the tag for the next iteration
THIS_TAGLINE="$LAST_TAGLINE"
continue
fi

# grab the tags from the last column of the taglines
THIS_TAG=$(echo "$THIS_TAGLINE" | awk '{print $NF}')
LAST_TAG=$(echo "$LAST_TAGLINE" | awk '{print $NF}')

# print the release description
printf "\n%s\n\n" "$THIS_TAGLINE" >> "$CHANGELOG"

# print all the commits between the tags
git shortlog -n ${LAST_TAG}...${THIS_TAG} | sed -r '/\):/s/^/ - /' >> "$CHANGELOG"

# first tag is special since there's no previous one
if [ "$LAST_TAG" == "0.0.1" ]; then
# print the release description
printf "\n%s\n\n" "$LAST_TAGLINE" >> "$CHANGELOG"
# print all the commits before the first tag
git shortlog -n $LAST_TAG | sed -r '/\):/s/^/ - /' >> "$CHANGELOG"
fi

# store the tag for the next iteration
THIS_TAGLINE="$LAST_TAGLINE"
done <<< "$TAGS"

# trim the first and last lines
sed -i '1d;$d' "$CHANGELOG"

0 comments on commit 80931e1

Please sign in to comment.