Files
job-search/scripts/build.sh
T
bwilliams dcb714dc19 Some bug fixes:
- logging: LogToFile shadowed the package-level fileLogger, so
  IsFileLogger was always false and Shutdown never closed the file
- logging: replace IsJSONHandler's unsafe reflection into slog
  internals with a *slog.JSONHandler type check
- cli: fail if the log file can't be opened instead of silently
  logging to the terminal; return the log shutdown error from Finish
- build.sh: -X flags used the wrong module path, so the version, build
  time and commit were never stamped
2026-10-09 17:58:48 +01:00

63 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build script for job-search release
set -euo pipefail
BUILD_DIR="build"
RELEASE_DIR="release"
DO_RELEASE=0
if [[ $* == *--release* ]]; then
DO_RELEASE=1
fi
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
GIT_COMMIT=
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')
VERSION_TAG=$(git describe --tags 2>/dev/null || echo 'unknown')
if [ "$VERSION" != "$VERSION_TAG" ]; then
echo "Dirty commits detected, marking as development build"
GIT_COMMIT=$(git rev-parse HEAD 2>/dev/null || echo 'unknown')
GIT_COMMIT_SHORT=$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
VERSION="${VERSION}.${GIT_COMMIT_SHORT}"
DO_RELEASE=0
if [[ $* == *--release* && $* == *--force* ]]; then
echo "Forcing release build anyway"
DO_RELEASE=1
fi
fi
LD_FLAGS=${LD_FLAGS:-""}
LD_FLAGS="$LD_FLAGS -X git.avsdev.uk/Go/job-search/internal/version.Version=${VERSION}"
if [[ $DO_RELEASE -ne 1 ]]; then
LD_FLAGS="$LD_FLAGS -X git.avsdev.uk/Go/job-search/internal/version.BuildTime=${BUILD_TIME}"
fi
if [ "$GIT_COMMIT" != "" ]; then
LD_FLAGS="$LD_FLAGS -X git.avsdev.uk/Go/job-search/internal/version.GitCommit=${GIT_COMMIT}"
fi
# Process any generators
go generate ./...
# Build binary with version info
go build \
-ldflags="$LD_FLAGS" \
-trimpath \
-o $BUILD_DIR/job-search-$VERSION \
./cmd/jobsearch
echo "Built $BUILD_DIR/job-search-$VERSION"
# If proper release, copy to output directory for packaging
if [[ $DO_RELEASE -eq 1 ]]; then
install -DT $BUILD_DIR/job-search-$VERSION $RELEASE_DIR/job-search
ARCH=`dpkg --print-architecture`
tar -czf $RELEASE_DIR/job-search-$VERSION-$ARCH.tar.gz \
--transform "s,^$RELEASE_DIR/,job-search-$VERSION-$ARCH/," \
$RELEASE_DIR/job-search
echo "Installed $RELEASE_DIR/job-search"
fi