packaging.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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: check-files
  44. uses: tj-actions/changed-files@v42
  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. **/*.patch
  54. **/*.cmake
  55. netdata.spec.in
  56. contrib/debian/
  57. CMakeLists.txt
  58. .github/data/distros.yml
  59. .github/workflows/packaging.yml
  60. .github/scripts/gen-matrix-packaging.py
  61. .github/scripts/pkg-test.sh
  62. packaging/*.sh
  63. packaging/*.version
  64. packaging/*.checksums
  65. src/aclk/aclk-schemas/
  66. src/ml/dlib/
  67. src/fluent-bit/
  68. src/web/server/h2o/libh2o/
  69. files_ignore: |
  70. **/*.md
  71. - name: List all changed files in pattern
  72. continue-on-error: true
  73. env:
  74. ALL_CHANGED_FILES: ${{ steps.check-files.outputs.all_changed_files }}
  75. run: |
  76. for file in ${ALL_CHANGED_FILES}; do
  77. echo "$file was changed"
  78. done
  79. - name: Check Run
  80. id: check-run
  81. run: |
  82. if [ "${{ steps.check-files.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  83. echo 'run=true' >> "${GITHUB_OUTPUT}"
  84. else
  85. echo 'run=false' >> "${GITHUB_OUTPUT}"
  86. fi
  87. matrix:
  88. name: Prepare Build Matrix
  89. runs-on: ubuntu-latest
  90. outputs:
  91. matrix: ${{ steps.set-matrix.outputs.matrix }}
  92. steps:
  93. - name: Checkout
  94. id: checkout
  95. uses: actions/checkout@v4
  96. - name: Prepare tools
  97. id: prepare
  98. run: |
  99. sudo apt-get update && sudo apt-get install -y python3-ruamel.yaml
  100. - name: Read build matrix
  101. id: set-matrix
  102. run: |
  103. if [ "${{ github.event_name }}" = "pull_request" ] && \
  104. [ "${{ !contains(github.event.pull_request.labels.*.name, 'run-ci/packaging') }}" = "true" ]; then
  105. matrix="$(.github/scripts/gen-matrix-packaging.py 1)"
  106. else
  107. matrix="$(.github/scripts/gen-matrix-packaging.py 0)"
  108. fi
  109. echo "Generated matrix: ${matrix}"
  110. echo "matrix=${matrix}" >> "${GITHUB_OUTPUT}"
  111. - name: Failure Notification
  112. uses: rtCamp/action-slack-notify@v2
  113. env:
  114. SLACK_COLOR: 'danger'
  115. SLACK_ICON_EMOJI: ':github-actions:'
  116. SLACK_TITLE: 'Package Build matrix generation failed:'
  117. SLACK_USERNAME: 'GitHub Actions'
  118. SLACK_MESSAGE: |-
  119. ${{ github.repository }}: Failed to generate build matrix for package build.
  120. Checkout: ${{ steps.checkout.outcome }}
  121. Prepare Tools: ${{ steps.prepare.outcome }}
  122. Read Build Matrix: ${{ steps.set-matrix.outcome }}
  123. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  124. if: >-
  125. ${{
  126. failure()
  127. && github.event_name != 'pull_request'
  128. && startsWith(github.ref, 'refs/heads/master')
  129. && github.repository == 'netdata/netdata'
  130. }}
  131. version-check:
  132. name: Version check
  133. runs-on: ubuntu-latest
  134. outputs:
  135. repo: ${{ steps.check-version.outputs.repo }}
  136. version: ${{ steps.check-version.outputs.version }}
  137. retention: ${{ steps.check-version.outputs.retention }}
  138. steps:
  139. - name: Checkout
  140. id: checkout
  141. uses: actions/checkout@v4
  142. - name: Check Version
  143. id: check-version
  144. run: |
  145. if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  146. case "${{ github.event.inputs.type }}" in
  147. "release")
  148. echo "repo=${REPO_PREFIX}" >> "${GITHUB_OUTPUT}"
  149. echo "version=${{ github.event.inputs.version }}" >> "${GITHUB_OUTPUT}"
  150. echo "retention=365" >> "${GITHUB_OUTPUT}"
  151. ;;
  152. "nightly")
  153. echo "repo=${REPO_PREFIX}-edge" >> "${GITHUB_OUTPUT}"
  154. echo "version=$(tr -d 'v' < packaging/version)" >> "${GITHUB_OUTPUT}"
  155. echo "retention=30" >> "${GITHUB_OUTPUT}"
  156. ;;
  157. *)
  158. echo "repo=${REPO_PREFIX}-devel" >> "${GITHUB_OUTPUT}"
  159. echo "version=0.${GITHUB_SHA}" >> "${GITHUB_OUTPUT}"
  160. echo "retention=30" >> "${GITHUB_OUTPUT}"
  161. ;;
  162. esac
  163. else
  164. echo "version=$(cut -d'-' -f 1 packaging/version | tr -d 'v')" >> "${GITHUB_OUTPUT}"
  165. echo "retention=0" >> "${GITHUB_OUTPUT}"
  166. fi
  167. - name: Failure Notification
  168. uses: rtCamp/action-slack-notify@v2
  169. env:
  170. SLACK_COLOR: 'danger'
  171. SLACK_ICON_EMOJI: ':github-actions:'
  172. SLACK_TITLE: 'Package Build version check failed:'
  173. SLACK_USERNAME: 'GitHub Actions'
  174. SLACK_MESSAGE: |-
  175. ${{ github.repository }}: Failed to generate version information for package build.
  176. Checkout: ${{ steps.checkout.outcome }}
  177. Check Version: ${{ steps.check-version.outcome }}
  178. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  179. if: >-
  180. ${{
  181. failure()
  182. && github.event_name != 'pull_request'
  183. && startsWith(github.ref, 'refs/heads/master')
  184. && github.repository == 'netdata/netdata'
  185. }}
  186. build:
  187. name: Build
  188. runs-on: ubuntu-latest
  189. env:
  190. DOCKER_CLI_EXPERIMENTAL: enabled
  191. needs:
  192. - matrix
  193. - version-check
  194. - file-check
  195. strategy:
  196. matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
  197. # We intentiaonally disable the fail-fast behavior so that a
  198. # build failure for one version doesn't prevent us from publishing
  199. # successfully built and tested packages for another version.
  200. fail-fast: false
  201. max-parallel: 8
  202. steps:
  203. - name: Skip Check
  204. id: skip
  205. if: needs.file-check.outputs.run != 'true'
  206. run: echo "SKIPPED"
  207. - name: Checkout
  208. id: checkout
  209. if: needs.file-check.outputs.run == 'true'
  210. uses: actions/checkout@v4
  211. with:
  212. fetch-depth: 0 # We need full history for versioning
  213. submodules: recursive
  214. - name: Set Sentry telemetry env vars
  215. id: set-telemetry-env-vars
  216. run: |
  217. if [ "${{ github.repository }}" = 'netdata/netdata' ] && \
  218. [ "${{ matrix.bundle_sentry }}" = 'true' ] && \
  219. [ "${{ github.event_name }}" = 'workflow_dispatch' ]; then
  220. echo "RELEASE_PIPELINE=Production" >> "${GITHUB_ENV}"
  221. echo "UPLOAD_SENTRY=true" >> "${GITHUB_ENV}"
  222. else
  223. echo "RELEASE_PIPELINE=Unknown" >> "${GITHUB_ENV}"
  224. echo "UPLOAD_SENTRY=false" >> "${GITHUB_ENV}"
  225. fi
  226. - name: Setup QEMU
  227. id: qemu
  228. if: matrix.platform != 'linux/amd64' && matrix.platform != 'linux/i386' && needs.file-check.outputs.run == 'true'
  229. uses: docker/setup-qemu-action@v3
  230. - name: Prepare Docker Environment
  231. id: docker-config
  232. if: needs.file-check.outputs.run == 'true'
  233. shell: bash
  234. run: |
  235. echo '{"cgroup-parent": "actions-job.slice", "experimental": true}' | sudo tee /etc/docker/daemon.json 2>/dev/null
  236. sudo service docker restart
  237. - name: Fetch images
  238. id: fetch-images
  239. if: needs.file-check.outputs.run == 'true'
  240. uses: nick-invision/retry@v3
  241. with:
  242. max_attempts: 3
  243. retry_wait_seconds: 30
  244. timeout_seconds: 900
  245. command: |
  246. docker pull --platform ${{ matrix.platform }} ${{ matrix.base_image }}
  247. docker pull --platform ${{ matrix.platform }} netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-v1
  248. - name: Build Packages
  249. id: build
  250. if: needs.file-check.outputs.run == 'true'
  251. shell: bash
  252. run: |
  253. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e VERSION=${{ needs.version-check.outputs.version }} \
  254. -e ENABLE_SENTRY=${{ matrix.bundle_sentry }} -e RELEASE_PIPELINE=${{ env.RELEASE_PIPELINE }} \
  255. -e BUILD_DESTINATION=${{ matrix.distro }}${{ matrix.version }}_${{ matrix.arch }} -e UPLOAD_SENTRY=${{ env.UPLOAD_SENTRY }} \
  256. -e SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_CLI_TOKEN }} -e NETDATA_SENTRY_DSN=${{ secrets.SENTRY_DSN }} \
  257. --platform=${{ matrix.platform }} -v "$PWD":/netdata netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-v1
  258. - name: Save Packages
  259. id: artifacts
  260. if: needs.file-check.outputs.run == 'true'
  261. continue-on-error: true
  262. uses: actions/upload-artifact@v4
  263. with:
  264. name: ${{ matrix.distro }}-${{ matrix.version }}-${{ matrix.arch }}-packages
  265. path: ${{ github.workspace }}/artifacts/*
  266. - name: Test Packages
  267. id: test
  268. if: needs.file-check.outputs.run == 'true'
  269. shell: bash
  270. run: |
  271. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e DISTRO=${{ matrix.distro }} \
  272. -e VERSION=${{ needs.version-check.outputs.version }} -e DISTRO_VERSION=${{ matrix.version }} \
  273. --platform=${{ matrix.platform }} -v "$PWD":/netdata ${{ matrix.base_image }} \
  274. /netdata/.github/scripts/pkg-test.sh
  275. - name: Upload to PackageCloud
  276. id: upload
  277. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  278. continue-on-error: true
  279. shell: bash
  280. env:
  281. PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
  282. run: |
  283. printf "Packages to upload:\n%s" "$(ls artifacts/*.${{ matrix.format }})"
  284. for pkgfile in artifacts/*.${{ matrix.format }} ; do
  285. .github/scripts/package_cloud_wrapper.sh yank ${{ needs.version-check.outputs.repo }}/${{ matrix.repo_distro }} \
  286. "$(basename "${pkgfile}")" || true
  287. .github/scripts/package_cloud_wrapper.sh push ${{ needs.version-check.outputs.repo }}/${{ matrix.repo_distro }} "${pkgfile}"
  288. done
  289. - name: SSH setup
  290. id: ssh-setup
  291. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  292. uses: shimataro/ssh-key-action@v2
  293. with:
  294. key: ${{ secrets.NETDATABOT_PACKAGES_SSH_KEY }}
  295. name: id_ecdsa
  296. known_hosts: ${{ secrets.PACKAGES_KNOWN_HOSTS }}
  297. - name: Upload to packages.netdata.cloud
  298. id: package-upload
  299. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  300. run: |
  301. .github/scripts/package-upload.sh \
  302. ${{ matrix.repo_distro }} \
  303. ${{ matrix.arch }} \
  304. ${{ matrix.format }} \
  305. ${{ needs.version-check.outputs.repo }}
  306. - name: Failure Notification
  307. uses: rtCamp/action-slack-notify@v2
  308. env:
  309. SLACK_COLOR: 'danger'
  310. SLACK_ICON_EMOJI: ':github-actions:'
  311. SLACK_TITLE: 'Package Build failed:'
  312. SLACK_USERNAME: 'GitHub Actions'
  313. SLACK_MESSAGE: |-
  314. ${{ github.repository }}: ${{ matrix.repo_distro }} ${{ matrix.version }} package build for ${{ matrix.arch }} failed.
  315. Checkout: ${{ steps.checkout.outcome }}
  316. Setup QEMU: ${{ steps.qemu.outcome }}
  317. Setup Docker: ${{ steps.docker-config.outcome }}
  318. Fetch images: ${{ steps.fetch-images.outcome }}
  319. Build: ${{ steps.build.outcome }}
  320. Test: ${{ steps.test.outcome }}
  321. Publish to PackageCloud: ${{ steps.upload.outcome }}
  322. Import SSH Key: ${{ steps.ssh-setup.outcome }}
  323. Publish to packages.netdata.cloud: ${{ steps.package-upload.outcome }}
  324. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  325. if: >-
  326. ${{
  327. failure()
  328. && github.event_name != 'pull_request'
  329. && startsWith(github.ref, 'refs/heads/master')
  330. && github.repository == 'netdata/netdata'
  331. && needs.file-check.outputs.run == 'true'
  332. }}