This is a project which is intended to demonstrate how to use Makefiles to build go projects. Build version tag will be detected automatically and updated in the compilation time.
sudo apt install make
yum install make
- Import Makefile into your project root
- Update main function as follows.
package main
import (
buildMeta "github.com/srimaln91/go-make"
)
func main() {
// Print binary details and terminate the program when --version flag provided.
buildMeta.CheckVersion()
// Optionally we can pass a printer that we can use to control the output
// It acceptes any type which implements the `Printer` interface
buildMeta.CheckVersion(buildMeta.PRINTER_SINGLE_LINE)
// Starting the bootstrpping process
// bootstrap.Start()
}
This project contains a sample Makefile with some build tasks.
# List configured make tasks
make help
# Run unit tests
make test
# Build project
make build
# Run project
make run
# Clean build directory
make clean
# Can check binary version by passing --version flag
./build/vx.x.x/go-build-linux-amd64 --version
# Output
+----------------+------------+------------------------------------------+-------------+-------------------------+
| BINARY VERSION | GO VERSION | GIT COMMIT | OS/ARCH | BUILT |
+----------------+------------+------------------------------------------+-------------+-------------------------+
| v0.6.0 | go1.12.9 | c8bf7b40e9d842769b580b704931904197e0b713 | linux/amd64 | 2019-10-05-14:01:35-UTC |
+----------------+------------+------------------------------------------+-------------+-------------------------+
- If the source code is exactly on a build tag, the binary will be created with a clean tag. Like
vx.x.x
- If the source code is modified and have uncommited changes, the build tag would be
vx.x.x-dirty
(latest build tag - dirty) - If the source code has any untagged changes and the working directory is clean, the build tag will be
vx.x.x-34fdr54
(latest build tag - latest commit SHA)