release-build.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. name: Build SPC Binary
  2. on:
  3. push:
  4. branches: [ "main" ]
  5. release:
  6. types:
  7. - published
  8. workflow_dispatch:
  9. env:
  10. PHP_VERSION: 8.2
  11. MICRO_VERSION: 8.2.18
  12. jobs:
  13. build-release-artifacts:
  14. name: "Build SPC Binary for ${{ matrix.operating-system.name }}"
  15. runs-on: ${{ matrix.operating-system.os }}
  16. strategy:
  17. matrix:
  18. operating-system:
  19. - name: "linux-x86_64"
  20. os: "ubuntu-latest"
  21. filename: "spc-linux-x86_64.tar.gz"
  22. - name: "macos-x86_64"
  23. os: "macos-13"
  24. filename: "spc-macos-x86_64.tar.gz"
  25. - name: "linux-aarch64"
  26. os: "ubuntu-latest"
  27. filename: "spc-linux-aarch64.tar.gz"
  28. - name: "macos-aarch64"
  29. os: "macos-14"
  30. filename: "spc-macos-aarch64.tar.gz"
  31. - name: "windows-x64"
  32. os: "ubuntu-latest"
  33. filename: "spc-windows-x64.exe"
  34. steps:
  35. - name: "Checkout"
  36. uses: "actions/checkout@v4"
  37. - if: inputs.debug == true
  38. run: echo "SPC_BUILD_DEBUG=--debug" >> $GITHUB_ENV
  39. - name: "Install PHP for official runners"
  40. uses: "shivammathur/setup-php@v2"
  41. with:
  42. coverage: none
  43. tools: composer:v2
  44. php-version: "${{ env.PHP_VERSION }}"
  45. ini-values: memory_limit=-1
  46. - name: "Get Composer Cache Directory"
  47. id: composer-cache
  48. run: |
  49. echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
  50. - name: "Cache Composer dependencies"
  51. uses: "actions/cache@v4"
  52. with:
  53. path: "${{ steps.composer-cache.outputs.dir }}"
  54. key: "php-${{ env.PHP_VERSION }}-locked-composer-${{ hashFiles('**/composer.lock') }}"
  55. restore-keys: |
  56. php-${{ env.PHP_VERSION }}-locked-composer
  57. - name: "Install Locked Dependencies"
  58. run: "composer install --no-interaction --no-progress"
  59. - name: "Build PHAR File"
  60. run: "composer build:phar"
  61. - name: "Download Minimal Combination"
  62. run: |
  63. if [ "${{ matrix.operating-system.name }}" = "windows-x64" ]; then
  64. curl -fsSL https://dl.static-php.dev/static-php-cli/windows/spc-min/php-${{ env.MICRO_VERSION }}-micro-win.zip -o tmp.zip
  65. unzip tmp.zip
  66. else
  67. curl -fsSL https://dl.static-php.dev/static-php-cli/minimal/php-${{ env.MICRO_VERSION }}-micro-${{ matrix.operating-system.name }}.tar.gz -o tmp.tgz
  68. tar -zxvf tmp.tgz
  69. fi
  70. - name: "Generate Executable"
  71. run: |
  72. bin/spc micro:combine spc.phar -M micro.sfx -O spc -I "memory_limit=2G"
  73. if [ "${{ matrix.operating-system.name }}" = "windows-x64" ]; then
  74. mv spc spc.exe
  75. else
  76. chmod +x spc
  77. fi
  78. if [ "${{ matrix.operating-system.name }}" = "macos-aarch64" ] || [ "${{ matrix.operating-system.name }}" = "macos-x86_64" ]; then
  79. sudo xattr -cr ./spc
  80. fi
  81. - name: "Archive Executable and Validate Binary"
  82. run: |
  83. if [ "${{ matrix.operating-system.name }}" != "windows-x64" ]; then
  84. tar -czf ${{ matrix.operating-system.filename }} spc
  85. # validate spc binary
  86. if [ "${{ matrix.operating-system.name }}" == "linux-x86_64" ]; then
  87. ./spc dev:extensions
  88. fi
  89. fi
  90. - name: "Copy file"
  91. run: |
  92. if [ "${{ matrix.operating-system.name }}" != "windows-x64" ]; then
  93. mkdir dist/ && cp ${{ matrix.operating-system.filename }} dist/ && cp spc dist/spc-${{ matrix.operating-system.name }}
  94. else
  95. mkdir dist/ && cp spc.exe dist/${{ matrix.operating-system.filename }}
  96. echo "SUFFIX=.exe" >> $GITHUB_ENV
  97. fi
  98. - name: "Upload Binaries to Release"
  99. uses: softprops/action-gh-release@v1
  100. if: ${{startsWith(github.ref, 'refs/tags/') }}
  101. with:
  102. files: dist/${{ matrix.operating-system.filename }}
  103. - name: "Deploy to self-hosted OSS"
  104. if: github.repository == 'crazywhalecc/static-php-cli'
  105. uses: static-php/upload-s3-action@v1.0.0
  106. with:
  107. aws_key_id: ${{ secrets.AWS_KEY_ID }}
  108. aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  109. aws_bucket: ${{ secrets.AWS_BUCKET }}
  110. source_dir: "dist/"
  111. destination_dir: static-php-cli/spc-bin/nightly/
  112. endpoint: ${{ secrets.AWS_ENDPOINT }}
  113. - name: "Upload Artifact"
  114. uses: actions/upload-artifact@v4
  115. with:
  116. path: spc${{ env.SUFFIX }}
  117. name: spc-${{ matrix.operating-system.name }}${{ env.SUFFIX }}