Skip to content

Commit

Permalink
wrote posix compliant build script, and modified makefile relevantly
Browse files Browse the repository at this point in the history
  • Loading branch information
dakyskye committed Jun 26, 2020
1 parent c5b5f90 commit 7a91e26
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 12 deletions.
112 changes: 112 additions & 0 deletions do.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/sh

# this script is part of dxhd project, used for building and releasing dxhd

set -e

BINARY_NAME=dxhd

GIT_VERSION="$(git rev-parse --short HEAD)"
DIRTY_VERSION="$(git describe --tags --dirty --always)"
RELEASE_VERSION="$(date '+%d.%m.%Y_%H.%M')"

RELEASE_DIR="$(readlink -f "$(dirname "$0")")/releases"

GOOS=linux

build() {
case "$1" in
fast)
go build -ldflags "-s -w -X main.version=$GIT_VERSION" -o "$BINARY_NAME" .
echo "built fast build of dxhd"
;;
dev)
go build -ldflags "-s -w -X main.version=$DIRTY_VERSION" -o "$BINARY_NAME" .
echo "built dirty, developer build of dxhd"
;;
*)
return 1
;;
esac
}

release_preconfig() {
mkdir -p "$RELEASE_DIR/386"
mkdir -p "$RELEASE_DIR/amd64"
mkdir -p "$RELEASE_DIR/arm"
mkdir -p "$RELEASE_DIR/arm64"
return 0
}

release_build() {
CGO_ENABLED=0

echo "building for 386"
GOARCH=386 go build -a -ldflags "-s -w -X main.version=$RELEASE_VERSION" -o "$RELEASE_DIR/386/$BINARY_NAME"_386 .

echo "building for amd64"
GOARCH=amd64 go build -a -ldflags "-s -w -X main.version=$RELEASE_VERSION" -o "$RELEASE_DIR/amd64/$BINARY_NAME"_amd64 .

echo "building for arm"
GOARCH=arm go build -a -ldflags "-s -w -X main.version=$RELEASE_VERSION" -o "$RELEASE_DIR/arm/$BINARY_NAME"_arm .

echo "building for arm64"
GOARCH=arm64 go build -a -ldflags "-s -w -X main.version=$RELEASE_VERSION" -o "$RELEASE_DIR/arm64/$BINARY_NAME"_arm64 .

echo

return 0
}

release_push() {
[ ! "$(git cherry)" = "" ] && echo "you have commits that are yet not pushed"
git status | grep -qi '^untracked files:' && echo "you have untracked files"
git status | grep -qi '^changes to be committed:' && echo "you have changes to be commited"

echo 'are you sure you want to git tag and push? type "yes I want" in screaming snake case :)'
read -r ANS
echo

case "$ANS" in
YES_I_WANT)
;;
*)
return 1
;;
esac

LAST_TAG="$(git describe --tags --abbrev=0)"

git tag -a "$RELEASE_VERSION" -m "$RELEASE_VERSION release"
git push -u origin "$RELEASE_VERSION"

return 0
}

release_commits() {
COMMITS="$(git log --oneline "$LAST_TAG"..HEAD)"
echo "commits since last tag ($LAST_TAG) for release page"
echo ""
echo "$COMMITS"
echo ""
echo "$COMMITS" > "$RELEASE_DIR/release_info"
}

if [ -z "$1" ]; then
build dev
else
case "$1" in
fast)
build fast
;;
dev)
build dev
;;
release)
release_preconfig
release_build
release_push
release_commits
;;
esac
fi
15 changes: 3 additions & 12 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
MASTERVERSION := $(shell git rev-parse --short HEAD)
VERSION := $(shell git describe --tags --dirty --always)
DATE := $(shell date "+%d.%m.%Y_%H.%M")

.POSIX:
fast:
go build -ldflags "-s -w -X main.version=$(MASTERVERSION)" -o dxhd .

./do.sh fast
dev:
go build -ldflags "-X main.version=$(VERSION)" -o dxhd .

release:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "-s -w -X main.version=$(DATE)" -o dxhd .
git tag -a $(DATE) -m "release $(DATE)"
git push origin $(DATE)
./do.sh dev

0 comments on commit 7a91e26

Please sign in to comment.