static.yaml 12 KB

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