build_packages.yaml 11 KB

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