build_packages.yaml 11 KB

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