From 6fe0c583ee618e3458a0f89e0c821565c31dc803 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 29 Sep 2026 13:51:49 +0200 Subject: [PATCH] Build blink binaries from local blink/ module in release The release build now compiles the per-platform blink binaries from the ported blink/ module instead of cloning the external ecs-go repository, so the shipped --blink runner reflects the code in this repository. - release step builds bin/blink-- from blink/, drops the external clone - remove the obsolete bin/turbo directory from the deployed repo - EcsGoBinaryLocator resolves the bundled bin/blink- - bin/blink wrapper execs the bundled binary, building from blink/ only in the source repo --- .github/workflows/buid_release.yaml | 15 ++++---- bin/blink | 46 +++++++++++++++++------- src/Turbo/EcsGoBinaryLocator.php | 12 +++---- tests/Turbo/EcsGoBinaryLocatorTest.php | 4 +-- tests/Turbo/Source/bin/{ecs-go => blink} | 0 5 files changed, 49 insertions(+), 28 deletions(-) rename tests/Turbo/Source/bin/{ecs-go => blink} (100%) diff --git a/.github/workflows/buid_release.yaml b/.github/workflows/buid_release.yaml index e7150b3f69..f4ec06ff27 100644 --- a/.github/workflows/buid_release.yaml +++ b/.github/workflows/buid_release.yaml @@ -73,6 +73,7 @@ jobs: # make bin files runnable without "php" chmod 777 ecs-prefixed-downgraded/bin/ecs chmod 777 ecs-prefixed-downgraded/bin/ecs.php + chmod 777 ecs-prefixed-downgraded/bin/blink # 4. lint the code for PHP 7.4 - this must happen here, as setup-php allows only one PHP version switch: https://github.com/shivammathur/setup-php/issues/434 - @@ -91,24 +92,21 @@ jobs: cp -R build/target-repository/. ecs-prefixed-downgraded cp -R templates ecs-prefixed-downgraded/ - # 5b. bundle ecs-go binaries for --blink, so it works without a Go toolchain + # 5b. bundle blink binaries for --blink, built from the local blink/ module, + # so it works without a Go toolchain - uses: actions/setup-go@v5 with: go-version: "1.26.6" - run: | - git clone --depth 1 https://github.com/TomasVotruba/ecs-go.git ecs-go-local - mkdir -p ecs-prefixed-downgraded/bin/turbo - for target in linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64; do suffix="" if [ "${target%/*}" = "windows" ]; then suffix=".exe"; fi - (cd ecs-go-local/ecs-go && CGO_ENABLED=0 GOOS=${target%/*} GOARCH=${target#*/} go build -trimpath -ldflags="-s -w" -o "$GITHUB_WORKSPACE/ecs-prefixed-downgraded/bin/turbo/ecs-go-${target%/*}-${target#*/}${suffix}" .) + (cd blink && CGO_ENABLED=0 GOOS=${target%/*} GOARCH=${target#*/} go build -trimpath -ldflags="-s -w" -o "$GITHUB_WORKSPACE/ecs-prefixed-downgraded/bin/blink-${target%/*}-${target#*/}${suffix}" .) done - chmod 755 ecs-prefixed-downgraded/bin/turbo/* - rm -rf ecs-go-local + chmod 755 ecs-prefixed-downgraded/bin/blink-* # 6. clone remote repository, so we can push it - @@ -121,7 +119,8 @@ jobs: token: ${{ secrets.ACCESS_TOKEN }} # remove remote files, to avoid piling up dead code in remote repository - - run: rm -rf remote-repository/.github remote-repository/docs remote-repository/config remote-repository/packages remote-repository/src remote-repository/vendor + # bin/turbo is the obsolete ecs-go binary directory, replaced by bin/blink- + - run: rm -rf remote-repository/.github remote-repository/docs remote-repository/config remote-repository/packages remote-repository/src remote-repository/vendor remote-repository/bin/turbo # clear the dev files - run: cp -a ecs-prefixed-downgraded/. remote-repository diff --git a/bin/blink b/bin/blink index a0d1da0382..7b14f66aa1 100755 --- a/bin/blink +++ b/bin/blink @@ -1,19 +1,41 @@ #!/usr/bin/env sh -# Composer bin wrapper for blink, the Go coding-standard tool under blink/. -# Builds the binary on first run (Go required) and execs it, so it works as -# vendor/bin/blink after installation without a build step at install time. +# Composer bin wrapper for blink, the Go coding-standard tool. +# In a release it execs the bundled per-platform binary (bin/blink--). +# In the source repo it builds from blink/ on first run (Go required). set -e -ROOT="$(cd "$(dirname "$0")/.." && pwd)" -SRC="$ROOT/blink" -BINARY="$SRC/blink" +DIR="$(cd "$(dirname "$0")" && pwd)" -if [ ! -x "$BINARY" ]; then - if ! command -v go >/dev/null 2>&1; then - echo "blink: Go toolchain required to build the binary (https://go.dev/dl)" >&2 - exit 1 +os=$(uname -s) +arch=$(uname -m) +case "$os" in + Linux) os=linux ;; + Darwin) os=darwin ;; + *) os= ;; +esac +case "$arch" in + x86_64 | amd64) arch=amd64 ;; + aarch64 | arm64) arch=arm64 ;; + *) arch= ;; +esac + +if [ -n "$os" ] && [ -n "$arch" ] && [ -x "$DIR/blink-$os-$arch" ]; then + exec "$DIR/blink-$os-$arch" "$@" +fi + +# source checkout: build from the blink/ Go module +SRC="$DIR/../blink" +if [ -d "$SRC" ]; then + BINARY="$SRC/blink" + if [ ! -x "$BINARY" ]; then + if ! command -v go >/dev/null 2>&1; then + echo "blink: Go toolchain required to build from source (https://go.dev/dl)" >&2 + exit 1 + fi + (cd "$SRC" && go build -o "$BINARY" .) fi - (cd "$SRC" && go build -o "$BINARY" .) + exec "$BINARY" "$@" fi -exec "$BINARY" "$@" +echo "blink: no bundled binary for $os-$arch and no blink/ source to build from" >&2 +exit 1 diff --git a/src/Turbo/EcsGoBinaryLocator.php b/src/Turbo/EcsGoBinaryLocator.php index 5d4a8d50ac..6caa338d8e 100644 --- a/src/Turbo/EcsGoBinaryLocator.php +++ b/src/Turbo/EcsGoBinaryLocator.php @@ -16,8 +16,8 @@ private const string ENV_OVERRIDE = 'ECS_TURBO_BIN'; public function __construct( - // filled with per-platform binaries by the release build, see .github/workflows/buid_release.yaml - private string $bundledDirectory = __DIR__ . '/../../bin/turbo', + // filled with per-platform blink binaries by the release build, see .github/workflows/buid_release.yaml + private string $bundledDirectory = __DIR__ . '/../../bin', ) { } @@ -28,7 +28,7 @@ public function locate(): string return $envBinary; } - $bundledBinary = $this->bundledDirectory . '/ecs-go-' . $this->resolvePlatform(); + $bundledBinary = $this->bundledDirectory . '/blink-' . $this->resolvePlatform(); if (is_file($bundledBinary)) { // archive extraction can drop the executable bit if (! is_executable($bundledBinary)) { @@ -38,18 +38,18 @@ public function locate(): string return $bundledBinary; } - $vendorBinary = getcwd() . '/vendor/bin/ecs-go'; + $vendorBinary = getcwd() . '/vendor/bin/blink'; if (is_file($vendorBinary)) { return $vendorBinary; } - $pathBinary = $this->findOnPath('ecs-go'); + $pathBinary = $this->findOnPath('blink'); if ($pathBinary !== null) { return $pathBinary; } throw new EcsGoBinaryNotFoundException(sprintf( - 'The ecs-go binary for --blink was not found in "%s" env, "vendor/bin/ecs-go" or on PATH. Build it from https://github.com/TomasVotruba/ecs-go and point "%s" to it.', + 'The blink binary for --blink was not found in "%s" env, "vendor/bin/blink" or on PATH. Build it with "go build" in the blink/ directory and point "%s" to it.', self::ENV_OVERRIDE, self::ENV_OVERRIDE, )); diff --git a/tests/Turbo/EcsGoBinaryLocatorTest.php b/tests/Turbo/EcsGoBinaryLocatorTest.php index 409945c96b..5205f3d0da 100644 --- a/tests/Turbo/EcsGoBinaryLocatorTest.php +++ b/tests/Turbo/EcsGoBinaryLocatorTest.php @@ -35,7 +35,7 @@ public function testBundledBinaryWinsOverPath(): void $arch = in_array(strtolower(php_uname('m')), ['aarch64', 'arm64'], true) ? 'arm64' : 'amd64'; $suffix = PHP_OS_FAMILY === 'Windows' ? '.exe' : ''; - $bundledBinary = $bundledDirectory . '/ecs-go-' . strtolower(PHP_OS_FAMILY) . '-' . $arch . $suffix; + $bundledBinary = $bundledDirectory . '/blink-' . strtolower(PHP_OS_FAMILY) . '-' . $arch . $suffix; touch($bundledBinary); $ecsGoBinaryLocator = new EcsGoBinaryLocator($bundledDirectory); @@ -55,7 +55,7 @@ public function testFindsBinaryOnPath(): void $originalPath = (string) getenv('PATH'); putenv('PATH=' . __DIR__ . '/Source/bin'); - $this->assertSame(__DIR__ . '/Source/bin/ecs-go', $this->ecsGoBinaryLocator->locate()); + $this->assertSame(__DIR__ . '/Source/bin/blink', $this->ecsGoBinaryLocator->locate()); putenv('PATH=' . $originalPath); } diff --git a/tests/Turbo/Source/bin/ecs-go b/tests/Turbo/Source/bin/blink similarity index 100% rename from tests/Turbo/Source/bin/ecs-go rename to tests/Turbo/Source/bin/blink