Skip to content

Commit

Permalink
Re-organizing the build script
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyr committed Jan 25, 2018
1 parent 612aa0b commit 78a8894
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions dist/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

# Import GPG key
gpg --import "$TRAVIS_BUILD_DIR/dist/gpg_key.priv"
echo -e '%_gpg_name Jiri Tyr (PKG) <[email protected]>\n%dist .el7' > ~/.rpmmacros

# Create RPM infrastructure
mkdir -p ~/rpmbuild/SOURCES
echo -e '#!/usr/bin/expect -f\nspawn rpmsign --key-id CA67951CD2BBE8AAE4210B72FB90C91F64BED28C --addsign {*}$argv\nexpect -exact "Enter pass phrase: "\nsend -- "\\r"\nexpect eof' > ~/rpm-sign.exp
chmod +x ~/rpm-sign.exp

# Archs to build for
declare -a PLATFORMS=(
'darwin/amd64'
'linux/amd64'
Expand All @@ -11,11 +21,10 @@ declare -a PLATFORMS=(
NAME='gbt'
VER="${TRAVIS_TAG:1}"
TMP="/tmp/$NAME"
rm -fr "$TMP"

gpg --import "$TRAVIS_BUILD_DIR/dist/gpg_key.priv"
echo -e '%_gpg_name Jiri Tyr (PKG) <[email protected]>\n%dist .el7' > ~/.rpmmacros
rm -fr "$TMP"

# Process build for each arch
for P in "${PLATFORMS[@]}"; do
echo "### Building $P"

Expand All @@ -27,6 +36,7 @@ for P in "${PLATFORMS[@]}"; do

mkdir -p "$PTMP"

# Compile GBT
if [ "$ARCH" == "$ARM" ]; then
GOOS="$OS" GOARCH="$ARCH" CGO_ENABLED=0 go build -ldflags='-s -w' -o "$PTMP/$NAME" github.com/jtyr/gbt/cmd/gbt
else
Expand All @@ -36,12 +46,14 @@ for P in "${PLATFORMS[@]}"; do
GOOS="$OS" GOARCH="$ARCH" GOARM="$ARM" CGO_ENABLED=0 go build -ldflags='-s -w' -o "$PTMP/$NAME" github.com/jtyr/gbt/cmd/gbt
fi

# Create .tar.gz package
(
cp -r "$TRAVIS_BUILD_DIR"/{README.md,LICENSE,themes,sources} "$PTMP"
tar -C "$PTMP/.." -czf "$TMP/$PKG" ./
cd "$TMP"
)

# Create Linux distro packages
if [ "$OS" = 'linux' ]; then
# DEB
(
Expand All @@ -54,7 +66,8 @@ for P in "${PLATFORMS[@]}"; do
fi

cd "$TRAVIS_BUILD_DIR/contrib"
ln -sf "$PTMP" "$TRAVIS_BUILD_DIR/contrib/$NAME"
rm -f "$TRAVIS_BUILD_DIR/contrib/$NAME"
ln -s "$PTMP" "$TRAVIS_BUILD_DIR/contrib/$NAME"
m4 -DVER="$VER" -DDATE="$(date '+%a, %d %b %Y %H:%M:%S %z')" debian/changelog.m4 > debian/changelog
dpkg-buildpackage -a$DEBARCH -tc -b -kCA67951CD2BBE8AAE4210B72FB90C91F64BED28C
)
Expand All @@ -63,20 +76,18 @@ for P in "${PLATFORMS[@]}"; do

# RPM
if [ "$ARCH" = 'amd64' ]; then
mkdir -p ~/rpmbuild/SOURCES
ln -sf "$TMP/$PKG" ~/rpmbuild/SOURCES/
(
cd "$TRAVIS_BUILD_DIR/contrib/redhat"
m4 -DVER="$VER" -DDATE="$(date '+%a %b %d %Y')" gbt.spec.m4 > gbt.spec
rpmbuild -bb gbt.spec
)
echo -e '#!/usr/bin/expect -f\nspawn rpmsign --key-id CA67951CD2BBE8AAE4210B72FB90C91F64BED28C --addsign {*}$argv\nexpect -exact "Enter pass phrase: "\nsend -- "\\r"\nexpect eof' > ~/rpm-sign.exp
chmod +x ~/rpm-sign.exp
~/rpm-sign.exp ~/rpmbuild/RPMS/x86_64/*.rpm
mv ~/rpmbuild/RPMS/x86_64/*.rpm "$TMP"
fi
fi
done

# Create checksums
cd "$TMP"
sha256sum *.tar.gz *.deb *.rpm | sort -k2 > "$NAME-$VER-checksums-sha256.txt"

0 comments on commit 78a8894

Please sign in to comment.