Browse Source

Add release script

tags/fbb2381b
William Petit 4 months ago
parent
commit
fbb2381b14
3 changed files with 105 additions and 2 deletions
  1. 2
    1
      .gitignore
  2. 4
    1
      Makefile
  3. 99
    0
      script/release

+ 2
- 1
.gitignore View File

@@ -1,4 +1,5 @@
1 1
 /coverage
2 2
 /vendor
3 3
 /bin
4
-/testdata
4
+/testdata
5
+/release

+ 4
- 1
Makefile View File

@@ -5,6 +5,9 @@ test:
5 5
 watch:
6 6
 	modd	
7 7
 
8
+release:
9
+	script/release
10
+
8 11
 deps:
9 12
 	GO111MODULE=off go get -u golang.org/x/tools/cmd/godoc
10 13
 	GO111MODULE=off go get -u github.com/cortesi/modd/cmd/modd
@@ -29,4 +32,4 @@ doc:
29 32
 bin/keygen:
30 33
 	go build -o bin/keygen ./cmd/keygen
31 34
 
32
-.PHONY: test lint doc sequence-diagram bin/keygen
35
+.PHONY: test lint doc sequence-diagram bin/keygen release

+ 99
- 0
script/release View File

@@ -0,0 +1,99 @@
1
+#!/bin/bash
2
+
3
+set -eo pipefail
4
+
5
+OS_TARGETS=(linux)
6
+ARCH_TARGETS=${ARCH_TARGETS:-amd64}
7
+
8
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
9
+
10
+function build {
11
+
12
+  local name=$1
13
+  local srcdir=$2
14
+  local os=$3
15
+  local arch=$4
16
+
17
+  local dirname="$name-$os-$arch"
18
+  local destdir="$DIR/../release/$dirname"
19
+
20
+  rm -rf "$destdir"
21
+  mkdir -p "$destdir"
22
+
23
+  echo "building $dirname..."
24
+
25
+  CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \
26
+    -ldflags="-s -w" \
27
+    -gcflags=-trimpath="${PWD}" \
28
+    -asmflags=-trimpath="${PWD}" \
29
+    -o "$destdir/$name" \
30
+    "$srcdir"
31
+
32
+  if [ ! -z "$(which upx)" ]; then
33
+    upx --best "$destdir/$name"
34
+  fi
35
+
36
+}
37
+
38
+function copy {
39
+
40
+  local name=$1
41
+  local os=$2
42
+  local arch=$3
43
+  local src=$4
44
+  local dest=$5
45
+
46
+  local dirname="$name-$os-$arch"
47
+  local destdir="$DIR/../release/$dirname"
48
+
49
+  echo "copying '$src' to '$destdir/$dest'..."
50
+
51
+  mkdir -p "$(dirname $destdir/$dest)"
52
+
53
+  cp -rfL $src "$destdir/$dest"
54
+
55
+}
56
+
57
+function dump_default_conf {
58
+  # Generate and copy configuration file
59
+  local command=$1
60
+  local os=$2
61
+  local arch=$3
62
+  local tmp_conf=$(mktemp)
63
+
64
+  go run "$DIR/../cmd/$command" -dump-config > "$tmp_conf"
65
+  copy "$command" $os $arch "$tmp_conf" "$command.conf"
66
+  rm -f "$tmp_conf"
67
+}
68
+
69
+function compress {
70
+
71
+  local name=$1
72
+  local os=$2
73
+  local arch=$3
74
+
75
+  local dirname="$name-$os-$arch"
76
+  local destdir="$DIR/../release/$dirname"
77
+
78
+  echo "compressing $dirname..."
79
+  tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname"
80
+}
81
+
82
+function release_keygen {
83
+  local os=$1
84
+  local arch=$2
85
+  build 'keygen' "$DIR/../cmd/keygen" $os $arch
86
+  copy 'keygen' $os $arch "$DIR/../README.md" "README.md"
87
+  compress 'keygen' $os $arch
88
+}
89
+
90
+
91
+function main {
92
+  for os in ${OS_TARGETS[@]}; do
93
+    for arch in ${ARCH_TARGETS[@]}; do
94
+      release_keygen $os $arch
95
+    done
96
+  done
97
+}
98
+
99
+main

Loading…
Cancel
Save