Archived
Add simple one-arg stamped build script
This commit is contained in:
@@ -70,10 +70,20 @@ The provider embeds build metadata (`version`, `commit`, `date`) in the binary.
|
||||
- `./terraform-provider-dynu --version`
|
||||
- `./terraform-provider-dynu version`
|
||||
|
||||
Build a stamped binary with standard Go `-ldflags`:
|
||||
Primary build method (recommended):
|
||||
|
||||
```bash
|
||||
VERSION=${VERSION:-v0.2.0}
|
||||
./build.sh v0.2.0
|
||||
```
|
||||
|
||||
`build.sh` takes exactly one argument (the version string), then derives commit and date automatically:
|
||||
- `COMMIT=$(git rev-parse --short HEAD)`
|
||||
- `DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)`
|
||||
|
||||
Manual equivalent (same stamped build command used by `build.sh`):
|
||||
|
||||
```bash
|
||||
VERSION=v0.2.0
|
||||
COMMIT=$(git rev-parse --short HEAD)
|
||||
DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
echo "Usage: ./build.sh <version>"
|
||||
}
|
||||
|
||||
if [[ $# -ne 1 ]]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "README.md" || ! -f "go.mod" || ! -f "main.go" ]]; then
|
||||
echo "Error: run this script from the repository root (terraform-dynu-provider)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "Error: git is required but was not found in PATH."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v go >/dev/null 2>&1; then
|
||||
echo "Error: go is required but was not found in PATH."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION="$1"
|
||||
COMMIT="$(git rev-parse --short HEAD)"
|
||||
DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
OUTPUT="terraform-provider-dynu"
|
||||
|
||||
echo "Building terraform-provider-dynu with metadata:"
|
||||
echo " version: ${VERSION}"
|
||||
echo " commit: ${COMMIT}"
|
||||
echo " date: ${DATE}"
|
||||
echo " output: ${OUTPUT}"
|
||||
|
||||
go build -o "${OUTPUT}" \
|
||||
-ldflags="-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}"
|
||||
|
||||
echo "Build complete: ${OUTPUT}"
|
||||
Reference in New Issue
Block a user