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
15 changes: 7 additions & 8 deletions .github/workflows/buid_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
-
Expand All @@ -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
-
Expand All @@ -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-<platform>
- 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
Expand Down
46 changes: 34 additions & 12 deletions bin/blink
Original file line number Diff line number Diff line change
@@ -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-<os>-<arch>).
# 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
12 changes: 6 additions & 6 deletions src/Turbo/EcsGoBinaryLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
) {
}

Expand All @@ -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)) {
Expand All @@ -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,
));
Expand Down
4 changes: 2 additions & 2 deletions tests/Turbo/EcsGoBinaryLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
File renamed without changes.
Loading