packaging.yml 10 KB

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