The main build script for this project is `script/build.go` which
implements Makefile-like building of the `gh` binary and associated man
pages. Our Makefile defers to the Go script.
However, when setting GOOS, GOARCH, and other environment variables to
modify the target for the resulting binary, these environment variables
would affect the execution of `build.go` as well, which was unintended.
This tweaks our Makefile to reset variables like GOOS and GOARCH when
building the `build.go` script itself, ensuring that the built script
runs on the same platform, and adds the ability to pass environment
variables as arguments to `go run script/build.go`. This allows the
following usage on platforms without `make`:
go run script/build.go GOOS=linux
With this style of invocation, the GOOS setting does not actually affect
`go run` itself; just the `go build` that is executed in a child process.
The implementation imitates the behavior of build-systems generated by
GNU Automake.
Implemented targets:
- install
- install-strip
- uninstall
Implemented variables:
- DESTDIR
- prefix
- bindir
- INSTALL_STRIP_FLAG
Internal implementation details:
- install-bins variable collects user binaries to be installed
- install-dirs variable collects directories to be created
- deb and rpm packages are now built for prereleases
- consolidate setup for deb & rpm
- man pages are generated for prereleases
- the `cli.github.com` site is only pushed to on full releases
Bonus:
- only publish the GitHub release after the Windows MSI is uploaded
- hub does not need downloading
Do not pass LDFLAGS as arguments to -ldflags, since these are passed to
'go tool link' and C compiler ldflags need to be passed as
-ldflags "-extldflags \"$LDFLAGS\"" with unreliable handling. Instead
copy over (unmodified) the standard environment variable to the special
golang-specific variable which the go compiler chooses to respect.
While we are at it, handle CPPFLAGS and CFLAGS too.
It's bad form to embed timestamps in binaries as it prevents
reproducible builds of the resulting binary.
The Reproducible Builds project defines SOURCE_DATE_EPOCH to help
reproduce binaries by allowing the date format to be overridden. This
patch adds support for this for GNU and BSD date.
Go 1.13 introduces `-trimpath` which strips build paths from all
compiled binaries. This enables people to reproduce the distributed cli
binary without having to recreate the build path.
https://reproducible-builds.org/specs/source-date-epoch/https://reproducible-builds.org/docs/build-path/
Signed-off-by: Morten Linderud <morten@linderud.pw>
`make site-docs`:
1. checks out the `gh-pages` branch into the `site/` directory;
2. regenerates `.md` help pages using Cobra;
3. commits and publishes updates.
This was a typo. Note that Makefile is only used for building a
development version after cloning from git; the tagged release process
uses `.goreleaser.yml` and skips the Makefile.