build_packages.yaml 10 KB

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