build_packages.yaml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. name: Cross build packages
  2. concurrency:
  3. group: build-${{ github.event_name }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. push:
  7. branches:
  8. - 'ci/**'
  9. tags:
  10. - v*
  11. - e*
  12. workflow_dispatch:
  13. inputs:
  14. branch_or_tag:
  15. required: false
  16. profile:
  17. required: false
  18. jobs:
  19. prepare:
  20. runs-on: ubuntu-22.04
  21. container: ghcr.io/emqx/emqx-builder/5.1-3:1.14.5-25.3.2-1-ubuntu22.04
  22. outputs:
  23. BUILD_PROFILE: ${{ steps.get_profile.outputs.BUILD_PROFILE }}
  24. IS_EXACT_TAG: ${{ steps.get_profile.outputs.IS_EXACT_TAG }}
  25. VERSION: ${{ steps.get_profile.outputs.VERSION }}
  26. steps:
  27. - uses: actions/checkout@v3
  28. with:
  29. ref: ${{ github.event.inputs.branch_or_tag }} # when input is not given, the event tag is used
  30. fetch-depth: 0
  31. - name: Get profile to build
  32. id: get_profile
  33. run: |
  34. git config --global --add safe.directory "$GITHUB_WORKSPACE"
  35. tag=${{ github.ref }}
  36. if git describe --tags --match "[v|e]*" --exact; then
  37. echo "WARN: This is an exact git tag, will publish release"
  38. is_exact_tag='true'
  39. else
  40. echo "WARN: This is NOT an exact git tag, will not publish release"
  41. is_exact_tag='false'
  42. fi
  43. echo "IS_EXACT_TAG=${is_exact_tag}" >> $GITHUB_OUTPUT
  44. case $tag in
  45. refs/tags/v*)
  46. PROFILE='emqx'
  47. ;;
  48. refs/tags/e*)
  49. PROFILE=emqx-enterprise
  50. ;;
  51. *)
  52. PROFILE=${{ github.event.inputs.profile }}
  53. case "$PROFILE" in
  54. emqx)
  55. true
  56. ;;
  57. emqx-enterprise)
  58. true
  59. ;;
  60. *)
  61. # maybe triggered from schedule
  62. echo "WARN: \"$PROFILE\" is not a valid profile."
  63. echo "building the default profile 'emqx' instead"
  64. PROFILE='emqx'
  65. ;;
  66. esac
  67. ;;
  68. esac
  69. echo "BUILD_PROFILE=$PROFILE" >> $GITHUB_OUTPUT
  70. echo "VERSION=$(./pkg-vsn.sh $PROFILE)" >> $GITHUB_OUTPUT
  71. windows:
  72. runs-on: windows-2019
  73. if: startsWith(github.ref_name, 'v')
  74. strategy:
  75. fail-fast: false
  76. matrix:
  77. profile: # for now only CE for windows
  78. - emqx
  79. steps:
  80. - uses: actions/checkout@v3
  81. with:
  82. ref: ${{ github.event.inputs.branch_or_tag }}
  83. fetch-depth: 0
  84. - uses: ilammy/msvc-dev-cmd@v1.12.0
  85. - uses: erlef/setup-beam@v1.15.4
  86. with:
  87. otp-version: 25.3.2
  88. - name: build
  89. env:
  90. PYTHON: python
  91. DIAGNOSTIC: 1
  92. run: |
  93. # ensure crypto app (openssl)
  94. erl -eval "erlang:display(crypto:info_lib())" -s init stop
  95. make ${{ matrix.profile }}-tgz
  96. - name: run emqx
  97. timeout-minutes: 5
  98. run: |
  99. $ErrorActionPreference = "Stop"
  100. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  101. Start-Sleep -s 10
  102. $pingOutput = ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx ping
  103. if ($pingOutput = 'pong') {
  104. echo "EMQX started OK"
  105. } else {
  106. echo "Failed to ping EMQX $pingOutput"
  107. Exit 1
  108. }
  109. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  110. echo "EMQX stopped"
  111. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  112. echo "EMQX installed"
  113. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  114. echo "EMQX uninstalled"
  115. - uses: actions/upload-artifact@v3
  116. if: success()
  117. with:
  118. name: ${{ matrix.profile }}
  119. path: _packages/${{ matrix.profile }}/
  120. mac:
  121. needs: prepare
  122. strategy:
  123. fail-fast: false
  124. matrix:
  125. profile:
  126. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  127. otp:
  128. - 25.3.2-1
  129. os:
  130. - macos-11
  131. - macos-12
  132. - macos-12-arm64
  133. runs-on: ${{ matrix.os }}
  134. steps:
  135. - uses: emqx/self-hosted-cleanup-action@v1.0.3
  136. - uses: actions/checkout@v3
  137. with:
  138. ref: ${{ github.event.inputs.branch_or_tag }}
  139. fetch-depth: 0
  140. - uses: ./.github/actions/package-macos
  141. with:
  142. profile: ${{ matrix.profile }}
  143. otp: ${{ matrix.otp }}
  144. os: ${{ matrix.os }}
  145. apple_id_password: ${{ secrets.APPLE_ID_PASSWORD }}
  146. apple_developer_identity: ${{ secrets.APPLE_DEVELOPER_IDENTITY }}
  147. apple_developer_id_bundle: ${{ secrets.APPLE_DEVELOPER_ID_BUNDLE }}
  148. apple_developer_id_bundle_password: ${{ secrets.APPLE_DEVELOPER_ID_BUNDLE_PASSWORD }}
  149. - uses: actions/upload-artifact@v3
  150. if: success()
  151. with:
  152. name: ${{ matrix.profile }}
  153. path: _packages/${{ matrix.profile }}/
  154. linux:
  155. needs: prepare
  156. runs-on: ${{ matrix.build_machine }}
  157. # always run in builder container because the host might have the wrong OTP version etc.
  158. # otherwise buildx.sh does not run docker if arch and os matches the target arch and os.
  159. container:
  160. image: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}"
  161. strategy:
  162. fail-fast: false
  163. matrix:
  164. profile:
  165. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  166. otp:
  167. - 25.3.2-1
  168. arch:
  169. - amd64
  170. - arm64
  171. os:
  172. - ubuntu22.04
  173. - ubuntu20.04
  174. - ubuntu18.04
  175. - debian12
  176. - debian11
  177. - debian10
  178. - el9
  179. - el8
  180. - el7
  181. - amzn2
  182. - amzn2023
  183. build_machine:
  184. - aws-arm64
  185. - aws-amd64
  186. builder:
  187. - 5.1-3
  188. elixir:
  189. - 1.14.5
  190. with_elixir:
  191. - 'no'
  192. exclude:
  193. - arch: arm64
  194. build_machine: aws-amd64
  195. - arch: amd64
  196. build_machine: aws-arm64
  197. include:
  198. - profile: emqx
  199. otp: 25.3.2-1
  200. arch: amd64
  201. os: ubuntu22.04
  202. build_machine: aws-amd64
  203. builder: 5.1-3
  204. elixir: 1.14.5
  205. with_elixir: 'yes'
  206. defaults:
  207. run:
  208. shell: bash
  209. steps:
  210. - uses: AutoModality/action-clean@v1
  211. - uses: actions/checkout@v3
  212. with:
  213. ref: ${{ github.event.inputs.branch_or_tag }}
  214. fetch-depth: 0
  215. - name: fix workdir
  216. run: |
  217. set -eu
  218. git config --global --add safe.directory "$GITHUB_WORKSPACE"
  219. # Align path for CMake caches
  220. if [ ! "$PWD" = "/emqx" ]; then
  221. ln -s $PWD /emqx
  222. cd /emqx
  223. fi
  224. echo "pwd is $PWD"
  225. - name: build emqx packages
  226. env:
  227. PROFILE: ${{ matrix.profile }}
  228. IS_ELIXIR: ${{ matrix.with_elixir }}
  229. ACLOCAL_PATH: "/usr/share/aclocal:/usr/local/share/aclocal"
  230. run: |
  231. set -eu
  232. if [ "${IS_ELIXIR:-}" == 'yes' ]; then
  233. make "${PROFILE}-elixir-tgz"
  234. else
  235. make "${PROFILE}-tgz"
  236. make "${PROFILE}-pkg"
  237. fi
  238. - name: test emqx packages
  239. env:
  240. PROFILE: ${{ matrix.profile }}
  241. IS_ELIXIR: ${{ matrix.with_elixir }}
  242. run: |
  243. set -eu
  244. if [ "${IS_ELIXIR:-}" == 'yes' ]; then
  245. ./scripts/pkg-tests.sh "${PROFILE}-elixir-tgz"
  246. else
  247. ./scripts/pkg-tests.sh "${PROFILE}-tgz"
  248. ./scripts/pkg-tests.sh "${PROFILE}-pkg"
  249. fi
  250. - uses: actions/upload-artifact@v3
  251. with:
  252. name: ${{ matrix.profile }}
  253. path: _packages/${{ matrix.profile }}/
  254. publish_artifacts:
  255. runs-on: ubuntu-22.04
  256. needs: [prepare, mac, linux]
  257. if: needs.prepare.outputs.IS_EXACT_TAG == 'true'
  258. strategy:
  259. fail-fast: false
  260. matrix:
  261. profile:
  262. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  263. steps:
  264. - uses: actions/download-artifact@v3
  265. with:
  266. name: ${{ matrix.profile }}
  267. path: packages/${{ matrix.profile }}
  268. - name: install dos2unix
  269. run: sudo apt-get update && sudo apt install -y dos2unix
  270. - name: get packages
  271. run: |
  272. set -e -u
  273. cd packages/${{ matrix.profile }}
  274. # fix the .sha256 file format
  275. for var in $(ls | grep emqx | grep -v sha256); do
  276. dos2unix $var.sha256
  277. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  278. done
  279. cd -
  280. - uses: aws-actions/configure-aws-credentials@v2
  281. with:
  282. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  283. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  284. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  285. - name: upload to aws s3
  286. env:
  287. PROFILE: ${{ matrix.profile }}
  288. run: |
  289. set -e -u
  290. if [ $PROFILE = 'emqx' ]; then
  291. s3dir='emqx-ce'
  292. elif [ $PROFILE = 'emqx-enterprise' ]; then
  293. s3dir='emqx-ee'
  294. else
  295. echo "unknown profile $PROFILE"
  296. exit 1
  297. fi
  298. aws s3 cp --recursive packages/$PROFILE s3://${{ secrets.AWS_S3_BUCKET }}/$s3dir/${{ github.ref_name }}
  299. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$s3dir/${{ github.ref_name }}/*"