build_packages.yaml 12 KB

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