2020-06-16 17:27:55 -07:00
#!/bin/sh
# Human readable names of binary distributions
DISTRO = ( macOS linux)
# Operating systems for the respective distributions
OS = ( darwin linux)
# Architectures for the respective distributions
ARCH = ( amd64 amd64)
# Version
VERSION = $1
2020-08-30 12:03:28 -07:00
SHOULD_RELEASE = $2
2020-06-17 23:54:55 -07:00
if [ [ -z " ${ VERSION } " ] ] ; then
echo "Version must be specified when running build"
2020-06-22 09:53:26 -07:00
exit
2020-06-17 23:54:55 -07:00
fi
2020-06-16 17:27:55 -07:00
[ [ -z " ${ VERSION } " ] ] && VERSION = 'unknownver' || VERSION = " ${ VERSION } "
GIT_COMMIT = $( git rev-list -1 HEAD)
2020-07-28 21:30:03 -07:00
GIT_BRANCH = $( git rev-parse --abbrev-ref HEAD)
2020-06-16 17:27:55 -07:00
# Change to the root directory of the repository
cd $( git rev-parse --show-toplevel)
echo "Cleaning working directories..."
2020-06-18 17:47:44 -07:00
rm -rf ./webroot/hls/* ./hls/* ./webroot/thumbnail.jpg
2020-06-16 17:27:55 -07:00
echo " Creating version ${ VERSION } from commit ${ GIT_COMMIT } "
mkdir -p dist
build( ) {
NAME = $1
OS = $2
ARCH = $3
VERSION = $4
GIT_COMMIT = $5
2020-07-28 21:30:03 -07:00
echo " Building ${ NAME } ( ${ OS } / ${ ARCH } ) release from ${ GIT_BRANCH } ... "
2020-06-16 17:27:55 -07:00
2020-06-22 20:11:56 -05:00
mkdir -p dist/${ NAME }
2020-06-22 09:53:26 -07:00
mkdir -p dist/${ NAME } /webroot/static
2020-06-16 17:27:55 -07:00
2020-06-17 23:24:27 -07:00
# Default files
2020-06-22 20:11:56 -05:00
cp config-example.yaml dist/${ NAME } /config.yaml
2020-06-17 23:24:27 -07:00
cp webroot/static/content-example.md dist/${ NAME } /webroot/static/content.md
2020-06-16 17:27:55 -07:00
cp -R webroot/ dist/${ NAME } /webroot/
cp -R doc/ dist/${ NAME } /doc/
2020-06-25 17:44:47 -07:00
cp -R static/ dist/${ NAME } /static
2020-06-16 17:27:55 -07:00
cp README.md dist/${ NAME }
pushd dist/${ NAME } >> /dev/null
2020-07-12 17:58:34 -07:00
2020-07-28 21:30:03 -07:00
CGO_ENABLED = 1 ~/go/bin/xgo --branch ${ GIT_BRANCH } -ldflags " -s -w -X main.GitCommit= ${ GIT_COMMIT } -X main.BuildVersion= ${ VERSION } -X main.BuildType= ${ NAME } " -targets " ${ OS } / ${ ARCH } " github.com/gabek/owncast
2020-07-12 17:58:34 -07:00
mv owncast-*-${ ARCH } owncast
2020-06-16 17:27:55 -07:00
zip -r -q -8 ../owncast-$NAME -$VERSION .zip .
popd >> /dev/null
rm -rf dist/${ NAME } /
}
2020-07-20 22:04:00 -07:00
for i in " ${ !DISTRO[@] } " ; do
build ${ DISTRO [ $i ] } ${ OS [ $i ] } ${ ARCH [ $i ] } $VERSION $GIT_COMMIT
done
2020-06-16 17:27:55 -07:00
2020-08-30 12:03:28 -07:00
# Use the second argument "release" to create an actual release.
if [ " $SHOULD_RELEASE " != "release" ] ; then
echo "Not creating a release."
exit
fi
2020-06-16 17:27:55 -07:00
# Create the tag
2020-08-30 12:03:28 -07:00
git tag -a " v ${ VERSION } " -m " Release build v ${ VERSION } "
2020-06-16 17:27:55 -07:00
2020-08-30 12:03:28 -07:00
# On macOS open the Github page for new releases so they can be uploaded
if test -f "/usr/bin/open" ; then
open "https://github.com/gabek/owncast/releases/new"
open dist
fi
2020-07-07 00:23:21 -07:00
# Docker build
# Must authenticate first: https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages#authenticating-to-github-packages
2020-08-30 12:03:28 -07:00
DOCKER_IMAGE = " owncast- ${ VERSION } "
echo " Building Docker image ${ DOCKER_IMAGE } ... "
# Change to the root directory of the repository
cd $( git rev-parse --show-toplevel)
2020-07-20 18:39:39 -07:00
# Github Packages
2020-08-30 12:03:28 -07:00
docker build --build-arg NAME = docker --build-arg VERSION = ${ VERSION } --build-arg GIT_COMMIT = $GIT_COMMIT -t owncast . -f scripts/Dockerfile-build
docker tag $DOCKER_IMAGE docker.pkg.github.com/gabek/owncast/$DOCKER_IMAGE :$VERSION
docker push docker.pkg.github.com/gabek/owncast/$DOCKER_IMAGE :$VERSION
2020-07-20 18:39:39 -07:00
#
# Dockerhub
# You must be authenticated via `docker login` with your Dockerhub credentials first.
2020-08-30 12:03:28 -07:00
docker tag owncast gabekangas/owncast:$VERSION
docker push gabekangas/owncast