Browse Source

Add release target to generate compiled version archive

develop
William Petit 4 months ago
parent
commit
c7d4215be8
8 changed files with 130 additions and 8 deletions
  1. 2
    1
      .gitignore
  2. 5
    2
      Makefile
  3. 2
    2
      cmd/configurator/README.md
  4. 0
    0
      cmd/configurator/main.go
  5. 1
    1
      cmd/discovery/main.go
  6. 2
    2
      cmd/updater/README.md
  7. 0
    0
      cmd/updater/main.go
  8. 118
    0
      scripts/release

+ 2
- 1
.gitignore View File

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

+ 5
- 2
Makefile View File

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

example/reachview/README.md → cmd/configurator/README.md View File

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

example/reachview/main.go → cmd/configurator/main.go View File


example/discovery/main.go → cmd/discovery/main.go View File

@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 var (
13
-	timeout = 5 * time.Second
13
+	timeout = 10 * time.Second
14 14
 )
15 15
 
16 16
 func init() {

example/updater/README.md → cmd/updater/README.md View File

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

example/updater/main.go → cmd/updater/main.go View File


+ 118
- 0
scripts/release View File

@@ -0,0 +1,118 @@
1
+#!/bin/bash
2
+
3
+set -eo pipefail
4
+
5
+export GO111MODULE=on
6
+
7
+OS_TARGETS=(windows linux)
8
+ARCH_TARGETS=(amd64)
9
+
10
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
11
+
12
+function build {
13
+
14
+  local name=$1
15
+  local srcdir=$2
16
+  local os=$3
17
+  local arch=$4
18
+
19
+  local dirname="$name-$os-$arch"
20
+  local destdir="$DIR/../release/$dirname"
21
+
22
+  local ext=
23
+  [ "$os" == "windows" ] && ext=.exe
24
+
25
+  rm -rf "$destdir"
26
+  mkdir -p "$destdir"
27
+
28
+  echo "building $dirname..."
29
+
30
+  CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \
31
+    -v \
32
+    -mod=vendor \
33
+    -ldflags="-s -w" \
34
+    -gcflags=-trimpath="${PWD}" \
35
+    -asmflags=-trimpath="${PWD}" \
36
+    -o "$destdir/$name$ext" \
37
+    "$srcdir"
38
+
39
+  if [ ! -z "$(which upx)" ]; then
40
+    upx --best "$destdir/$name$ext"
41
+  fi
42
+
43
+}
44
+
45
+function copy {
46
+
47
+  local name=$1
48
+  local os=$2
49
+  local arch=$3
50
+  local src=$4
51
+  local dest=$5
52
+
53
+  local dirname="$name-$os-$arch"
54
+  local destdir="$DIR/../release/$dirname"
55
+
56
+  echo "copying '$src' to '$destdir/$dest'..."
57
+
58
+  mkdir -p "$(dirname $destdir/$dest)"
59
+
60
+  cp -rfL $src "$destdir/$dest"
61
+
62
+}
63
+
64
+function compress {
65
+
66
+  local name=$1
67
+  local os=$2
68
+  local arch=$3
69
+
70
+  local dirname="$name-$os-$arch"
71
+  local destdir="$DIR/../release/$dirname"
72
+
73
+  echo "compressing $dirname..."
74
+  tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname"
75
+}
76
+
77
+function release_updater {
78
+
79
+  local os=$1
80
+  local arch=$2
81
+  
82
+  build 'updater' "$DIR/../cmd/updater" $os $arch
83
+  compress 'updater' $os $arch
84
+
85
+}
86
+
87
+function release_discovery {
88
+
89
+  local os=$1
90
+  local arch=$2
91
+
92
+  build 'discovery' "$DIR/../cmd/discovery" $os $arch
93
+  compress 'discovery' $os $arch
94
+
95
+}
96
+
97
+function release_configurator {
98
+
99
+  local os=$1
100
+  local arch=$2
101
+
102
+  build 'configurator' "$DIR/../cmd/configurator" $os $arch
103
+  compress 'configurator' $os $arch
104
+
105
+}
106
+
107
+
108
+function main {
109
+  for os in ${OS_TARGETS[@]}; do
110
+    for arch in ${ARCH_TARGETS[@]}; do
111
+      release_configurator $os $arch
112
+      release_updater $os $arch
113
+      release_discovery $os $arch
114
+    done
115
+  done
116
+}
117
+
118
+main

Loading…
Cancel
Save