build_packages.yaml 12 KB

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