This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-release.go
94 lines (77 loc) · 1.84 KB
/
make-release.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2018 The solid-mon-rpi Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main() {
log.SetPrefix("release: ")
log.SetFlags(0)
flag.Parse()
tag := version()
if flag.NArg() > 0 {
tag = flag.Arg(0)
}
os.Setenv("GO111MODULE", "on")
run("go", "generate")
run("go", "get", "-v", "./...")
oname := filepath.Join(".", "releases", tag, "solid-mon-rpi-linux-arm.exe")
err := os.MkdirAll(filepath.Dir(oname), 0755)
if err != nil {
log.Fatal(err)
}
log.Printf("create an ARM-based executable for RPi3... version=%q", tag)
cmd := exec.Command("go",
"build", "-v",
"-ldflags", fmt.Sprintf("-X main.Version=%q", tag),
"-o", oname,
)
cmd.Env = append([]string{
"GOARCH=arm",
"GOARM=7",
"GO111MODULE=on",
}, os.Environ()...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
err = os.Chmod(oname, 0755)
if err != nil {
log.Fatal(err)
}
log.Printf("create an ARM-based executable for RPi3... [done]")
dir := filepath.Dir(oname)
log.Printf("xfer %q to CERN...", dir)
run("scp", "-r", dir, "lxplus.cern.ch:www/solid-mon-rpi/.")
}
func run(cmd string, args ...string) {
c := exec.Command(cmd, args...)
c.Stdin = os.Stdin
c.Stdout = os.Stdout
c.Stderr = os.Stderr
err := c.Run()
if err != nil {
log.Fatal(err)
}
}
func version() string {
tag, err := exec.Command("git", "describe", "--contains", "HEAD").Output()
if err == nil {
return strings.Trim(string(tag), "\n")
}
rev, err := exec.Command("git", "rev-parse", "--short", "HEAD").Output()
if err != nil {
log.Fatalf("could not retrieve current git revision: %v", err)
}
return strings.Trim(string(rev), "\n")
}