build_packages.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. 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.2
  86. with:
  87. otp-version: 24.3.4.6
  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. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx start
  100. Start-Sleep -s 5
  101. echo "EMQX started"
  102. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx stop
  103. echo "EMQX stopped"
  104. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx install
  105. echo "EMQX installed"
  106. ./_build/${{ matrix.profile }}/rel/emqx/bin/emqx uninstall
  107. echo "EMQX uninstalled"
  108. - uses: actions/upload-artifact@v3
  109. if: success()
  110. with:
  111. name: ${{ matrix.profile }}
  112. path: _packages/${{ matrix.profile }}/
  113. mac:
  114. needs: prepare
  115. strategy:
  116. fail-fast: false
  117. matrix:
  118. profile:
  119. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  120. otp:
  121. - 24.3.4.2-3
  122. os:
  123. - macos-11
  124. - macos-12
  125. - macos-12-arm64
  126. runs-on: ${{ matrix.os }}
  127. steps:
  128. - uses: emqx/self-hosted-cleanup-action@v1.0.3
  129. - uses: actions/checkout@v3
  130. with:
  131. ref: ${{ github.event.inputs.branch_or_tag }}
  132. fetch-depth: 0
  133. - uses: ./.github/actions/package-macos
  134. with:
  135. profile: ${{ matrix.profile }}
  136. otp: ${{ matrix.otp }}
  137. os: ${{ matrix.os }}
  138. apple_id_password: ${{ secrets.APPLE_ID_PASSWORD }}
  139. apple_developer_identity: ${{ secrets.APPLE_DEVELOPER_IDENTITY }}
  140. apple_developer_id_bundle: ${{ secrets.APPLE_DEVELOPER_ID_BUNDLE }}
  141. apple_developer_id_bundle_password: ${{ secrets.APPLE_DEVELOPER_ID_BUNDLE_PASSWORD }}
  142. - uses: actions/upload-artifact@v3
  143. if: success()
  144. with:
  145. name: ${{ matrix.profile }}
  146. path: _packages/${{ matrix.profile }}/
  147. linux:
  148. needs: prepare
  149. runs-on: ${{ matrix.build_machine }}
  150. # always run in builder container because the host might have the wrong OTP version etc.
  151. # otherwise buildx.sh does not run docker if arch and os matches the target arch and os.
  152. container:
  153. image: "ghcr.io/emqx/emqx-builder/${{ matrix.builder }}:${{ matrix.elixir }}-${{ matrix.otp }}-${{ matrix.os }}"
  154. strategy:
  155. fail-fast: false
  156. matrix:
  157. profile:
  158. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  159. otp:
  160. - 24.3.4.2-3
  161. arch:
  162. - amd64
  163. - arm64
  164. os:
  165. - ubuntu22.04
  166. - ubuntu20.04
  167. - ubuntu18.04
  168. - debian11
  169. - debian10
  170. - el9
  171. - el8
  172. - el7
  173. - amzn2
  174. build_machine:
  175. - aws-arm64
  176. - ubuntu-22.04
  177. builder:
  178. - 5.0-34
  179. elixir:
  180. - 1.13.4
  181. exclude:
  182. - arch: arm64
  183. build_machine: ubuntu-22.04
  184. - arch: amd64
  185. build_machine: aws-arm64
  186. include:
  187. - profile: emqx
  188. otp: 25.1.2-3
  189. arch: amd64
  190. os: ubuntu22.04
  191. build_machine: ubuntu-22.04
  192. builder: 5.0-34
  193. elixir: 1.13.4
  194. release_with: elixir
  195. - profile: emqx
  196. otp: 25.1.2-3
  197. arch: amd64
  198. os: amzn2
  199. build_machine: ubuntu-22.04
  200. builder: 5.0-34
  201. elixir: 1.13.4
  202. release_with: elixir
  203. defaults:
  204. run:
  205. shell: bash
  206. steps:
  207. - uses: AutoModality/action-clean@v1
  208. if: matrix.build_machine == 'aws-arm64'
  209. - uses: actions/checkout@v3
  210. with:
  211. ref: ${{ github.event.inputs.branch_or_tag }}
  212. fetch-depth: 0
  213. - name: build emqx packages
  214. env:
  215. ELIXIR: ${{ matrix.elixir }}
  216. PROFILE: ${{ matrix.profile }}
  217. ARCH: ${{ matrix.arch }}
  218. run: |
  219. set -eu
  220. git config --global --add safe.directory "$GITHUB_WORKSPACE"
  221. # Align path for CMake caches
  222. if [ ! "$PWD" = "/emqx" ]; then
  223. ln -s $PWD /emqx
  224. cd /emqx
  225. fi
  226. echo "pwd is $PWD"
  227. PKGTYPES="tgz pkg"
  228. IS_ELIXIR="no"
  229. WITH_ELIXIR=${{ matrix.release_with }}
  230. if [ "${WITH_ELIXIR:-}" == 'elixir' ]; then
  231. PKGTYPES="tgz"
  232. # set Elixir build flag
  233. IS_ELIXIR="yes"
  234. fi
  235. for PKGTYPE in ${PKGTYPES};
  236. do
  237. ./scripts/buildx.sh \
  238. --profile "${PROFILE}" \
  239. --pkgtype "${PKGTYPE}" \
  240. --arch "${ARCH}" \
  241. --elixir "${IS_ELIXIR}" \
  242. --builder "force_host"
  243. done
  244. - uses: actions/upload-artifact@v3
  245. if: success()
  246. with:
  247. name: ${{ matrix.profile }}
  248. path: _packages/${{ matrix.profile }}/
  249. publish_artifacts:
  250. runs-on: ubuntu-22.04
  251. needs: [prepare, mac, linux]
  252. if: needs.prepare.outputs.IS_EXACT_TAG == 'true'
  253. strategy:
  254. fail-fast: false
  255. matrix:
  256. profile:
  257. - ${{ needs.prepare.outputs.BUILD_PROFILE }}
  258. steps:
  259. - uses: actions/download-artifact@v3
  260. with:
  261. name: ${{ matrix.profile }}
  262. path: packages/${{ matrix.profile }}
  263. - name: install dos2unix
  264. run: sudo apt-get update && sudo apt install -y dos2unix
  265. - name: get packages
  266. run: |
  267. set -e -u
  268. cd packages/${{ matrix.profile }}
  269. # fix the .sha256 file format
  270. for var in $(ls | grep emqx | grep -v sha256); do
  271. dos2unix $var.sha256
  272. echo "$(cat $var.sha256) $var" | sha256sum -c || exit 1
  273. done
  274. cd -
  275. - uses: aws-actions/configure-aws-credentials@v2
  276. with:
  277. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
  278. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  279. aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
  280. - name: upload to aws s3
  281. env:
  282. PROFILE: ${{ matrix.profile }}
  283. run: |
  284. set -e -u
  285. if [ $PROFILE = 'emqx' ]; then
  286. s3dir='emqx-ce'
  287. elif [ $PROFILE = 'emqx-enterprise' ]; then
  288. s3dir='emqx-ee'
  289. else
  290. echo "unknown profile $PROFILE"
  291. exit 1
  292. fi
  293. aws s3 cp --recursive packages/$PROFILE s3://${{ secrets.AWS_S3_BUCKET }}/$s3dir/${{ github.ref_name }}
  294. aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/$s3dir/${{ github.ref_name }}/*"
  295. - name: Push to packagecloud.io
  296. env:
  297. PROFILE: ${{ matrix.profile }}
  298. VERSION: ${{ needs.prepare.outputs.VERSION }}
  299. PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }}
  300. run: |
  301. set -eu
  302. REPO=$PROFILE
  303. if [ $PROFILE = 'emqx-enterprise' ]; then
  304. REPO='emqx-enterprise5'
  305. fi
  306. function push() {
  307. 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
  308. }
  309. push "debian/buster" "packages/$PROFILE/$PROFILE-$VERSION-debian10-amd64.deb"
  310. push "debian/buster" "packages/$PROFILE/$PROFILE-$VERSION-debian10-arm64.deb"
  311. push "debian/bullseye" "packages/$PROFILE/$PROFILE-$VERSION-debian11-amd64.deb"
  312. push "debian/bullseye" "packages/$PROFILE/$PROFILE-$VERSION-debian11-arm64.deb"
  313. push "ubuntu/bionic" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu18.04-amd64.deb"
  314. push "ubuntu/bionic" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu18.04-arm64.deb"
  315. push "ubuntu/focal" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu20.04-amd64.deb"
  316. push "ubuntu/focal" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu20.04-arm64.deb"
  317. push "ubuntu/jammy" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu22.04-amd64.deb"
  318. push "ubuntu/jammy" "packages/$PROFILE/$PROFILE-$VERSION-ubuntu22.04-arm64.deb"
  319. push "el/6" "packages/$PROFILE/$PROFILE-$VERSION-amzn2-amd64.rpm"
  320. push "el/6" "packages/$PROFILE/$PROFILE-$VERSION-amzn2-arm64.rpm"
  321. push "el/7" "packages/$PROFILE/$PROFILE-$VERSION-el7-amd64.rpm"
  322. push "el/7" "packages/$PROFILE/$PROFILE-$VERSION-el7-arm64.rpm"
  323. push "el/8" "packages/$PROFILE/$PROFILE-$VERSION-el8-amd64.rpm"
  324. push "el/8" "packages/$PROFILE/$PROFILE-$VERSION-el8-arm64.rpm"
  325. push "el/9" "packages/$PROFILE/$PROFILE-$VERSION-el9-amd64.rpm"
  326. push "el/9" "packages/$PROFILE/$PROFILE-$VERSION-el9-arm64.rpm"