diff --git a/.github/actions/cache/action.yaml b/.github/actions/cache/action.yaml index 02bfc7c1..4280e0f1 100644 --- a/.github/actions/cache/action.yaml +++ b/.github/actions/cache/action.yaml @@ -1,6 +1,12 @@ name: 'Compute cache keys' description: 'Export cache keys for the build process to env vars' +inputs: + os: + description: 'The OS to compute the cache key for' + required: true + default: 'linux' + runs: using: "composite" steps: @@ -9,11 +15,17 @@ runs: run: | set -e - # Should be the same command as the one in .github/workflows/ci.yml - cache_dirname_main=$(tests/bin/compile-get-cache-key phar-location-is-not-used-in-cache-key --php-extensions=mbstring,phar,posix,tokenizer,pcntl) - cache_key_main=$(basename $cache_dirname_main) - echo cache_dirname_main=$cache_dirname_main >> $GITHUB_ENV - echo cache_key_main=$cache_key_main >> $GITHUB_ENV + # Should be the same command as the one in tools/static/castor.php + cache_dirname_linux_amd64=$(tests/bin/compile-get-cache-key phar-location-is-not-used-in-cache-key --os=linux --arch=x86_64 --php-extensions=mbstring,phar,posix,tokenizer,pcntl) + cache_key_linux_amd64=$(basename $cache_dirname_linux_amd64) + echo cache_dirname_linux_amd64=$cache_dirname_linux_amd64 >> $GITHUB_ENV + echo cache_key_linux_amd64=$cache_key_linux_amd64 >> $GITHUB_ENV + + # Should be the same command as the one in tools/static/castor.php + cache_dirname_darwin_amd64=$(tests/bin/compile-get-cache-key phar-location-is-not-used-in-cache-key --os=macos --arch=x86_64 --php-extensions=mbstring,phar,posix,tokenizer,pcntl) + cache_key_darwin_amd64=$(basename $cache_dirname_darwin_amd64) + echo cache_dirname_darwin_amd64=$cache_dirname_darwin_amd64 >> $GITHUB_ENV + echo cache_key_darwin_amd64=$cache_key_darwin_amd64 >> $GITHUB_ENV # And should be the same command as the one in CompileCommandTest cache_dirname_test=$(tests/bin/compile-get-cache-key phar-location-is-not-used-in-cache-key --os linux --php-extensions mbstring,phar,posix,tokenizer) @@ -21,15 +33,23 @@ runs: echo cache_dirname_test=$cache_dirname_test >> $GITHUB_ENV echo cache_key_test=$cache_key_test >> $GITHUB_ENV - - name: Restore PHP static building artifacts cache for main job + - name: Restore PHP static building artifacts cache for linux-amd64 + uses: actions/cache@v4 + with: + path: ${{ env.cache_dirname_linux_amd64 }} + key: php-static-${{ env.cache_key_linux_amd64 }} + if: ${{ inputs.os == 'linux' }} + + - name: Restore PHP static building artifacts cache for darwin-amd64 uses: actions/cache@v4 with: - path: ${{ env.cache_dirname_main }} - key: php-static-${{ env.cache_key_main }} - if: matrix.castor.method == 'static' + path: ${{ env.cache_dirname_darwin_amd64 }} + key: php-static-${{ env.cache_key_darwin_amd64 }} + if: ${{ inputs.os == 'darwin' }} - name: Restore PHP static building artifacts cache for test job uses: actions/cache@v4 with: path: ${{ env.cache_dirname_test }} key: php-static-${{ env.cache_key_test }} + if: ${{ inputs.os == 'linux' }} diff --git a/.github/actions/static/action.yaml b/.github/actions/static/action.yaml index ec9cc9dd..609a1ad7 100644 --- a/.github/actions/static/action.yaml +++ b/.github/actions/static/action.yaml @@ -1,13 +1,41 @@ name: 'Build static binaries' description: 'Builds static binaries for all systems' +inputs: + os: + description: 'The operating system to build for' + required: true + default: 'linux' + runs: using: "composite" steps: - name: Build Castor static binary for Linux run: bin/castor castor:static:linux shell: bash + if: ${{ inputs.os == 'linux' }} + + - name: Ensure Linux binary is OK + run: ./castor.linux-amd64 --version + shell: bash + if: ${{ inputs.os == 'linux' }} + + - name: Build Castor static binary for MacOS - amd64 + run: bin/castor castor:static:darwin-amd64 + shell: bash + if: ${{ inputs.os == 'darwin-amd64' }} + + - name: Ensure MacOs - amd64 binary is OK + run: ./castor.darwin-amd64 --version + shell: bash + if: ${{ inputs.os == 'darwin-amd64' }} + + - name: Build Castor static binary for MacOS - arm64 + run: bin/castor castor:static:darwin-arm64 + shell: bash + if: ${{ inputs.os == 'darwin-arm64' }} - - name: Ensure binary is OK - run: ./castor.linux.x86_64 --version + - name: Ensure MacOs - arm64 binary is OK + run: ./castor.darwin-arm64 --version shell: bash + if: ${{ inputs.os == 'darwin-arm64' }} diff --git a/.github/workflows/artefacts.yml b/.github/workflows/artifacts.yml similarity index 52% rename from .github/workflows/artefacts.yml rename to .github/workflows/artifacts.yml index 4b8fc359..e3d5bb33 100644 --- a/.github/workflows/artefacts.yml +++ b/.github/workflows/artifacts.yml @@ -1,4 +1,4 @@ -name: Build phars +name: Artifacts on: push: @@ -10,8 +10,8 @@ permissions: contents: write jobs: - phar: - name: Create phar and upload them as an artifact + phars: + name: Create phars and upload runs-on: ubuntu-latest steps: @@ -52,10 +52,72 @@ jobs: path: tools/phar/build/castor.windows-amd64.phar if-no-files-found: error + static-linux: + needs: phars + name: Create Linux static binary and upload + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: ./.github/actions/install + + - uses: ./.github/actions/cache + with: + os: 'linux' + + - name: retrieve phar artifacts + uses: actions/download-artifact@v4 + with: + path: tools/phar/build + merge-multiple: true + + - uses: ./.github/actions/static + with: + os: 'linux' + + - name: Upload the Linux static binary + uses: actions/upload-artifact@v4 + with: + name: 'castor.linux-amd64' + path: ./castor.linux-amd64 + if-no-files-found: error + + static-darwin-amd64: + needs: phars + name: Create MacOs amd64 static binary and upload + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: ./.github/actions/install + + - uses: ./.github/actions/cache + with: + os: 'darwin' + + - name: retrieve phar artifacts + uses: actions/download-artifact@v4 + with: + path: tools/phar/build + merge-multiple: true + + - uses: ./.github/actions/static + with: + os: 'darwin-amd64' + + - name: Upload the MacOs amd64 static binary + uses: actions/upload-artifact@v4 + with: + name: 'castor.darwin-amd64' + path: ./castor.darwin-amd64 + if-no-files-found: error + release: - name: Upload phars to the release + name: Upload artifacts to the release if: github.event_name == 'release' - needs: [phar] + needs: [phars, static-linux, static-darwin-amd64] runs-on: ubuntu-latest steps: - name: Checkout @@ -69,8 +131,10 @@ jobs: - name: Upload files run: | + gh release upload ${{ github.ref_name }} ./build/castor.darwin-amd64 gh release upload ${{ github.ref_name }} ./build/castor.darwin-amd64.phar gh release upload ${{ github.ref_name }} ./build/castor.darwin-arm64.phar + gh release upload ${{ github.ref_name }} ./build/castor.linux-amd64 gh release upload ${{ github.ref_name }} ./build/castor.linux-amd64.phar gh release upload ${{ github.ref_name }} ./build/castor.windows-amd64.phar env: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6de658f8..f67dc3f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,7 +77,7 @@ jobs: if: matrix.castor.method == 'phar' || matrix.castor.method == 'static' - name: Compile Custom Built PHP along Castor phar for Linux - # Should be the same command as the one in .github/actions/cache/action.yaml + # Should be the same command as the one in tools/static/castor.php run: bin/castor compile tools/phar/build/castor.linux-amd64.phar --php-extensions=mbstring,phar,posix,tokenizer,pcntl --binary-path=${{ github.workspace }}/${{ matrix.castor.bin }} if: matrix.castor.method == 'static' diff --git a/CHANGELOG.md b/CHANGELOG.md index 2597010a..1e65a93c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Allow to listen to the symfony console events * Add a `compile` command that puts together a customizable PHP binary with a repacked castor app into one executable file +* Distribute `castor.linux.amd64` automatically with the release * Set the process title according to the current application name and task name * Compile watcher and phar for `ARM64` on macOS * Deprecates `add_context()` function, use `AsContextGenerator` attribute diff --git a/bin/generate-tests.php b/bin/generate-tests.php index 7f05d799..bb904e50 100755 --- a/bin/generate-tests.php +++ b/bin/generate-tests.php @@ -50,7 +50,8 @@ 'castor:qa:cs', 'castor:qa:phpstan', 'castor:repack', - 'castor:static:build', + 'castor:static:darwin-amd64', + 'castor:static:darwin-arm64', 'castor:static:linux', 'castor:watcher:build', 'castor:watcher:darwin', diff --git a/tests/Examples/Generated/ListTest.php.output.txt b/tests/Examples/Generated/ListTest.php.output.txt index 491d0ca3..871fc97a 100644 --- a/tests/Examples/Generated/ListTest.php.output.txt +++ b/tests/Examples/Generated/ListTest.php.output.txt @@ -15,8 +15,9 @@ castor:phar:linux Build phar for castor:phar:windows Build phar for Windows system castor:qa:cs Fix CS castor:qa:phpstan Run PHPStan -castor:static:build Build phar for all systems -castor:static:linux Build phar for Linux system +castor:static:darwin-amd64 Build static binary for MacOS (amd64) system +castor:static:darwin-arm64 Build static binary for MacOS (arm64) system +castor:static:linux Build static binary for Linux system castor:watcher:build Build watcher for all systems castor:watcher:darwin Build watcher for MacOS system castor:watcher:linux Build watcher for Linux system diff --git a/tools/static/castor.php b/tools/static/castor.php index f28aec5b..beb8632b 100644 --- a/tools/static/castor.php +++ b/tools/static/castor.php @@ -4,17 +4,22 @@ use Castor\Attribute\AsTask; -use function Castor\parallel; use function Castor\run; -#[AsTask(description: 'Build phar for Linux system')] +#[AsTask(description: 'Build static binary for Linux system')] function linux() { - run('bin/castor compile ./tools/phar/build/castor.linux-amd64.phar --os=linux --arch=x86_64', timeout: 0); + run('bin/castor compile tools/phar/build/castor.linux-amd64.phar --os=linux --arch=x86_64 --binary-path=castor.linux-amd64 --php-extensions=mbstring,phar,posix,tokenizer,pcntl', timeout: 0); } -#[AsTask(description: 'Build phar for all systems')] -function build() +#[AsTask(description: 'Build static binary for MacOS (amd64) system')] +function darwinAmd64() { - parallel(linux(...)); + run('bin/castor compile tools/phar/build/castor.darwin-amd64.phar --os=macos --arch=x86_64 --binary-path=castor.darwin-amd64 --php-extensions=mbstring,phar,posix,tokenizer,pcntl', timeout: 0); +} + +#[AsTask(description: 'Build static binary for MacOS (arm64) system')] +function darwinArm64() +{ + run('bin/castor compile tools/phar/build/castor.darwin-arm64.phar --os=macos --arch=aarch64 --binary-path=castor.darwin-arm64 --php-extensions=mbstring,phar,posix,tokenizer,pcntl', timeout: 0); }