added release builder

This commit is contained in:
2023-03-31 14:47:29 +02:00
parent 5ec23ce9fd
commit 80ef77457d
2 changed files with 92 additions and 1 deletions

View File

@@ -26,9 +26,13 @@ BRANCH = $(shell git branch --show-current)
COMMIT = $(shell git rev-parse --short=8 HEAD)
BUILD = $(shell date +%Y.%m.%d.%H%M%S)
VERSION := $(if $(filter $(BRANCH), development),$(version)-$(BRANCH)-$(COMMIT)-$(BUILD),$(version))
ONMAIN := $(if $(filter $(BRANCH), main),"main","")
HAVE_POD := $(shell pod2text -h 2>/dev/null)
HAVE_LINT:= $(shell golangci-lint -h 2>/dev/null)
DAEMON := ephemerupd
CLIENT := upctl
DATE = $(shell date +%Y-%m-%d)
all: cmd/formtemplate.go lint buildlocal buildlocalctl
@@ -47,8 +51,14 @@ buildimage: clean
docker-compose --verbose build
release:
./mkrel.sh $(DAEMON) $(version)
ifdef BR_MAIN
git tag -a $(version) -m "$(version) released on $(DATE)"
git push origin --tags
./mkrel.sh $(DAEMON) $(CLIENT) $(version)
gh release create $(version) --generate-notes releases/*
else
@echo "Cannot create release on branch $(BRANCH), checkout main and retry!"
endif
install: buildlocal
install -d -o $(UID) -g $(GID) $(PREFIX)/bin

81
mkrel.sh Executable file
View File

@@ -0,0 +1,81 @@
#!/bin/bash
# Copyright © 2023 Thomas von Dein
# 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 3 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.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# get list with: go tool dist list
DIST="darwin/amd64
freebsd/amd64
linux/amd64
windows/amd64"
daemon="$1"
client="$2"
version="$3"
if test -z "$version"; then
echo "Usage: $0 <daemon name> <client name> <release version>"
exit 1
fi
rm -rf releases
mkdir -p releases
for D in $DIST; do
os=${D/\/*/}
arch=${D/*\//}
binfile="releases/${daemon}-${os}-${arch}-${version}"
clientfile="releases/${client}-${os}-${arch}-${version}"
tardir="${daemon}-${os}-${arch}-${version}"
tarfile="releases/${daemon}-${os}-${arch}-${version}.tar.gz"
set -x
GOOS=${os} GOARCH=${arch} go build -o ${binfile} -ldflags "-X 'github.com/tlinden/ephemerup/cfg.VERSION=${version}'"
cd $client
GOOS=${os} GOARCH=${arch} go build -o ../${clientfile} -ldflags "-X 'github.com/tlinden/ephemerup/upctl/cfg.VERSION=${version}'"
cd -
mkdir -p ${tardir}
cp ${binfile} ${clientfile} README.md LICENSE ${tardir}/
echo 'daemon = ephemerupd
client = upctl
PREFIX = /usr/local
UID = root
GID = 0
install-client:
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
install -d -o $(UID) -g $(GID) $(PREFIX)/man/man1
install -o $(UID) -g $(GID) -m 555 $(client) $(PREFIX)/bin/
install -o $(UID) -g $(GID) -m 444 $(client).1 $(PREFIX)/man/man1/
install: install-client
install -d -o $(UID) -g $(GID) $(PREFIX)/sbin
install -o $(UID) -g $(GID) -m 555 $(daemon) $(PREFIX)/sbin/
install -o $(UID) -g $(GID) -m 444 $(daemon).1 $(PREFIX)/man/man1/' > ${tardir}/Makefile
tar cpzf ${tarfile} ${tardir}
for file in ${binfile} ${tarfile} ${clientfile}; do
sha256sum ${file} | cut -d' ' -f1 > ${file}.sha256
done
rm -rf ${tardir}
set +x
done