build_packages.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. outputs:
  23. BUILD_PROFILE: ${{ steps.get_profile.outputs.BUILD_PROFILE }}
  24. IS_EXACT_TAG: ${{ steps.get_profile.outputs.IS_EXACT_TAG }}
  25. steps:
  26. - uses: actions/checkout@v2
  27. with:
  28. ref: ${{ github.event.inputs.branch_or_tag }} # when input is not given, the event tag is used
  29. path: source
  30. fetch-depth: 0
  31. - name: Get profile to build
  32. id: get_profile
  33. run: |
  34. cd source
  35. tag=${{ github.ref }}
  36. if git describe --tags --match "[v|e]*" --exact; then
  37. echo "This is an exact git tag, will publish release"
  38. is_exact='true'
  39. else
  40. echo "This is NOT an exact git tag, will not publish release"
  41. is_exact='false'
  42. fi
  43. echo "::set-output name=IS_EXACT_TAG::${is_exact}"
  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. echo "ERROR: Failed to resolve build profile"
  62. exit 1
  63. ;;
  64. esac
  65. ;;
  66. esac
  67. echo "::set-output name=BUILD_PROFILE::$PROFILE"
  68. - name: get_all_deps
  69. run: |
  70. make -C source deps-all
  71. zip -ryq source.zip source/* source/.[^.]*
  72. - uses: actions/upload-artifact@v2
  73. with:
  74. name: source
  75. path: source.zip
  76. windows:
  77. runs-on: windows-2019
  78. needs: prepare
  79. strategy:
  80. fail-fast: false
  81. matrix:
  82. profile: # for now only CE for windows
  83. - emqx
  84. otp:
  85. - 24.2.1
  86. steps:
  87. - uses: actions/download-artifact@v2
  88. with:
  89. name: source
  90. path: .
  91. - name: unzip source code
  92. run: Expand-Archive -Path source.zip -DestinationPath ./
  93. - uses: ilammy/msvc-dev-cmd@v1
  94. - uses: erlef/setup-beam@v1
  95. with:
  96. otp-version: ${{ matrix.otp }}
  97. - name: build
  98. env:
  99. PYTHON: python
  100. DIAGNOSTIC: 1
  101. working-directory: source
  102. run: |
  103. # ensure crypto app (openssl)
  104. erl -eval "erlang:display(crypto:info_lib())" -s init stop
  105. make ${{ matrix.profile }}-tgz
  106. - name: run emqx
  107. timeout-minutes: 5
  108. working-directory: source
  109. run: |
  110. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  111. Start-Sleep -s 5
  112. echo "EMQX started"
  113. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  114. echo "EMQX stopped"
  115. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  116. echo "EMQX installed"
  117. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  118. echo "EMQX uninstalled"
  119. - uses: actions/upload-artifact@v1
  120. with:
  121. name: ${{ matrix.profile }}-windows
  122. path: source/_packages/${{ matrix.profile }}/.
  123. mac:
  124. needs: prepare
  125. strategy:
  126. fail-fast: false
  127. matrix:
  128. profile:
  129. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  130. otp:
  131. - 24.2.1-1
  132. os:
  133. - macos-11
  134. - macos-10.15
  135. runs-on: ${{ matrix.os }}
  136. steps:
  137. - uses: actions/download-artifact@v2
  138. with:
  139. name: source
  140. path: .
  141. - name: unzip source code
  142. run: unzip -q source.zip
  143. - name: prepare
  144. run: |
  145. brew update
  146. brew install curl zip unzip kerl coreutils
  147. echo "/usr/local/opt/bison/bin" >> $GITHUB_PATH
  148. echo "/usr/local/bin" >> $GITHUB_PATH
  149. git config --global credential.helper store
  150. - uses: actions/cache@v2
  151. id: cache
  152. with:
  153. path: ~/.kerl/${{ matrix.otp }}
  154. key: otp-install-${{ matrix.otp }}-${{ matrix.os }}
  155. - name: build erlang
  156. if: steps.cache.outputs.cache-hit != 'true'
  157. timeout-minutes: 60
  158. env:
  159. KERL_BUILD_BACKEND: git
  160. OTP_GITHUB_URL: https://github.com/emqx/otp
  161. run: |
  162. kerl update releases
  163. kerl build ${{ matrix.otp }}
  164. kerl install ${{ matrix.otp }} $HOME/.kerl/${{ matrix.otp }}
  165. - name: build
  166. working-directory: source
  167. env:
  168. AUTO_INSTALL_BUILD_DEPS: 1
  169. run: |
  170. . $HOME/.kerl/${{ matrix.otp }}/activate
  171. make ensure-rebar3
  172. sudo cp rebar3 /usr/local/bin/rebar3
  173. rm -rf _build/${{ matrix.profile }}/lib
  174. make ${{ matrix.profile }}-tgz
  175. - name: test
  176. working-directory: source
  177. run: |
  178. pkg_name=$(find _packages/${{ matrix.profile }} -mindepth 1 -maxdepth 1 -iname \*.tar.gz)
  179. mkdir -p emqx
  180. tar -C emqx -zxf $pkg_name
  181. # gsed -i '/emqx_telemetry/d' ./emqx/data/loaded_plugins
  182. ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
  183. ready='no'
  184. for i in {1..10}; do
  185. if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then
  186. ready='yes'
  187. break
  188. fi
  189. sleep 1
  190. done
  191. if [ "$ready" != "yes" ]; then
  192. echo "Timed out waiting for emqx to be ready"
  193. cat emqx/log/erlang.log.1
  194. exit 1
  195. fi
  196. ./emqx/bin/emqx_ctl status
  197. ./emqx/bin/emqx stop
  198. rm -rf emqx
  199. - uses: actions/upload-artifact@v1
  200. with:
  201. name: ${{ matrix.profile }}-${{ matrix.otp }}
  202. path: source/_packages/${{ matrix.profile }}/.
  203. linux:
  204. needs: prepare
  205. runs-on: ${{ matrix.build_machine }}
  206. container:
  207. image: "ghcr.io/emqx/emqx-builder/5.0-16:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}"
  208. strategy:
  209. fail-fast: false
  210. matrix:
  211. profile:
  212. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  213. otp:
  214. - 24.2.1-1 # we test with OTP 23, but only build package on OTP 24 versions
  215. elixir:
  216. - 1.13.4
  217. # used to split elixir packages into a separate job, since the
  218. # entire job may take a lot of time, especially on arm64
  219. # emulation.
  220. # we only want to build ubuntu and centos with elixir for the
  221. # time being, so it's easier to just include those with
  222. # `with_elixir` set.
  223. build_elixir:
  224. # - with_elixir
  225. - no_elixir
  226. arch:
  227. - amd64
  228. - arm64
  229. os:
  230. - ubuntu20.04
  231. - ubuntu18.04
  232. - ubuntu16.04
  233. - debian11
  234. - debian10
  235. - debian9
  236. - el8
  237. - el7
  238. - raspbian10
  239. build_machine:
  240. - aws-arm64
  241. - ubuntu-20.04
  242. exclude:
  243. - arch: arm64
  244. build_machine: ubuntu-20.04
  245. - arch: amd64
  246. build_machine: aws-arm64
  247. - os: raspbian9
  248. arch: amd64
  249. - os: raspbian10
  250. arch: amd64
  251. - os: raspbian10 # we only have arm32 image
  252. arch: arm64
  253. - os: raspbian9
  254. profile: emqx
  255. - os: raspbian10
  256. profile: emqx
  257. - os: raspbian9
  258. profile: emqx-enterprise
  259. - os: raspbian10
  260. profile: emqx-enterprise
  261. include:
  262. - profile: emqx
  263. otp: 24.2.1-1
  264. elixir: 1.13.4
  265. build_elixir: with_elixir
  266. arch: amd64
  267. os: ubuntu20.04
  268. build_machine: ubuntu-20.04
  269. - profile: emqx
  270. otp: 24.2.1-1
  271. elixir: 1.13.4
  272. build_elixir: with_elixir
  273. arch: amd64
  274. os: el7
  275. build_machine: ubuntu-20.04
  276. defaults:
  277. run:
  278. shell: bash
  279. steps:
  280. - uses: AutoModality/action-clean@v1
  281. if: matrix.build_machine == 'aws-arm64'
  282. - uses: actions/download-artifact@v2
  283. with:
  284. name: source
  285. path: .
  286. - name: unzip source code
  287. run: unzip -q source.zip
  288. - name: build emqx packages
  289. working-directory: source
  290. env:
  291. OTP: ${{ matrix.otp }}
  292. ELIXIR: ${{ matrix.elixir }}
  293. PROFILE: ${{ matrix.profile }}
  294. ARCH: ${{ matrix.arch }}
  295. SYSTEM: ${{ matrix.os }}
  296. run: |
  297. set -eu
  298. git config --global --add safe.directory "/__w/emqx/emqx"
  299. # Align path for CMake caches
  300. if [ ! "$PWD" = "/emqx" ]; then
  301. ln -s $PWD /emqx
  302. cd /emqx
  303. fi
  304. echo "pwd is $PWD"
  305. PkgTypes="tgz pkg"
  306. IsElixir="no"
  307. if [ ${{ matrix.build_elixir }} = "with_elixir" ]; then
  308. PkgTypes="tgz"
  309. # set Elixir build flag
  310. IsElixir="yes"
  311. fi
  312. for PKGTYPE in ${PkgTypes};
  313. do
  314. ./scripts/buildx.sh \
  315. --profile "${PROFILE}" \
  316. --pkgtype "${PKGTYPE}" \
  317. --arch "${ARCH}" \
  318. --elixir "${IsElixir}" \
  319. --builder "ghcr.io/emqx/emqx-builder/5.0-16:${ELIXIR}-${OTP}-${SYSTEM}"
  320. done
  321. - uses: actions/upload-artifact@v1
  322. with:
  323. name: ${{ matrix.profile }}-${{ matrix.otp }}
  324. path: source/_packages/${{ matrix.profile }}/.
  325. publish_artifacts:
  326. runs-on: ubuntu-20.04
  327. needs: [prepare, mac, linux, docker]
  328. if: ${{ needs.prepare.outputs.IS_EXACT_TAG }}
  329. strategy:
  330. fail-fast: false
  331. matrix:
  332. profile:
  333. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  334. otp:
  335. - 24.2.1-1
  336. include:
  337. - profile: emqx
  338. otp: windows # otp version on windows is rather fixed
  339. steps:
  340. - uses: actions/download-artifact@v2
  341. with:
  342. name: ${{ matrix.profile }}-${{ matrix.otp }}
  343. path: packages/${{ matrix.profile }}
  344. - name: install dos2unix
  345. run: sudo apt-get update && sudo apt install -y dos2unix
  346. - name: get packages
  347. run: |
  348. set -e -u
  349. cd packages/${{ matrix.profile }}
  350. for var in $( ls |grep emqx |grep -v sha256); do
  351. dos2unix $var.sha256
  352. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  353. done
  354. cd -
  355. - uses: aws-actions/configure-aws-credentials@v1
  356. with:
  357. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  358. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  359. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  360. - name: upload to aws s3
  361. env:
  362. PROFILE: ${{ matrix.profile }}
  363. run: |
  364. set -e -u
  365. if [ $PROFILE = 'emqx' ]; then
  366. s3dir='emqx-ce'
  367. elif [ $PROFILE = 'emqx-enterprise' ]; then
  368. s3dir='emqx-ee'
  369. else
  370. echo "unknown profile $PROFILE"
  371. exit 1
  372. fi
  373. aws s3 cp --recursive packages/$PROFILE s3://${{ secrets.AWS_S3_BUCKET }}/$s3dir/${{ github.ref_name }}
  374. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$s3dir/${{ github.ref_name }}/*"