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-0: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. - debian11
  176. - debian10
  177. - el9
  178. - el8
  179. - el7
  180. - amzn2
  181. build_machine:
  182. - aws-arm64
  183. - ubuntu-22.04
  184. builder:
  185. - 5.1-0
  186. elixir:
  187. - 1.14.5
  188. with_elixir:
  189. - 'no'
  190. exclude:
  191. - arch: arm64
  192. build_machine: ubuntu-22.04
  193. - arch: amd64
  194. build_machine: aws-arm64
  195. include:
  196. - profile: emqx
  197. otp: 25.3.2-1
  198. arch: amd64
  199. os: ubuntu22.04
  200. build_machine: ubuntu-22.04
  201. builder: 5.1-0
  202. elixir: 1.14.5
  203. with_elixir: 'yes'
  204. - profile: emqx
  205. otp: 25.3.2-1
  206. arch: amd64
  207. os: amzn2
  208. build_machine: ubuntu-22.04
  209. builder: 5.1-0
  210. elixir: 1.14.5
  211. with_elixir: 'yes'
  212. defaults:
  213. run:
  214. shell: bash
  215. steps:
  216. - uses: AutoModality/action-clean@v1
  217. if: matrix.build_machine == 'aws-arm64'
  218. - uses: actions/checkout@v3
  219. with:
  220. ref: ${{ github.event.inputs.branch_or_tag }}
  221. fetch-depth: 0
  222. - name: build emqx packages
  223. env:
  224. ELIXIR: ${{ matrix.elixir }}
  225. PROFILE: ${{ matrix.profile }}
  226. ARCH: ${{ matrix.arch }}
  227. run: |
  228. set -eu
  229. git config --global --add safe.directory "$GITHUB_WORKSPACE"
  230. # Align path for CMake caches
  231. if [ ! "$PWD" = "/emqx" ]; then
  232. ln -s $PWD /emqx
  233. cd /emqx
  234. fi
  235. echo "pwd is $PWD"
  236. PKGTYPES="tgz pkg"
  237. IS_ELIXIR=${{ matrix.with_elixir }}
  238. if [ "${IS_ELIXIR:-}" == 'yes' ]; then
  239. PKGTYPES="tgz"
  240. fi
  241. for PKGTYPE in ${PKGTYPES};
  242. do
  243. ./scripts/buildx.sh \
  244. --profile "${PROFILE}" \
  245. --pkgtype "${PKGTYPE}" \
  246. --arch "${ARCH}" \
  247. --elixir "${IS_ELIXIR}" \
  248. --builder "force_host"
  249. done
  250. - uses: actions/upload-artifact@v3
  251. if: success()
  252. with:
  253. name: ${{ matrix.profile }}
  254. path: _packages/${{ matrix.profile }}/
  255. publish_artifacts:
  256. runs-on: ubuntu-22.04
  257. needs: [prepare, mac, linux]
  258. if: needs.prepare.outputs.IS_EXACT_TAG == 'true'
  259. strategy:
  260. fail-fast: false
  261. matrix:
  262. profile:
  263. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  264. steps:
  265. - uses: actions/download-artifact@v3
  266. with:
  267. name: ${{ matrix.profile }}
  268. path: packages/${{ matrix.profile }}
  269. - name: install dos2unix
  270. run: sudo apt-get update && sudo apt install -y dos2unix
  271. - name: get packages
  272. run: |
  273. set -e -u
  274. cd packages/${{ matrix.profile }}
  275. # fix the .sha256 file format
  276. for var in $(ls | grep emqx | grep -v sha256); do
  277. dos2unix $var.sha256
  278. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  279. done
  280. cd -
  281. - uses: aws-actions/configure-aws-credentials@v2
  282. with:
  283. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  284. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  285. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  286. - name: upload to aws s3
  287. env:
  288. PROFILE: ${{ matrix.profile }}
  289. run: |
  290. set -e -u
  291. if [ $PROFILE = 'emqx' ]; then
  292. s3dir='emqx-ce'
  293. elif [ $PROFILE = 'emqx-enterprise' ]; then
  294. s3dir='emqx-ee'
  295. else
  296. echo "unknown profile $PROFILE"
  297. exit 1
  298. fi
  299. aws s3 cp --recursive packages/$PROFILE s3://${{ secrets.AWS_S3_BUCKET }}/$s3dir/${{ github.ref_name }}
  300. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$s3dir/${{ github.ref_name }}/*"