packaging.yml 13 KB

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