From 61ee0fbedf79fb66799386d4493873d268589818 Mon Sep 17 00:00:00 2001 From: Jacobo de Vera Date: Mon, 16 Feb 2026 09:31:06 +0000 Subject: [PATCH 1/4] Enhance build script with named flags, build number option, and legacy support Replace the positional-only build script with a flag-based CLI: - Named flags: -v/--version, -n/--name, -l/--long-name, -o/--output - New -b/--build-number flag for stable CI build numbers (github.run_number) - Legacy positional args (VERSION NAME LONG_NAME) still work for muscle memory - Debug mode (-d), help (-h), and input validation - Update CI workflow to use build.sh with -b for stable build numbers - Update docs (README, introduction, build-from-source) with new usage --- .github/workflows/go.yml | 5 +- README.md | 11 +- build.sh | 155 +++++++++++++++++- .../content/en/docs/overview/introduction.md | 5 +- .../en/docs/quickstart/build-from-source.md | 5 +- 5 files changed, 156 insertions(+), 25 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index fa0b880c..93c32338 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -59,9 +59,8 @@ jobs: GOARCH: ${{matrix.arch}} CGO_ENABLED: ${{matrix.cgo}} run: | - go build -o build/cdt_${{steps.vars.outputs.os}}_${{matrix.arch}}_${{steps.vars.outputs.sha_short}} -ldflags='-X main.version=${{github.ref_name}} -X main.buildNum=${{github.run_number}} -X main.appName=cdt' - - go build -o build/cola_${{steps.vars.outputs.os}}_${{matrix.arch}}_${{steps.vars.outputs.sha_short}} -ldflags="-X main.version=${{github.ref_name}} -X main.buildNum=${{github.run_number}} -X main.appName=cola -X 'main.appLongName=Command Launcher'" + ./build.sh -v ${{github.ref_name}} -b ${{github.run_number}} -n cdt -l "Criteo Dev Toolkit" -o build/cdt_${{steps.vars.outputs.os}}_${{matrix.arch}}_${{steps.vars.outputs.sha_short}} + ./build.sh -v ${{github.ref_name}} -b ${{github.run_number}} -n cola -l "Command Launcher" -o build/cola_${{steps.vars.outputs.os}}_${{matrix.arch}}_${{steps.vars.outputs.sha_short}} - name: Test & Benchmark run: go test -v ./... diff --git a/README.md b/README.md index c8d30ebc..1ecbcc81 100644 --- a/README.md +++ b/README.md @@ -66,14 +66,9 @@ You can build the command launcher with your prefered name (in the example: `Cri go build -o cdt -ldflags='-X main.version=dev -X main.appName=cdt -X "main.appLongName=Criteo Dev Toolkit"' main.go ``` -Or simply call the `build.sh` scripts -``` -./build.sh [version] [app name] [app long name] [--resign] -``` - -On macOS (Apple Silicon), copying the built binary to another location may invalidate its ad-hoc code signature, causing the system to kill the process. Use the `--resign` flag to re-sign the binary after build: -``` -./build.sh dev cdt "Criteo Dev Toolkit" --resign +Or using the `build.sh` script +```shell +./build.sh -v VERSION -n APP_NAME -l APP_LONG_NAME ``` ### Run tests diff --git a/build.sh b/build.sh index 19f56044..20bc119a 100755 --- a/build.sh +++ b/build.sh @@ -1,14 +1,153 @@ #!/usr/bin/env sh -DEFAULT_VERSION=$(git rev-parse --abbrev-ref HEAD)-dev +DEBUG=0 -VERSION=${1:-$DEFAULT_VERSION} -APP_NAME=${2:-cdt} -APP_LONG_NAME=${3:-Criteo Dev Toolkit} -RESIGN=${4:-} +# Default values +DEFAULT_APP_NAME="cdt" +DEFAULT_APP_LONG_NAME="Criteo Dev Toolkit" -go build -o $APP_NAME -ldflags="-X main.version=$VERSION -X main.buildNum=$(date +'%Y%m%d-%H%M%S') -X main.appName=$APP_NAME -X 'main.appLongName=$APP_LONG_NAME'" +default_version() { + echo "$(git rev-parse --abbrev-ref HEAD)-dev" +} -if [ "$RESIGN" = "--resign" ] && [ "$(uname)" = "Darwin" ]; then - codesign --force -s - "$APP_NAME" +default_build_number() { + date +'%Y%m%d-%H%M%S' +} + +debug() { + if [ $DEBUG -eq 1 ]; then + echo "$1" + fi +} + +# Function to show usage +show_usage() { + program=$(basename "$0") + cat <&2 + exit 1 + fi +} + +# Parse options +VERSION= +APP_NAME= +APP_LONG_NAME= +OUTPUT= +BUILD_NUMBER= +POSITIONAL_COUNT=0 + +while [ $# -gt 0 ]; do + case "$1" in + -v|--version) + validate_argument "$1" "$2" + VERSION="$2" + shift 2 + ;; + -n|--name) + validate_argument "$1" "$2" + APP_NAME="$2" + shift 2 + ;; + -l|--long-name) + validate_argument "$1" "$2" + APP_LONG_NAME="$2" + shift 2 + ;; + -o|--output) + validate_argument "$1" "$2" + OUTPUT="$2" + shift 2 + ;; + -b|--build-number) + validate_argument "$1" "$2" + BUILD_NUMBER="$2" + shift 2 + ;; + -d|--debug) + DEBUG=1 + shift 1 + ;; + -h|--help) + show_usage + exit 0 + ;; + -*) + echo "Error: Unknown option $1" >&2 + show_usage + exit 1 + ;; + *) + # Collect positional arguments for legacy mode + POSITIONAL_COUNT=$((POSITIONAL_COUNT + 1)) + case $POSITIONAL_COUNT in + 1) VERSION="$1" ;; + 2) APP_NAME="$1" ;; + 3) APP_LONG_NAME="$1" ;; + *) + echo "Error: Too many positional arguments" >&2 + show_usage + exit 1 + ;; + esac + shift + ;; + esac +done + +# Derive the long name from the app name if not set +if [ -z "$APP_LONG_NAME" ] && [ -n "$APP_NAME" ]; then + APP_LONG_NAME="$APP_NAME Command Launcher" fi + +# Set defaults for missing arguments +[ -z "$VERSION" ] && VERSION=$(default_version) +[ -z "$APP_NAME" ] && APP_NAME=$DEFAULT_APP_NAME +[ -z "$APP_LONG_NAME" ] && APP_LONG_NAME=$DEFAULT_APP_LONG_NAME +[ -z "$OUTPUT" ] && OUTPUT=$APP_NAME +[ -z "$BUILD_NUMBER" ] && BUILD_NUMBER=$(default_build_number) + +LD_FLAGS="" +LD_FLAGS="$LD_FLAGS -X main.version=${VERSION}" +LD_FLAGS="$LD_FLAGS -X main.buildNum=${BUILD_NUMBER}" +LD_FLAGS="$LD_FLAGS -X main.appName=${APP_NAME}" +LD_FLAGS="$LD_FLAGS -X 'main.appLongName=${APP_LONG_NAME}'" + +debug "Building $APP_NAME" +debug "Version: $VERSION" +debug "Build number: $BUILD_NUMBER" +debug "App name: $APP_NAME" +debug "App long name: $APP_LONG_NAME" +debug "Output: $OUTPUT" + +go build -o "$OUTPUT" -ldflags="${LD_FLAGS}" diff --git a/gh-pages/content/en/docs/overview/introduction.md b/gh-pages/content/en/docs/overview/introduction.md index 22ff513a..c765b60b 100644 --- a/gh-pages/content/en/docs/overview/introduction.md +++ b/gh-pages/content/en/docs/overview/introduction.md @@ -82,10 +82,9 @@ You can build the command launcher with your preferred name (in the example: `Cr go build -o cdt -ldflags='-X main.version=dev -X main.appName=cdt -X "main.appLongName=Criteo Dev Toolkit"' main.go ``` -Or simply call the `build.sh` script - +Or using the `build.sh` script ```shell -./build.sh [version] [app name] [app long name] +./build.sh -v VERSION -n APP_NAME -l APP_LONG_NAME ``` ## Running tests diff --git a/gh-pages/content/en/docs/quickstart/build-from-source.md b/gh-pages/content/en/docs/quickstart/build-from-source.md index 8bc88160..83010d57 100644 --- a/gh-pages/content/en/docs/quickstart/build-from-source.md +++ b/gh-pages/content/en/docs/quickstart/build-from-source.md @@ -36,10 +36,9 @@ You can build the command launcher with your prefered name (in the example: `Com go build -o cola -ldflags='-X main.version=dev -X main.appName=cola -X "main.appLongName=Command Launcher"' main.go ``` -Or simply call the `build.sh` scripts - +Or using the `build.sh` script ```shell -./build.sh [version] [app name] [app long name] +./build.sh -v VERSION -n APP_NAME -l APP_LONG_NAME ``` ## Run tests From 3ff8c9978655c663dd376ace291ab4ea78e2a093 Mon Sep 17 00:00:00 2001 From: Jacobo de Vera Date: Sun, 15 Mar 2026 12:14:34 +0000 Subject: [PATCH 2/4] Fix markdown lint: add blank lines before fenced code blocks --- gh-pages/content/en/docs/overview/introduction.md | 1 + gh-pages/content/en/docs/quickstart/build-from-source.md | 1 + 2 files changed, 2 insertions(+) diff --git a/gh-pages/content/en/docs/overview/introduction.md b/gh-pages/content/en/docs/overview/introduction.md index c765b60b..fb84731a 100644 --- a/gh-pages/content/en/docs/overview/introduction.md +++ b/gh-pages/content/en/docs/overview/introduction.md @@ -83,6 +83,7 @@ go build -o cdt -ldflags='-X main.version=dev -X main.appName=cdt -X "main.appLo ``` Or using the `build.sh` script + ```shell ./build.sh -v VERSION -n APP_NAME -l APP_LONG_NAME ``` diff --git a/gh-pages/content/en/docs/quickstart/build-from-source.md b/gh-pages/content/en/docs/quickstart/build-from-source.md index 83010d57..1750b93e 100644 --- a/gh-pages/content/en/docs/quickstart/build-from-source.md +++ b/gh-pages/content/en/docs/quickstart/build-from-source.md @@ -37,6 +37,7 @@ go build -o cola -ldflags='-X main.version=dev -X main.appName=cola -X "main.app ``` Or using the `build.sh` script + ```shell ./build.sh -v VERSION -n APP_NAME -l APP_LONG_NAME ``` From 252a3cb2797db4fd128b5b5e775b189b0e5f9ed9 Mon Sep 17 00:00:00 2001 From: Jacobo de Vera Date: Sun, 15 Mar 2026 12:19:49 +0000 Subject: [PATCH 3/4] Accept legacy --resign as positional arg for backwards compat --- build.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.sh b/build.sh index 20bc119a..cd43fcb8 100755 --- a/build.sh +++ b/build.sh @@ -102,6 +102,11 @@ while [ $# -gt 0 ]; do show_usage exit 0 ;; + --resign) + # Legacy compat: accept --resign without short flag in positional mode + RESIGN=1 + shift 1 + ;; -*) echo "Error: Unknown option $1" >&2 show_usage From 0238a137209fc8941c91fa10205d2bef4003c7e3 Mon Sep 17 00:00:00 2001 From: Jacobo de Vera Date: Sun, 15 Mar 2026 12:28:37 +0000 Subject: [PATCH 4/4] Fix Windows CI: add shell: bash to Build step --- .github/workflows/go.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 93c32338..023cee14 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -58,6 +58,7 @@ jobs: env: GOARCH: ${{matrix.arch}} CGO_ENABLED: ${{matrix.cgo}} + shell: bash run: | ./build.sh -v ${{github.ref_name}} -b ${{github.run_number}} -n cdt -l "Criteo Dev Toolkit" -o build/cdt_${{steps.vars.outputs.os}}_${{matrix.arch}}_${{steps.vars.outputs.sha_short}} ./build.sh -v ${{github.ref_name}} -b ${{github.run_number}} -n cola -l "Command Launcher" -o build/cola_${{steps.vars.outputs.os}}_${{matrix.arch}}_${{steps.vars.outputs.sha_short}}