static.yaml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. schedule:
  15. - cron: '0 0 * * *'
  16. jobs:
  17. release:
  18. if: github.ref_type == 'tag'
  19. name: Create GitHub Release
  20. runs-on: ubuntu-latest
  21. steps:
  22. - name: Create release
  23. uses: ncipollo/release-action@v1
  24. with:
  25. generateReleaseNotes: true
  26. allowUpdates: true
  27. omitBodyDuringUpdate: true
  28. omitNameDuringUpdate: true
  29. prepare:
  30. runs-on: ubuntu-latest
  31. outputs:
  32. ref: ${{ steps.ref.outputs.ref }}
  33. steps:
  34. -
  35. name: Get latest release
  36. id: ref
  37. if: github.event_name == 'schedule'
  38. run: echo ref="$(gh release view --repo dunglas/frankenphp --json tagName --jq '.tagName')" >> "${GITHUB_OUTPUT}"
  39. build-linux:
  40. name: Build Linux x86_64 binary
  41. runs-on: ubuntu-latest
  42. needs: [ prepare ]
  43. steps:
  44. -
  45. uses: actions/checkout@v4
  46. with:
  47. ref: ${{ needs.prepare.outputs.ref }}
  48. -
  49. name: Set up Docker Buildx
  50. uses: docker/setup-buildx-action@v3
  51. with:
  52. version: latest
  53. -
  54. name: Login to DockerHub
  55. if: github.event_name == 'schedule' || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
  56. uses: docker/login-action@v3
  57. with:
  58. username: ${{secrets.REGISTRY_USERNAME}}
  59. password: ${{secrets.REGISTRY_PASSWORD}}
  60. -
  61. name: Build
  62. id: build
  63. uses: docker/bake-action@v4
  64. with:
  65. pull: true
  66. load: ${{toJson(github.event_name != 'schedule' && !startsWith(github.ref, 'refs/tags/') && (github.ref != 'refs/heads/main' || github.event_name == 'pull_request'))}}
  67. push: ${{toJson(github.event_name == 'schedule' || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request'))}}
  68. targets: static-builder
  69. set: |
  70. *.cache-from=type=gha,scope=${{github.ref}}-static-builder
  71. *.cache-from=type=gha,scope=refs/heads/main-static-builder
  72. *.cache-to=type=gha,scope=${{github.ref}}-static-builder
  73. env:
  74. LATEST: '1' # TODO: unset this variable when releasing the first stable version
  75. SHA: ${{github.sha}}
  76. VERSION: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref || github.sha}}
  77. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  78. -
  79. name: Pull Docker image
  80. if: github.event_name == 'schedule' || startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && github.event_name != 'pull_request')
  81. run: docker pull dunglas/frankenphp:static-builder
  82. -
  83. name: Copy binary
  84. 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
  85. -
  86. name: Upload asset
  87. if: github.event_name == 'schedule' || github.ref_type == 'tag'
  88. uses: ncipollo/release-action@v1
  89. with:
  90. tag: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}
  91. generateReleaseNotes: true
  92. allowUpdates: true
  93. omitBodyDuringUpdate: true
  94. omitNameDuringUpdate: true
  95. artifacts: frankenphp-linux-x86_64
  96. replacesArtifacts: true
  97. -
  98. name: Upload artifact
  99. if: github.ref_type == 'branch'
  100. uses: actions/upload-artifact@v3
  101. with:
  102. path: frankenphp-linux-x86_64
  103. build-mac:
  104. name: Build macOS x86_64 binaries
  105. runs-on: macos-latest
  106. needs: [ prepare ]
  107. env:
  108. HOMEBREW_NO_AUTO_UPDATE: 1
  109. steps:
  110. -
  111. uses: actions/checkout@v4
  112. with:
  113. ref: ${{ needs.prepare.outputs.ref }}
  114. -
  115. uses: actions/setup-go@v5
  116. with:
  117. go-version: '1.21'
  118. cache-dependency-path: |
  119. go.sum
  120. caddy/go.sum
  121. -
  122. name: Set FRANKENPHP_VERSION
  123. run: |
  124. if [ "${GITHUB_REF_TYPE}" == "tag" ]; then
  125. export FRANKENPHP_VERSION=${GITHUB_REF_NAME:1}
  126. elif [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then
  127. export FRANKENPHP_VERSION="${{ needs.prepare.outputs.ref }}"
  128. else
  129. export FRANKENPHP_VERSION=${GITHUB_SHA}
  130. fi
  131. echo "FRANKENPHP_VERSION=${FRANKENPHP_VERSION}" >> "${GITHUB_ENV}"
  132. -
  133. name: Build FrankenPHP
  134. run: ./build-static.sh
  135. env:
  136. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  137. -
  138. name: Upload asset
  139. if: github.event_name == 'schedule' || github.ref_type == 'tag'
  140. uses: ncipollo/release-action@v1
  141. with:
  142. tag: ${{ (github.ref_type == 'tag' && github.ref_name) || needs.prepare.outputs.ref }}
  143. generateReleaseNotes: true
  144. allowUpdates: true
  145. omitBodyDuringUpdate: true
  146. omitNameDuringUpdate: true
  147. artifacts: dist/frankenphp-mac-x86_64
  148. replacesArtifacts: true
  149. -
  150. name: Upload artifact
  151. if: github.ref_type == 'branch'
  152. uses: actions/upload-artifact@v3
  153. with:
  154. path: dist/frankenphp-mac-x86_64