build_packages.yaml 13 KB

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