static.yaml 4.5 KB

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