diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 655f03b..c4df005 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,6 +77,135 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: php-matrix.phar + name: phar path: phar/php-matrix if-no-files-found: error + + build: + name: build (${{ matrix.runs-on }}) + needs: phar + strategy: + matrix: + include: + - runs-on: ubuntu-24.04-arm + variant: linux_arm64 + spc-variant: linux-aarch64 + - runs-on: ubuntu-24.04 + variant: linux_amd64 + spc-variant: linux-x86_64 + - runs-on: macos-15 + variant: darwin_arm64 + spc-variant: macos-aarch64 + - runs-on: macos-15-intel + variant: darwin_amd64 + spc-variant: macos-x86_64 + runs-on: ${{ matrix.runs-on }} + steps: + - uses: actions/checkout@v5 + with: + sparse-checkout: craft.yml + sparse-checkout-cone-mode: false + + - name: Install spc + run: | + gh release download --repo crazywhalecc/static-php-cli --pattern "${PATTERN}" --output spc.tar.gz && \ + mkdir -p /tmp/spc && \ + tar -xvf spc.tar.gz --directory /tmp/spc && \ + echo "/tmp/spc" >> "$GITHUB_PATH" + env: + PATTERN: spc-${{ matrix.spc-variant }}.tar.gz + GH_TOKEN: ${{ github.token }} + + - uses: actions/download-artifact@v5 + with: + name: phar + path: phar + + - name: Restore cached micro.sfx + id: restore-micro-sfx + uses: actions/cache/restore@v4 + with: + path: buildroot/bin/micro.sfx + key: micro-sfx-${{ runner.os }}-${{ runner.arch }}-${{ needs.phar.outputs.php-version }}-${{ hashFiles('craft.yml') }} + + - name: Build micro.sfx + if: steps.restore-micro-sfx.outputs.cache-hit != 'true' + run: spc craft + env: + GITHUB_TOKEN: ${{ github.token }} # Not a typo. + + - name: Cache micro.sfx + id: cache-micro-sfx + if: steps.restore-micro-sfx.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: buildroot/bin/micro.sfx + key: ${{ steps.restore-micro-sfx.outputs.cache-primary-key }} + + - run: mkdir -p out + - run: spc micro:combine phar/php-matrix --output out/php-matrix + + - uses: actions/upload-artifact@v4 + with: + name: php-matrix_${{ matrix.variant }} + path: out/php-matrix + if-no-files-found: error + + e2e: + name: e2e (${{ matrix.runs-on }}) + needs: build + strategy: + matrix: + include: + - runs-on: ubuntu-24.04-arm + variant: linux_arm64 + - runs-on: ubuntu-24.04 + variant: linux_amd64 + - runs-on: macos-15 + variant: darwin_arm64 + - runs-on: macos-15-intel + variant: darwin_amd64 + runs-on: ${{ matrix.runs-on }} + env: + GOFLAGS: '-mod=mod' + steps: + - uses: actions/checkout@v5 + + - uses: actions/setup-go@v6 + with: + go-version-file: 'go.mod' + + - run: echo OS="$(go env GOOS)" >> $GITHUB_ENV + - run: echo ARCH="$(go env GOARCH)" >> $GITHUB_ENV + + - uses: actions/download-artifact@v5 + with: + name: php-matrix_${{ matrix.variant }} + path: out + + - name: Grant the binary execute permission + run: chmod +x out/php-matrix + + - name: Add the binary into PATH + run: echo "${WORKSPACE}/out" >> "$GITHUB_PATH" + env: + WORKSPACE: ${{ github.workspace }} + + - name: Print the binary path + run: go test -count=1 -v ./internal + + - run: go test -count=1 ./... + + merge: + needs: + - build + - e2e + runs-on: ubuntu-24.04 + steps: + - name: Merge binary artifacts + uses: actions/upload-artifact/merge@v4 + with: + name: binaries + pattern: php-matrix_* + separate-directories: true + delete-merged: true diff --git a/.gitignore b/.gitignore index 0efb0b6..bd36730 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,11 @@ # Box /phar/ + +# Static PHP CLI (spc) +/buildroot/ +/downloads/ +/log/ +/out/ +/pkgroot/ +/source/ diff --git a/composer.json b/composer.json index b6140ef..b936fbc 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,8 @@ "composer-runtime-api": "^2.2", "composer/semver": "^3.4", "guzzlehttp/guzzle": "^7.10", - "symfony/console": "^7.3" + "symfony/console": "^7.3", + "symfony/polyfill-iconv": "^1.33" }, "require-dev": { "mockery/mockery": "^1.6", diff --git a/composer.lock b/composer.lock index a9ed1d9..12e6cd6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ae157235d90a82c6435e6ffd3cd98ba7", + "content-hash": "a30de2a4a1940747be0195d81fee04f7", "packages": [ { "name": "composer/semver", @@ -913,6 +913,90 @@ ], "time": "2024-09-09T11:45:10+00:00" }, + { + "name": "symfony/polyfill-iconv", + "version": "v1.33.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-iconv.git", + "reference": "5f3b930437ae03ae5dff61269024d8ea1b3774aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/5f3b930437ae03ae5dff61269024d8ea1b3774aa", + "reference": "5f3b930437ae03ae5dff61269024d8ea1b3774aa", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "provide": { + "ext-iconv": "*" + }, + "suggest": { + "ext-iconv": "For best performance" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Iconv\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Iconv extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "iconv", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-iconv/tree/v1.33.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://github.com/nicolas-grekas", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-09-17T14:58:18+00:00" + }, { "name": "symfony/polyfill-intl-grapheme", "version": "v1.33.0", diff --git a/craft.yml b/craft.yml new file mode 100644 index 0000000..dc2e87d --- /dev/null +++ b/craft.yml @@ -0,0 +1,9 @@ +php-version: 8.4 +extensions: + - phar + - filter # For Symfony CompleteCommand + - curl # For guzzlehttp/guzzle +sapi: + - micro +download-options: + prefer-pre-built: true