Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ jobs:
env:
GOARCH: ${{matrix.arch}}
CGO_ENABLED: ${{matrix.cgo}}
shell: bash
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 ./...
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
160 changes: 152 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,158 @@
#!/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 <<EOF
Usage:
$program [OPTIONS]
OR
$program VERSION APP_NAME APP_LONG_NAME

Options:
-v, --version VERSION Set version
-n, --name NAME Set app name
-l, --long-name LONG_NAME Set app long name
-o, --output OUTPUT Set output file name (default: APP_NAME)
-b, --build-number NUMBER Set build number (default: timestamp)
-d, --debug Enable debug output
-h, --help Show this help message

Examples:
$program # Use all defaults
$program 1.0.0 # Set version only (legacy)
$program 1.0.0 myapp 'My App' # Set all three (legacy)
$program -v 1.0.0 # Set version only
$program -n myapp # Set app name only
$program -l 'My App' # Set app long name only
$program -v 1.0.0 -n myapp -l 'My App' # Set all three
$program -b 42 # Set build number
EOF
}

validate_argument() {
if [ -z "$2" ] || [ "${2#-}" = "$2" ]; then
return 0
else
echo "Error: $1 requires a value" >&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
;;
--resign)
# Legacy compat: accept --resign without short flag in positional mode
RESIGN=1
shift 1
;;
-*)
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}"
4 changes: 2 additions & 2 deletions gh-pages/content/en/docs/overview/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions gh-pages/content/en/docs/quickstart/build-from-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ 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
Expand Down
Loading