build_packages.yaml 12 KB

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