Add release target to generate compiled version archive

This commit is contained in:
wpetit 2019-03-27 18:50:35 +01:00
parent 8c6c0e12b2
commit c7d4215be8
8 changed files with 130 additions and 8 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/vendor /vendor
/bin /bin
/.env /.env
/release

View File

@ -29,11 +29,14 @@ install-devtools: vendor
GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
clean: clean:
rm -rf ./bin rm -rf ./bin ./release
go clean -i -x -r -modcache go clean -i -x -r -modcache
doc: doc:
@echo "Open your browser to http://localhost:6060/pkg/forge.cadoles.com/Pyxis/orion/ to see the documentation" @echo "Open your browser to http://localhost:6060/pkg/forge.cadoles.com/Pyxis/orion/ to see the documentation"
@godoc -http=:6060 @godoc -http=:6060
.PHONY: test clean generate vendor install-devtools lint watch tidy doc release:
scripts/release
.PHONY: test clean generate vendor install-devtools lint watch tidy doc release

View File

@ -1,4 +1,4 @@
# Example: ReachView # Example: Configurator
A simple example of a ReachView client that can: A simple example of a ReachView client that can:
@ -10,7 +10,7 @@ A simple example of a ReachView client that can:
2. Launch the example: 2. Launch the example:
```shell ```shell
go run example/reachview/main.go \ go run cmd/configurator/main.go \
-mode 'rover|base'\ -mode 'rover|base'\
-host '<DEVICE_IP_ADDRESS'\ -host '<DEVICE_IP_ADDRESS'\
``` ```

View File

@ -10,7 +10,7 @@ import (
) )
var ( var (
timeout = 5 * time.Second timeout = 10 * time.Second
) )
func init() { func init() {

View File

@ -11,7 +11,7 @@ A simple example of an updater client wich can:
2. Launch the example in `configure-wifi` phase and provides WiFi network informations. 2. Launch the example in `configure-wifi` phase and provides WiFi network informations.
```shell ```shell
go run example/updater/main.go \ go run cmd/updater/main.go \
-phase 'configure-wifi'\ -phase 'configure-wifi'\
-host '<DEVICE_IP_ADDRESS'\ -host '<DEVICE_IP_ADDRESS'\
-ssid '<WIFI_SSID>'\ -ssid '<WIFI_SSID>'\
@ -21,7 +21,7 @@ A simple example of an updater client wich can:
3. The device will switch to the provided WiFi network, as you should do. 3. The device will switch to the provided WiFi network, as you should do.
4. Launch the example in `update-then-reboot` phase. 4. Launch the example in `update-then-reboot` phase.
```shell ```shell
go run example/updater/main.go \ go run cmd/updater/main.go \
-phase 'update-and-reboot'\ -phase 'update-and-reboot'\
-host '<DEVICE_IP_ADDRESS' -host '<DEVICE_IP_ADDRESS'
``` ```

118
scripts/release Executable file
View File

@ -0,0 +1,118 @@
#!/bin/bash
set -eo pipefail
export GO111MODULE=on
OS_TARGETS=(windows linux)
ARCH_TARGETS=(amd64)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
function build {
local name=$1
local srcdir=$2
local os=$3
local arch=$4
local dirname="$name-$os-$arch"
local destdir="$DIR/../release/$dirname"
local ext=
[ "$os" == "windows" ] && ext=.exe
rm -rf "$destdir"
mkdir -p "$destdir"
echo "building $dirname..."
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \
-v \
-mod=vendor \
-ldflags="-s -w" \
-gcflags=-trimpath="${PWD}" \
-asmflags=-trimpath="${PWD}" \
-o "$destdir/$name$ext" \
"$srcdir"
if [ ! -z "$(which upx)" ]; then
upx --best "$destdir/$name$ext"
fi
}
function copy {
local name=$1
local os=$2
local arch=$3
local src=$4
local dest=$5
local dirname="$name-$os-$arch"
local destdir="$DIR/../release/$dirname"
echo "copying '$src' to '$destdir/$dest'..."
mkdir -p "$(dirname $destdir/$dest)"
cp -rfL $src "$destdir/$dest"
}
function compress {
local name=$1
local os=$2
local arch=$3
local dirname="$name-$os-$arch"
local destdir="$DIR/../release/$dirname"
echo "compressing $dirname..."
tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname"
}
function release_updater {
local os=$1
local arch=$2
build 'updater' "$DIR/../cmd/updater" $os $arch
compress 'updater' $os $arch
}
function release_discovery {
local os=$1
local arch=$2
build 'discovery' "$DIR/../cmd/discovery" $os $arch
compress 'discovery' $os $arch
}
function release_configurator {
local os=$1
local arch=$2
build 'configurator' "$DIR/../cmd/configurator" $os $arch
compress 'configurator' $os $arch
}
function main {
for os in ${OS_TARGETS[@]}; do
for arch in ${ARCH_TARGETS[@]}; do
release_configurator $os $arch
release_updater $os $arch
release_discovery $os $arch
done
done
}
main