mirror of
https://github.com/walles/moar.git
synced 2024-09-11 12:15:43 +03:00
Write version number into executable
This commit is contained in:
parent
84ae2cb21c
commit
0fbb2ce8d3
10
build.sh
Executable file
10
build.sh
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
VERSION="$(git describe --tags --dirty)"
|
||||||
|
|
||||||
|
# Linker flags trick below from here:
|
||||||
|
# https://www.reddit.com/r/golang/comments/4cpi2y/question_where_to_keep_the_version_number_of_a_go/d1kbap7?utm_source=share&utm_medium=web2x
|
||||||
|
|
||||||
|
# This line must be last in the script so that its return code
|
||||||
|
# propagates properly to its caller
|
||||||
|
go build -ldflags="-X main.versionString=$VERSION"
|
8
moar.go
8
moar.go
@ -14,18 +14,20 @@ import (
|
|||||||
"golang.org/x/crypto/ssh/terminal"
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var versionString = "Should be set when building, please use build.sh to build"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// FIXME: On any panic or warnings, also print system info and how to report bugs
|
// FIXME: On any panic or warnings, also print system info and how to report bugs
|
||||||
|
|
||||||
version := flag.Bool("version", false, "Prints the moar version number")
|
printVersion := flag.Bool("version", false, "Prints the moar version number")
|
||||||
|
|
||||||
// FIXME: Support --help
|
// FIXME: Support --help
|
||||||
|
|
||||||
// FIXME: Support --no-highlight
|
// FIXME: Support --no-highlight
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *version {
|
if *printVersion {
|
||||||
fmt.Println("FIXME: Imagine a version string here")
|
fmt.Println(versionString)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
moar.sh
2
moar.sh
@ -7,6 +7,6 @@ set -e -o pipefail
|
|||||||
|
|
||||||
rm -f moar
|
rm -f moar
|
||||||
|
|
||||||
go build 1>&2
|
./build.sh 1>&2
|
||||||
|
|
||||||
./moar "$@"
|
./moar "$@"
|
||||||
|
13
test.sh
13
test.sh
@ -5,9 +5,14 @@ set -e -o pipefail
|
|||||||
# Unit tests first
|
# Unit tests first
|
||||||
go test github.com/walles/moar/m
|
go test github.com/walles/moar/m
|
||||||
|
|
||||||
# Verify sending the output to a file
|
# Ensure we can cross compile
|
||||||
go build
|
GOOS=linux GOARCH=386 ./build.sh
|
||||||
|
GOOS=darwin GOARCH=amd64 ./build.sh
|
||||||
|
|
||||||
|
# Make sure we have a runnable binary for the current platform when done
|
||||||
|
./build.sh
|
||||||
|
|
||||||
|
# Verify sending the output to a file
|
||||||
RESULT="$(mktemp)"
|
RESULT="$(mktemp)"
|
||||||
function cleanup {
|
function cleanup {
|
||||||
rm -rf "$RESULT"
|
rm -rf "$RESULT"
|
||||||
@ -34,9 +39,5 @@ echo Test --version...
|
|||||||
./moar --version > /dev/null # Should exit with code 0
|
./moar --version > /dev/null # Should exit with code 0
|
||||||
diff -u <(./moar --version) <(git describe --tags --dirty)
|
diff -u <(./moar --version) <(git describe --tags --dirty)
|
||||||
|
|
||||||
# Ensure we can cross compile
|
|
||||||
GOOS=linux GOARCH=386 go build
|
|
||||||
GOOS=darwin GOARCH=amd64 go build
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "All tests passed!"
|
echo "All tests passed!"
|
||||||
|
Loading…
Reference in New Issue
Block a user