packaging.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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@v45
  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. CMakeLists.txt
  57. .github/data/distros.yml
  58. .github/workflows/packaging.yml
  59. .github/scripts/gen-matrix-packaging.py
  60. .github/scripts/pkg-test.sh
  61. packaging/cmake/
  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. packaging/repoconfig/
  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 || true
  101. sudo apt-get install -y python3-ruamel.yaml
  102. - name: Read build matrix
  103. id: set-matrix
  104. run: |
  105. if [ "${{ github.event_name }}" = "pull_request" ] && \
  106. [ "${{ !contains(github.event.pull_request.labels.*.name, 'run-ci/packaging') }}" = "true" ]; then
  107. matrix="$(.github/scripts/gen-matrix-packaging.py 1)"
  108. else
  109. matrix="$(.github/scripts/gen-matrix-packaging.py 0)"
  110. fi
  111. echo "Generated matrix: ${matrix}"
  112. echo "matrix=${matrix}" >> "${GITHUB_OUTPUT}"
  113. - name: Failure Notification
  114. uses: rtCamp/action-slack-notify@v2
  115. env:
  116. SLACK_COLOR: 'danger'
  117. SLACK_ICON_EMOJI: ':github-actions:'
  118. SLACK_TITLE: 'Package Build matrix generation failed:'
  119. SLACK_USERNAME: 'GitHub Actions'
  120. SLACK_MESSAGE: |-
  121. ${{ github.repository }}: Failed to generate build matrix for package build.
  122. Checkout: ${{ steps.checkout.outcome }}
  123. Prepare Tools: ${{ steps.prepare.outcome }}
  124. Read Build Matrix: ${{ steps.set-matrix.outcome }}
  125. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  126. if: >-
  127. ${{
  128. failure()
  129. && github.event_name != 'pull_request'
  130. && startsWith(github.ref, 'refs/heads/master')
  131. && github.repository == 'netdata/netdata'
  132. }}
  133. version-check:
  134. name: Version check
  135. runs-on: ubuntu-latest
  136. outputs:
  137. repo: ${{ steps.check-version.outputs.repo }}
  138. version: ${{ steps.check-version.outputs.version }}
  139. retention: ${{ steps.check-version.outputs.retention }}
  140. steps:
  141. - name: Checkout
  142. id: checkout
  143. uses: actions/checkout@v4
  144. - name: Check Version
  145. id: check-version
  146. run: |
  147. if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  148. case "${{ github.event.inputs.type }}" in
  149. "release")
  150. echo "repo=${REPO_PREFIX}" >> "${GITHUB_OUTPUT}"
  151. echo "version=${{ github.event.inputs.version }}" >> "${GITHUB_OUTPUT}"
  152. echo "retention=365" >> "${GITHUB_OUTPUT}"
  153. ;;
  154. "nightly")
  155. echo "repo=${REPO_PREFIX}-edge" >> "${GITHUB_OUTPUT}"
  156. echo "version=$(tr -d 'v' < packaging/version)" >> "${GITHUB_OUTPUT}"
  157. echo "retention=30" >> "${GITHUB_OUTPUT}"
  158. ;;
  159. *)
  160. echo "repo=${REPO_PREFIX}-devel" >> "${GITHUB_OUTPUT}"
  161. echo "version=0.${GITHUB_SHA}" >> "${GITHUB_OUTPUT}"
  162. echo "retention=30" >> "${GITHUB_OUTPUT}"
  163. ;;
  164. esac
  165. else
  166. echo "version=$(cut -d'-' -f 1 packaging/version | tr -d 'v')" >> "${GITHUB_OUTPUT}"
  167. echo "retention=0" >> "${GITHUB_OUTPUT}"
  168. fi
  169. - name: Failure Notification
  170. uses: rtCamp/action-slack-notify@v2
  171. env:
  172. SLACK_COLOR: 'danger'
  173. SLACK_ICON_EMOJI: ':github-actions:'
  174. SLACK_TITLE: 'Package Build version check failed:'
  175. SLACK_USERNAME: 'GitHub Actions'
  176. SLACK_MESSAGE: |-
  177. ${{ github.repository }}: Failed to generate version information for package build.
  178. Checkout: ${{ steps.checkout.outcome }}
  179. Check Version: ${{ steps.check-version.outcome }}
  180. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  181. if: >-
  182. ${{
  183. failure()
  184. && github.event_name != 'pull_request'
  185. && startsWith(github.ref, 'refs/heads/master')
  186. && github.repository == 'netdata/netdata'
  187. }}
  188. build:
  189. name: Build
  190. runs-on: ubuntu-latest
  191. env:
  192. DOCKER_CLI_EXPERIMENTAL: enabled
  193. needs:
  194. - matrix
  195. - version-check
  196. - file-check
  197. strategy:
  198. matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
  199. # We intentiaonally disable the fail-fast behavior so that a
  200. # build failure for one version doesn't prevent us from publishing
  201. # successfully built and tested packages for another version.
  202. fail-fast: false
  203. max-parallel: 8
  204. steps:
  205. - name: Skip Check
  206. id: skip
  207. if: needs.file-check.outputs.run != 'true'
  208. run: echo "SKIPPED"
  209. - name: Checkout
  210. id: checkout
  211. if: needs.file-check.outputs.run == 'true'
  212. uses: actions/checkout@v4
  213. with:
  214. fetch-depth: 0 # We need full history for versioning
  215. submodules: recursive
  216. - name: Set Sentry telemetry env vars
  217. id: set-telemetry-env-vars
  218. run: |
  219. if [ "${{ github.repository }}" = 'netdata/netdata' ] && \
  220. [ "${{ matrix.bundle_sentry }}" = 'true' ] && \
  221. [ "${{ github.event_name }}" = 'workflow_dispatch' ]; then
  222. echo "RELEASE_PIPELINE=Production" >> "${GITHUB_ENV}"
  223. echo "UPLOAD_SENTRY=true" >> "${GITHUB_ENV}"
  224. else
  225. echo "RELEASE_PIPELINE=Unknown" >> "${GITHUB_ENV}"
  226. echo "UPLOAD_SENTRY=false" >> "${GITHUB_ENV}"
  227. fi
  228. - name: Setup QEMU
  229. id: qemu
  230. if: matrix.platform != 'linux/amd64' && matrix.platform != 'linux/i386' && needs.file-check.outputs.run == 'true'
  231. uses: docker/setup-qemu-action@v3
  232. - name: Fetch images
  233. id: fetch-images
  234. if: needs.file-check.outputs.run == 'true'
  235. uses: nick-invision/retry@v3
  236. with:
  237. max_attempts: 3
  238. retry_wait_seconds: 30
  239. timeout_seconds: 900
  240. command: |
  241. docker pull --platform ${{ matrix.platform }} ${{ matrix.base_image }}
  242. docker pull --platform ${{ matrix.platform }} netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-${{ matrix.builder_rev }}
  243. - name: Build Packages
  244. id: build
  245. if: needs.file-check.outputs.run == 'true'
  246. shell: bash
  247. run: |
  248. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e VERSION=${{ needs.version-check.outputs.version }} \
  249. -e ENABLE_SENTRY=${{ matrix.bundle_sentry }} -e RELEASE_PIPELINE=${{ env.RELEASE_PIPELINE }} \
  250. -e BUILD_DESTINATION=${{ matrix.distro }}${{ matrix.version }}_${{ matrix.arch }} -e UPLOAD_SENTRY=${{ env.UPLOAD_SENTRY }} \
  251. -e SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_CLI_TOKEN }} -e NETDATA_SENTRY_DSN=${{ secrets.SENTRY_DSN }} \
  252. -e GOOS=$(echo ${{ matrix.platform }} | cut -f 1 -d '/') -e GOARCH=$(echo ${{ matrix.platform }} | cut -f 2 -d '/') \
  253. --platform=${{ matrix.platform }} -v "$PWD":/netdata netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-${{ matrix.builder_rev }}
  254. - name: Save Packages
  255. id: artifacts
  256. if: needs.file-check.outputs.run == 'true'
  257. continue-on-error: true
  258. uses: actions/upload-artifact@v4.4.2
  259. with:
  260. name: ${{ matrix.distro }}-${{ matrix.version }}-${{ matrix.arch }}-packages
  261. path: ${{ github.workspace }}/artifacts/*
  262. - name: Test Packages
  263. id: test
  264. if: needs.file-check.outputs.run == 'true'
  265. shell: bash
  266. run: |
  267. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e DISTRO=${{ matrix.distro }} \
  268. -e VERSION=${{ needs.version-check.outputs.version }} -e DISTRO_VERSION=${{ matrix.version }} \
  269. --platform=${{ matrix.platform }} -v "$PWD":/netdata ${{ matrix.base_image }} \
  270. /netdata/.github/scripts/pkg-test.sh
  271. - name: SSH setup
  272. id: ssh-setup
  273. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  274. uses: shimataro/ssh-key-action@v2
  275. with:
  276. key: ${{ secrets.NETDATABOT_PACKAGES_SSH_KEY }}
  277. name: id_ecdsa
  278. known_hosts: ${{ secrets.PACKAGES_KNOWN_HOSTS }}
  279. - name: Import GPG Keys
  280. id: import-keys
  281. if: needs.file-check.outputs.run == 'true' && matrix.format == 'deb' && github.event_name != 'pull_request'
  282. uses: crazy-max/ghaction-import-gpg@v6
  283. with:
  284. gpg_private_key: ${{ secrets.NETDATABOT_PACKAGE_SIGNING_KEY }}
  285. - name: Sign DEB Packages
  286. id: sign-deb
  287. if: needs.file-check.outputs.run == 'true' && matrix.format == 'deb' && github.event_name != 'pull_request'
  288. shell: bash
  289. run: .github/scripts/deb-sign.sh artifacts ${{ steps.import-keys.outputs.fingerprint }}
  290. - name: Upload to packages.netdata.cloud
  291. id: package-upload
  292. continue-on-error: true
  293. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  294. run: |
  295. .github/scripts/package-upload.sh \
  296. packages.netdata.cloud \
  297. ${{ matrix.repo_distro }} \
  298. ${{ matrix.arch }} \
  299. ${{ matrix.format }} \
  300. ${{ needs.version-check.outputs.repo }}
  301. - name: Upload to packages2.netdata.cloud
  302. id: package2-upload
  303. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  304. run: |
  305. .github/scripts/package-upload.sh \
  306. packages2.netdata.cloud \
  307. ${{ matrix.repo_distro }} \
  308. ${{ matrix.arch }} \
  309. ${{ matrix.format }} \
  310. ${{ needs.version-check.outputs.repo }}
  311. - name: Failure Notification
  312. uses: rtCamp/action-slack-notify@v2
  313. env:
  314. SLACK_COLOR: 'danger'
  315. SLACK_ICON_EMOJI: ':github-actions:'
  316. SLACK_TITLE: 'Package Build failed:'
  317. SLACK_USERNAME: 'GitHub Actions'
  318. SLACK_MESSAGE: |-
  319. ${{ github.repository }}: ${{ matrix.repo_distro }} ${{ matrix.version }} package build for ${{ matrix.arch }} failed.
  320. Checkout: ${{ steps.checkout.outcome }}
  321. Setup QEMU: ${{ steps.qemu.outcome }}
  322. Setup Docker: ${{ steps.docker-config.outcome }}
  323. Fetch images: ${{ steps.fetch-images.outcome }}
  324. Build: ${{ steps.build.outcome }}
  325. Test: ${{ steps.test.outcome }}
  326. Publish to PackageCloud: ${{ steps.upload.outcome }}
  327. Import SSH Key: ${{ steps.ssh-setup.outcome }}
  328. Publish to packages.netdata.cloud: ${{ steps.package-upload.outcome }}
  329. Import GPG Keys: ${{ steps.import-keys.outcome }}
  330. Sign DEB Packages: ${{ steps.sign-deb.outcome }}
  331. Publish to packages2.netdata.cloud: ${{ steps.package2-upload.outcome }}
  332. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  333. if: >-
  334. ${{
  335. failure()
  336. && github.event_name != 'pull_request'
  337. && startsWith(github.ref, 'refs/heads/master')
  338. && github.repository == 'netdata/netdata'
  339. && needs.file-check.outputs.run == 'true'
  340. }}