static.yaml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ---
  2. name: Build binary releases
  3. on:
  4. pull_request:
  5. branches:
  6. - main
  7. push:
  8. branches:
  9. - main
  10. tags:
  11. - v*.*.*
  12. workflow_dispatch:
  13. inputs:
  14. version:
  15. description: 'FrankenPHP version'
  16. required: false
  17. type: string
  18. schedule:
  19. - cron: '0 0 * * *'
  20. jobs:
  21. prepare:
  22. runs-on: ubuntu-latest
  23. outputs:
  24. ref: ${{ steps.ref.outputs.ref || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}
  25. steps:
  26. -
  27. name: Get latest release
  28. id: ref
  29. if: github.event_name == 'schedule'
  30. run: echo ref="$(gh release view --repo dunglas/frankenphp --json tagName --jq '.tagName')" >> "${GITHUB_OUTPUT}"
  31. env:
  32. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  33. build-linux:
  34. name: Build Linux x86_64 binary
  35. runs-on: ubuntu-latest
  36. needs: [ prepare ]
  37. steps:
  38. -
  39. uses: actions/checkout@v4
  40. with:
  41. ref: ${{ needs.prepare.outputs.ref }}
  42. -
  43. name: Set up Docker Buildx
  44. uses: docker/setup-buildx-action@v3
  45. with:
  46. version: latest
  47. -
  48. name: Login to DockerHub
  49. if: needs.prepare.outputs.ref || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
  50. uses: docker/login-action@v3
  51. with:
  52. username: ${{secrets.REGISTRY_USERNAME}}
  53. password: ${{secrets.REGISTRY_PASSWORD}}
  54. -
  55. name: Build
  56. id: build
  57. uses: docker/bake-action@v4
  58. with:
  59. pull: true
  60. load: ${{ (!needs.prepare.outputs.ref && !startsWith(github.ref, 'refs/tags/') && (github.ref != 'refs/heads/main' || github.event_name == 'pull_request')) && true || false }}
  61. push: ${{ (needs.prepare.outputs.ref || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) && true || false }}
  62. targets: static-builder
  63. set: |
  64. *.cache-from=type=gha,scope=${{needs.prepare.outputs.ref || github.ref}}-static-builder
  65. *.cache-from=type=gha,scope=refs/heads/main-static-builder
  66. *.cache-to=type=gha,scope=${{needs.prepare.outputs.ref || github.ref}}-static-builder,ignore-error=true
  67. env:
  68. SHA: ${{github.sha}}
  69. VERSION: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref || github.sha}}
  70. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  71. -
  72. name: Pull Docker image
  73. if: needs.prepare.outputs.ref || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
  74. run: docker pull dunglas/frankenphp:static-builder
  75. -
  76. name: Copy binary
  77. run: docker cp "$(docker create --name static-builder dunglas/frankenphp:static-builder):/go/src/app/dist/frankenphp-linux-x86_64" frankenphp-linux-x86_64 ; docker rm static-builder
  78. -
  79. name: Upload asset
  80. if: needs.prepare.outputs.ref || github.ref_type == 'tag'
  81. run: gh release upload "${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}" frankenphp-linux-x86_64 --repo dunglas/frankenphp --clobber
  82. env:
  83. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  84. -
  85. name: Upload artifact
  86. if: github.ref_type == 'branch'
  87. uses: actions/upload-artifact@v3
  88. with:
  89. name: frankenphp-linux-x86_64
  90. path: frankenphp-linux-x86_64
  91. build-mac:
  92. name: Build macOS x86_64 binaries
  93. runs-on: macos-latest
  94. needs: [ prepare ]
  95. env:
  96. HOMEBREW_NO_AUTO_UPDATE: 1
  97. steps:
  98. -
  99. uses: actions/checkout@v4
  100. with:
  101. ref: ${{ needs.prepare.outputs.ref }}
  102. -
  103. uses: actions/setup-go@v5
  104. with:
  105. go-version: '1.21'
  106. cache-dependency-path: |
  107. go.sum
  108. caddy/go.sum
  109. -
  110. name: Set FRANKENPHP_VERSION
  111. run: |
  112. if [ "${GITHUB_REF_TYPE}" == "tag" ]; then
  113. export FRANKENPHP_VERSION=${GITHUB_REF_NAME:1}
  114. elif [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then
  115. export FRANKENPHP_VERSION="${{ needs.prepare.outputs.ref }}"
  116. else
  117. export FRANKENPHP_VERSION=${GITHUB_SHA}
  118. fi
  119. echo "FRANKENPHP_VERSION=${FRANKENPHP_VERSION}" >> "${GITHUB_ENV}"
  120. -
  121. name: Build FrankenPHP
  122. run: ./build-static.sh
  123. env:
  124. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  125. RELEASE: ${{ (needs.prepare.outputs.ref || github.ref_type == 'tag') && '1' || '' }}
  126. -
  127. name: Upload artifact
  128. if: github.ref_type == 'branch'
  129. uses: actions/upload-artifact@v3
  130. with:
  131. name: frankenphp-mac-x86_64
  132. path: dist/frankenphp-mac-x86_64