packaging.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. ---
  2. # Handles building of binary packages for the agent.
  3. name: Packages
  4. on:
  5. pull_request:
  6. types:
  7. - opened
  8. - reopened
  9. - labeled
  10. - synchronize
  11. push:
  12. branches:
  13. - master
  14. workflow_dispatch:
  15. inputs:
  16. type:
  17. description: Package build type
  18. default: devel
  19. required: true
  20. version:
  21. description: Package version
  22. required: false
  23. env:
  24. DISABLE_TELEMETRY: 1
  25. REPO_PREFIX: netdata/netdata
  26. concurrency:
  27. group: packages-${{ github.ref }}-${{ github.event_name }}
  28. cancel-in-progress: true
  29. jobs:
  30. file-check: # Check what files changed if we’re being run in a PR or on a push.
  31. name: Check Modified Files
  32. runs-on: ubuntu-latest
  33. outputs:
  34. run: ${{ steps.check-run.outputs.run }}
  35. steps:
  36. - name: Checkout
  37. id: checkout
  38. uses: actions/checkout@v4
  39. with:
  40. fetch-depth: 0
  41. submodules: recursive
  42. - name: Check files
  43. id: file-check
  44. uses: tj-actions/changed-files@v40
  45. with:
  46. since_last_remote_commit: ${{ github.event_name != 'pull_request' }}
  47. files: |
  48. **.c
  49. **.cc
  50. **.h
  51. **.hh
  52. **.in
  53. netdata.spec.in
  54. configure.ac
  55. **/Makefile*
  56. Makefile*
  57. .github/data/distros.yml
  58. .github/workflows/packaging.yml
  59. .github/scripts/gen-matrix-packaging.py
  60. .github/scripts/pkg-test.sh
  61. build/**
  62. packaging/*.sh
  63. packaging/*.checksums
  64. packaging/*.version
  65. contrib/debian/**
  66. aclk/aclk-schemas/
  67. ml/dlib/
  68. mqtt_websockets
  69. web/server/h2o/libh2o
  70. files_ignore: |
  71. **.md
  72. - name: Check Run
  73. id: check-run
  74. run: |
  75. if [ "${{ steps.file-check.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  76. echo 'run=true' >> "${GITHUB_OUTPUT}"
  77. else
  78. echo 'run=false' >> "${GITHUB_OUTPUT}"
  79. fi
  80. matrix:
  81. name: Prepare Build Matrix
  82. runs-on: ubuntu-latest
  83. outputs:
  84. matrix: ${{ steps.set-matrix.outputs.matrix }}
  85. steps:
  86. - name: Checkout
  87. id: checkout
  88. uses: actions/checkout@v4
  89. - name: Prepare tools
  90. id: prepare
  91. run: |
  92. sudo apt-get update && sudo apt-get install -y python3-ruamel.yaml
  93. - name: Read build matrix
  94. id: set-matrix
  95. run: |
  96. if [ "${{ github.event_name }}" = "pull_request" ] && \
  97. [ "${{ !contains(github.event.pull_request.labels.*.name, 'run-ci/packaging') }}" = "true" ]; then
  98. matrix="$(.github/scripts/gen-matrix-packaging.py 1)"
  99. else
  100. matrix="$(.github/scripts/gen-matrix-packaging.py 0)"
  101. fi
  102. echo "Generated matrix: ${matrix}"
  103. echo "matrix=${matrix}" >> "${GITHUB_OUTPUT}"
  104. - name: Failure Notification
  105. uses: rtCamp/action-slack-notify@v2
  106. env:
  107. SLACK_COLOR: 'danger'
  108. SLACK_ICON_EMOJI: ':github-actions:'
  109. SLACK_TITLE: 'Package Build matrix generation failed:'
  110. SLACK_USERNAME: 'GitHub Actions'
  111. SLACK_MESSAGE: |-
  112. ${{ github.repository }}: Failed to generate build matrix for package build.
  113. Checkout: ${{ steps.checkout.outcome }}
  114. Prepare Tools: ${{ steps.prepare.outcome }}
  115. Read Build Matrix: ${{ steps.set-matrix.outcome }}
  116. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  117. if: >-
  118. ${{
  119. failure()
  120. && github.event_name != 'pull_request'
  121. && startsWith(github.ref, 'refs/heads/master')
  122. && github.repository == 'netdata/netdata'
  123. }}
  124. version-check:
  125. name: Version check
  126. runs-on: ubuntu-latest
  127. outputs:
  128. repo: ${{ steps.check-version.outputs.repo }}
  129. version: ${{ steps.check-version.outputs.version }}
  130. retention: ${{ steps.check-version.outputs.retention }}
  131. steps:
  132. - name: Checkout
  133. id: checkout
  134. uses: actions/checkout@v4
  135. - name: Check Version
  136. id: check-version
  137. run: |
  138. if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  139. case "${{ github.event.inputs.type }}" in
  140. "release")
  141. echo "repo=${REPO_PREFIX}" >> "${GITHUB_OUTPUT}"
  142. echo "version=${{ github.event.inputs.version }}" >> "${GITHUB_OUTPUT}"
  143. echo "retention=365" >> "${GITHUB_OUTPUT}"
  144. ;;
  145. "nightly")
  146. echo "repo=${REPO_PREFIX}-edge" >> "${GITHUB_OUTPUT}"
  147. echo "version=$(tr -d 'v' < packaging/version)" >> "${GITHUB_OUTPUT}"
  148. echo "retention=30" >> "${GITHUB_OUTPUT}"
  149. ;;
  150. *)
  151. echo "repo=${REPO_PREFIX}-devel" >> "${GITHUB_OUTPUT}"
  152. echo "version=0.${GITHUB_SHA}" >> "${GITHUB_OUTPUT}"
  153. echo "retention=30" >> "${GITHUB_OUTPUT}"
  154. ;;
  155. esac
  156. else
  157. echo "version=$(cut -d'-' -f 1 packaging/version | tr -d 'v')" >> "${GITHUB_OUTPUT}"
  158. echo "retention=0" >> "${GITHUB_OUTPUT}"
  159. fi
  160. - name: Failure Notification
  161. uses: rtCamp/action-slack-notify@v2
  162. env:
  163. SLACK_COLOR: 'danger'
  164. SLACK_ICON_EMOJI: ':github-actions:'
  165. SLACK_TITLE: 'Package Build version check failed:'
  166. SLACK_USERNAME: 'GitHub Actions'
  167. SLACK_MESSAGE: |-
  168. ${{ github.repository }}: Failed to generate version information for package build.
  169. Checkout: ${{ steps.checkout.outcome }}
  170. Check Version: ${{ steps.check-version.outcome }}
  171. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  172. if: >-
  173. ${{
  174. failure()
  175. && github.event_name != 'pull_request'
  176. && startsWith(github.ref, 'refs/heads/master')
  177. && github.repository == 'netdata/netdata'
  178. }}
  179. build:
  180. name: Build
  181. runs-on: ubuntu-latest
  182. env:
  183. DOCKER_CLI_EXPERIMENTAL: enabled
  184. needs:
  185. - matrix
  186. - version-check
  187. - file-check
  188. strategy:
  189. matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
  190. # We intentiaonally disable the fail-fast behavior so that a
  191. # build failure for one version doesn't prevent us from publishing
  192. # successfully built and tested packages for another version.
  193. fail-fast: false
  194. max-parallel: 8
  195. steps:
  196. - name: Skip Check
  197. id: skip
  198. if: needs.file-check.outputs.run != 'true'
  199. run: echo "SKIPPED"
  200. - name: Checkout
  201. id: checkout
  202. if: needs.file-check.outputs.run == 'true'
  203. uses: actions/checkout@v4
  204. with:
  205. fetch-depth: 0 # We need full history for versioning
  206. submodules: recursive
  207. - name: Setup QEMU
  208. id: qemu
  209. if: matrix.platform != 'linux/amd64' && matrix.platform != 'linux/i386' && needs.file-check.outputs.run == 'true'
  210. uses: docker/setup-qemu-action@v3
  211. - name: Prepare Docker Environment
  212. id: docker-config
  213. if: needs.file-check.outputs.run == 'true'
  214. shell: bash
  215. run: |
  216. echo '{"cgroup-parent": "actions-job.slice", "experimental": true}' | sudo tee /etc/docker/daemon.json 2>/dev/null
  217. sudo service docker restart
  218. - name: Fetch images
  219. id: fetch-images
  220. if: needs.file-check.outputs.run == 'true'
  221. uses: nick-invision/retry@v2
  222. with:
  223. max_attempts: 3
  224. retry_wait_seconds: 30
  225. timeout_seconds: 900
  226. command: |
  227. docker pull --platform ${{ matrix.platform }} ${{ matrix.base_image }}
  228. docker pull --platform ${{ matrix.platform }} netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-v1
  229. - name: Build Packages
  230. id: build
  231. if: needs.file-check.outputs.run == 'true'
  232. shell: bash
  233. run: |
  234. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e VERSION=${{ needs.version-check.outputs.version }} \
  235. --platform=${{ matrix.platform }} -v "$PWD":/netdata netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-v1
  236. - name: Save Packages
  237. id: artifacts
  238. if: needs.file-check.outputs.run == 'true'
  239. continue-on-error: true
  240. uses: actions/upload-artifact@v3
  241. with:
  242. name: ${{ matrix.distro }}-${{ matrix.version }}-${{ matrix.arch }}-packages
  243. path: ${{ github.workspace }}/artifacts/*
  244. - name: Test Packages
  245. id: test
  246. if: needs.file-check.outputs.run == 'true'
  247. shell: bash
  248. run: |
  249. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e DISTRO=${{ matrix.distro }} \
  250. -e VERSION=${{ needs.version-check.outputs.version }} -e DISTRO_VERSION=${{ matrix.version }} \
  251. --platform=${{ matrix.platform }} -v "$PWD":/netdata ${{ matrix.base_image }} \
  252. /netdata/.github/scripts/pkg-test.sh
  253. - name: Upload to PackageCloud
  254. id: upload
  255. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  256. continue-on-error: true
  257. shell: bash
  258. env:
  259. PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
  260. run: |
  261. printf "Packages to upload:\n%s" "$(ls artifacts/*.${{ matrix.format }})"
  262. for pkgfile in artifacts/*.${{ matrix.format }} ; do
  263. .github/scripts/package_cloud_wrapper.sh yank ${{ needs.version-check.outputs.repo }}/${{ matrix.repo_distro }} \
  264. "$(basename "${pkgfile}")" || true
  265. .github/scripts/package_cloud_wrapper.sh push ${{ needs.version-check.outputs.repo }}/${{ matrix.repo_distro }} "${pkgfile}"
  266. done
  267. - name: SSH setup
  268. id: ssh-setup
  269. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  270. uses: shimataro/ssh-key-action@v2
  271. with:
  272. key: ${{ secrets.NETDATABOT_PACKAGES_SSH_KEY }}
  273. name: id_ecdsa
  274. known_hosts: ${{ secrets.PACKAGES_KNOWN_HOSTS }}
  275. - name: Upload to packages.netdata.cloud
  276. id: package-upload
  277. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  278. run: |
  279. .github/scripts/package-upload.sh \
  280. ${{ matrix.repo_distro }} \
  281. ${{ matrix.arch }} \
  282. ${{ matrix.format }} \
  283. ${{ needs.version-check.outputs.repo }}
  284. - name: Failure Notification
  285. uses: rtCamp/action-slack-notify@v2
  286. env:
  287. SLACK_COLOR: 'danger'
  288. SLACK_ICON_EMOJI: ':github-actions:'
  289. SLACK_TITLE: 'Package Build failed:'
  290. SLACK_USERNAME: 'GitHub Actions'
  291. SLACK_MESSAGE: |-
  292. ${{ github.repository }}: ${{ matrix.repo_distro }} ${{ matrix.version }} package build for ${{ matrix.arch }} failed.
  293. Checkout: ${{ steps.checkout.outcome }}
  294. Setup QEMU: ${{ steps.qemu.outcome }}
  295. Setup Docker: ${{ steps.docker-config.outcome }}
  296. Fetch images: ${{ steps.fetch-images.outcome }}
  297. Build: ${{ steps.build.outcome }}
  298. Test: ${{ steps.test.outcome }}
  299. Publish to PackageCloud: ${{ steps.upload.outcome }}
  300. Import SSH Key: ${{ steps.ssh-setup.outcome }}
  301. Publish to packages.netdata.cloud: ${{ steps.package-upload.outcome }}
  302. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  303. if: >-
  304. ${{
  305. failure()
  306. && github.event_name != 'pull_request'
  307. && startsWith(github.ref, 'refs/heads/master')
  308. && github.repository == 'netdata/netdata'
  309. && needs.file-check.outputs.run == 'true'
  310. }}