static.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ---
  2. name: Build binary releases
  3. concurrency:
  4. cancel-in-progress: true
  5. group: ${{ github.workflow }}-${{ github.ref }}
  6. on:
  7. pull_request:
  8. branches:
  9. - main
  10. paths-ignore:
  11. - 'docs/**'
  12. push:
  13. branches:
  14. - main
  15. tags:
  16. - v*.*.*
  17. workflow_dispatch:
  18. inputs:
  19. version:
  20. description: 'FrankenPHP version'
  21. required: false
  22. type: string
  23. schedule:
  24. - cron: '0 0 * * *'
  25. env:
  26. IMAGE_NAME: ${{ (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/')) && 'dunglas/frankenphp' || 'dunglas/frankenphp-dev' }}
  27. LATEST: ${{ (github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/')) && '0' || '1' }}
  28. jobs:
  29. prepare:
  30. runs-on: ubuntu-latest
  31. outputs:
  32. push: ${{ toJson((steps.check.outputs.ref || (github.event_name == 'workflow_dispatch' && inputs.version) || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')) && true || false) }}
  33. platforms: ${{ steps.matrix.outputs.platforms }}
  34. metadata: ${{ steps.matrix.outputs.metadata }}
  35. ref: ${{ steps.check.outputs.ref }}
  36. steps:
  37. -
  38. name: Get version
  39. id: check
  40. if: github.event_name == 'schedule'
  41. run: |
  42. ref="${{ (github.ref_type == 'tag' && github.ref_name) || (github.event_name == 'workflow_dispatch' && inputs.version) || '' }}"
  43. if [[ -z "${ref}" ]]; then
  44. ref="$(gh release view --repo dunglas/frankenphp --json tagName --jq '.tagName')"
  45. fi
  46. echo "ref=${ref}" >> "${GITHUB_OUTPUT}"
  47. env:
  48. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  49. -
  50. uses: actions/checkout@v4
  51. with:
  52. ref: ${{ steps.check.outputs.ref }}
  53. -
  54. name: Set up Docker Buildx
  55. uses: docker/setup-buildx-action@v3
  56. with:
  57. version: latest
  58. -
  59. name: Create platforms matrix
  60. id: matrix
  61. run: |
  62. METADATA="$(docker buildx bake --print static-builder | jq -c)"
  63. {
  64. echo metadata="${METADATA}"
  65. echo platforms="$(jq -c 'first(.target[]) | .platforms' <<< "${METADATA}")"
  66. } >> "${GITHUB_OUTPUT}"
  67. env:
  68. SHA: ${{ github.sha }}
  69. VERSION: ${{ steps.check.outputs.ref || github.sha }}
  70. build-linux:
  71. strategy:
  72. fail-fast: false
  73. matrix:
  74. platform: ${{ fromJson(needs.prepare.outputs.platforms) }}
  75. debug: [false]
  76. include:
  77. -
  78. qemu: true
  79. -
  80. platform: linux/amd64
  81. qemu: false
  82. -
  83. platform: linux/amd64
  84. qemu: false
  85. debug: true
  86. name: Build ${{ matrix.platform }} static binary${{ matrix.debug && ' (debug)' || '' }}
  87. runs-on: ubuntu-latest
  88. needs: [ prepare ]
  89. steps:
  90. -
  91. uses: actions/checkout@v4
  92. with:
  93. ref: ${{ needs.prepare.outputs.ref }}
  94. -
  95. name: Set up QEMU
  96. if: matrix.qemu
  97. uses: docker/setup-qemu-action@v3
  98. with:
  99. platforms: ${{ matrix.platform }}
  100. -
  101. name: Set up Docker Buildx
  102. uses: docker/setup-buildx-action@v3
  103. with:
  104. platforms: ${{ matrix.platform }}
  105. version: latest
  106. -
  107. name: Login to DockerHub
  108. if: ${{ fromJson(needs.prepare.outputs.push) && !matrix.debug }}
  109. uses: docker/login-action@v3
  110. with:
  111. username: ${{ secrets.REGISTRY_USERNAME }}
  112. password: ${{ secrets.REGISTRY_PASSWORD }}
  113. -
  114. name: Build
  115. id: build
  116. uses: docker/bake-action@v4
  117. with:
  118. pull: true
  119. load: ${{ !fromJson(needs.prepare.outputs.push) || matrix.debug }}
  120. targets: static-builder
  121. set: |
  122. ${{ matrix.debug && 'static-builder.args.DEBUG_SYMBOLS=1' || '' }}
  123. *.tags=
  124. *.platform=${{ matrix.platform }}
  125. *.cache-from=type=gha,scope=${{ needs.prepare.outputs.ref || github.ref }}-static-builder${{ matrix.debug && '-debug' && '' }}
  126. *.cache-from=type=gha,scope=refs/heads/main-static-builder${{ matrix.debug && '-debug' && '' }}
  127. *.cache-to=type=gha,scope=${{ needs.prepare.outputs.ref || github.ref }}-static-builder${{ matrix.debug && '-debug' && '' }},ignore-error=true
  128. ${{ (fromJson(needs.prepare.outputs.push) && !matrix.debug) && format('*.output=type=image,name={0},push-by-digest=true,name-canonical=true,push=true', env.IMAGE_NAME) || '' }}
  129. env:
  130. SHA: ${{ github.sha }}
  131. VERSION: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref || github.sha }}
  132. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  133. -
  134. # Workaround for https://github.com/actions/runner/pull/2477#issuecomment-1501003600
  135. name: Export metadata
  136. if: fromJson(needs.prepare.outputs.push) && !matrix.debug
  137. run: |
  138. mkdir -p /tmp/metadata
  139. # shellcheck disable=SC2086
  140. digest=$(jq -r '."static-builder"."containerimage.digest"' <<< ${METADATA})
  141. touch "/tmp/metadata/${digest#sha256:}"
  142. env:
  143. METADATA: ${{ steps.build.outputs.metadata }}
  144. -
  145. name: Upload metadata
  146. if: fromJson(needs.prepare.outputs.push) && !matrix.debug
  147. uses: actions/upload-artifact@v3
  148. with:
  149. name: metadata-static-builder
  150. path: /tmp/metadata/*
  151. if-no-files-found: error
  152. retention-days: 1
  153. -
  154. name: Copy binary
  155. if: ${{ !fromJson(needs.prepare.outputs.push) || matrix.debug }}
  156. run: |
  157. digest=$(jq -r '."static-builder"."containerimage.config.digest"' <<< "${METADATA}")
  158. docker create --platform=${{ matrix.platform }} --name static-builder "${digest}"
  159. docker cp "static-builder:/go/src/app/dist/${BINARY}" "${BINARY}${{ matrix.debug && '-debug' || '' }}"
  160. env:
  161. METADATA: ${{ steps.build.outputs.metadata }}
  162. BINARY: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}
  163. -
  164. name: Upload artifact
  165. if: ${{ !fromJson(needs.prepare.outputs.push) }}
  166. uses: actions/upload-artifact@v3
  167. with:
  168. name: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}${{ matrix.debug && '-debug' || '' }}
  169. path: frankenphp-linux-${{ matrix.platform == 'linux/amd64' && 'x86_64' || 'aarch64' }}${{ matrix.debug && '-debug' || '' }}
  170. -
  171. name: Upload debug asset
  172. if: fromJson(needs.prepare.outputs.push) && matrix.debug && (needs.prepare.outputs.ref || github.ref_type == 'tag')
  173. run: gh release upload "${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}" frankenphp-linux-x86_64-debug --repo dunglas/frankenphp --clobber
  174. env:
  175. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  176. # Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/
  177. push:
  178. runs-on: ubuntu-latest
  179. needs:
  180. - prepare
  181. - build-linux
  182. if: fromJson(needs.prepare.outputs.push)
  183. #if: fromJson(needs.prepare.outputs.push) && (needs.prepare.outputs.ref || github.ref_type == 'tag')
  184. steps:
  185. -
  186. name: Download metadata
  187. uses: actions/download-artifact@v3
  188. with:
  189. name: metadata-static-builder
  190. path: /tmp/metadata
  191. -
  192. name: Set up Docker Buildx
  193. uses: docker/setup-buildx-action@v3
  194. with:
  195. version: latest
  196. -
  197. name: Login to DockerHub
  198. uses: docker/login-action@v3
  199. with:
  200. username: ${{ secrets.REGISTRY_USERNAME }}
  201. password: ${{ secrets.REGISTRY_PASSWORD }}
  202. -
  203. name: Create manifest list and push
  204. working-directory: /tmp/metadata
  205. run: |
  206. # shellcheck disable=SC2046,SC2086
  207. docker buildx imagetools create $(jq -cr '.target."static-builder".tags | map("-t " + .) | join(" ")' <<< "${METADATA}") \
  208. $(printf "${IMAGE_NAME}@sha256:%s " *)
  209. env:
  210. METADATA: ${{ needs.prepare.outputs.metadata }}
  211. -
  212. name: Inspect image
  213. run: |
  214. # shellcheck disable=SC2046,SC2086
  215. docker buildx imagetools inspect "$(jq -cr '.target."static-builder".tags | first' <<< "${METADATA}")"
  216. env:
  217. METADATA: ${{ needs.prepare.outputs.metadata }}
  218. -
  219. name: Copy binary
  220. run: |
  221. tag=$(jq -cr '.target."static-builder".tags | first' <<< "${METADATA}")
  222. docker cp "$(docker create --platform=linux/amd64 --name static-builder "${tag}"):/go/src/app/dist/frankenphp-linux-x86_64" frankenphp-linux-x86_64 ; docker rm static-builder
  223. docker cp "$(docker create --platform=linux/arm64 --name static-builder "${tag}"):/go/src/app/dist/frankenphp-linux-aarch64" frankenphp-linux-aarch64 ; docker rm static-builder
  224. env:
  225. METADATA: ${{ needs.prepare.outputs.metadata }}
  226. -
  227. name: Upload asset
  228. if: needs.prepare.outputs.ref || github.ref_type == 'tag'
  229. run: gh release upload "${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}" frankenphp-linux-x86_64 frankenphp-linux-aarch64 --repo dunglas/frankenphp --clobber
  230. env:
  231. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  232. build-mac:
  233. strategy:
  234. fail-fast: false
  235. matrix:
  236. platform: ['arm64', 'x86_64']
  237. name: Build macOS ${{ matrix.platform }} binaries
  238. runs-on: ${{ matrix.platform == 'arm64' && 'macos-14' || 'macos-13' }}
  239. needs: [ prepare ]
  240. env:
  241. HOMEBREW_NO_AUTO_UPDATE: 1
  242. steps:
  243. -
  244. uses: actions/checkout@v4
  245. with:
  246. ref: ${{ needs.prepare.outputs.ref }}
  247. -
  248. uses: actions/setup-go@v5
  249. with:
  250. go-version: '1.22'
  251. cache-dependency-path: |
  252. go.sum
  253. caddy/go.sum
  254. -
  255. name: Set FRANKENPHP_VERSION
  256. run: |
  257. if [ "${GITHUB_REF_TYPE}" == "tag" ]; then
  258. export FRANKENPHP_VERSION=${GITHUB_REF_NAME:1}
  259. elif [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then
  260. export FRANKENPHP_VERSION="${{ needs.prepare.outputs.ref }}"
  261. else
  262. export FRANKENPHP_VERSION=${GITHUB_SHA}
  263. fi
  264. echo "FRANKENPHP_VERSION=${FRANKENPHP_VERSION}" >> "${GITHUB_ENV}"
  265. -
  266. name: Build FrankenPHP
  267. run: ./build-static.sh
  268. env:
  269. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  270. RELEASE: ${{ (needs.prepare.outputs.ref || github.ref_type == 'tag') && '1' || '' }}
  271. -
  272. name: Upload artifact
  273. if: github.ref_type == 'branch'
  274. uses: actions/upload-artifact@v3
  275. with:
  276. name: frankenphp-mac-${{ matrix.platform }}
  277. path: dist/frankenphp-mac-${{ matrix.platform }}