packaging.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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: ${{ matrix.runner }}
  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.qemu && needs.file-check.outputs.run == 'true'
  231. run: |
  232. sudo apt-get update
  233. sudo apt-get upgrade -y
  234. sudo apt-get install -y qemu-user-static
  235. - name: Fetch images
  236. id: fetch-images
  237. if: needs.file-check.outputs.run == 'true'
  238. uses: nick-invision/retry@v3
  239. with:
  240. max_attempts: 3
  241. retry_wait_seconds: 30
  242. timeout_seconds: 900
  243. command: |
  244. docker pull --platform ${{ matrix.platform }} ${{ matrix.base_image }}
  245. docker pull --platform ${{ matrix.platform }} netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-${{ matrix.builder_rev }}
  246. - name: Build Packages
  247. id: build
  248. if: needs.file-check.outputs.run == 'true'
  249. shell: bash
  250. run: |
  251. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e VERSION=${{ needs.version-check.outputs.version }} \
  252. -e ENABLE_SENTRY=${{ matrix.bundle_sentry }} -e RELEASE_PIPELINE=${{ env.RELEASE_PIPELINE }} \
  253. -e BUILD_DESTINATION=${{ matrix.distro }}${{ matrix.version }}_${{ matrix.arch }} -e UPLOAD_SENTRY=${{ env.UPLOAD_SENTRY }} \
  254. -e SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_CLI_TOKEN }} -e NETDATA_SENTRY_DSN=${{ secrets.SENTRY_DSN }} \
  255. -e GOOS=$(echo ${{ matrix.platform }} | cut -f 1 -d '/') -e GOARCH=$(echo ${{ matrix.platform }} | cut -f 2 -d '/') \
  256. --platform=${{ matrix.platform }} -v "$PWD":/netdata netdata/package-builders:${{ matrix.distro }}${{ matrix.version }}-${{ matrix.builder_rev }}
  257. - name: Save Packages
  258. id: artifacts
  259. if: needs.file-check.outputs.run == 'true'
  260. continue-on-error: true
  261. uses: actions/upload-artifact@v4.6.0
  262. with:
  263. name: ${{ matrix.distro }}-${{ matrix.version }}-${{ matrix.arch }}-packages
  264. path: ${{ github.workspace }}/artifacts/*
  265. - name: Test Packages
  266. id: test
  267. if: needs.file-check.outputs.run == 'true'
  268. shell: bash
  269. run: |
  270. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 -e DISTRO=${{ matrix.distro }} \
  271. -e VERSION=${{ needs.version-check.outputs.version }} -e DISTRO_VERSION=${{ matrix.version }} \
  272. --platform=${{ matrix.platform }} -v "$PWD":/netdata ${{ matrix.base_image }} \
  273. /netdata/.github/scripts/pkg-test.sh
  274. - name: Import GPG Keys
  275. id: import-keys
  276. if: needs.file-check.outputs.run == 'true' && matrix.format == 'deb' && github.event_name != 'pull_request'
  277. uses: crazy-max/ghaction-import-gpg@v6
  278. with:
  279. gpg_private_key: ${{ secrets.NETDATABOT_PACKAGE_SIGNING_KEY }}
  280. - name: Sign DEB Packages
  281. id: sign-deb
  282. if: needs.file-check.outputs.run == 'true' && matrix.format == 'deb' && github.event_name != 'pull_request'
  283. shell: bash
  284. run: .github/scripts/deb-sign.sh artifacts ${{ steps.import-keys.outputs.fingerprint }}
  285. - name: SSH setup
  286. id: ssh-setup
  287. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  288. uses: shimataro/ssh-key-action@v2
  289. with:
  290. key: ${{ secrets.NETDATABOT_PACKAGES_SSH_KEY }}
  291. name: id_ecdsa
  292. known_hosts: ${{ secrets.PACKAGES_KNOWN_HOSTS }}
  293. - name: Upload to packages.netdata.cloud
  294. id: package-upload
  295. continue-on-error: true
  296. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  297. run: |
  298. .github/scripts/package-upload.sh \
  299. packages.netdata.cloud \
  300. ${{ matrix.repo_distro }} \
  301. ${{ matrix.arch }} \
  302. ${{ matrix.format }} \
  303. ${{ needs.version-check.outputs.repo }}
  304. - name: Upload to packages2.netdata.cloud
  305. id: package2-upload
  306. if: github.event_name == 'workflow_dispatch' && github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true'
  307. run: |
  308. .github/scripts/package-upload.sh \
  309. packages2.netdata.cloud \
  310. ${{ matrix.repo_distro }} \
  311. ${{ matrix.arch }} \
  312. ${{ matrix.format }} \
  313. ${{ needs.version-check.outputs.repo }}
  314. - name: Failure Notification
  315. uses: rtCamp/action-slack-notify@v2
  316. env:
  317. SLACK_COLOR: 'danger'
  318. SLACK_ICON_EMOJI: ':github-actions:'
  319. SLACK_TITLE: 'Package Build failed:'
  320. SLACK_USERNAME: 'GitHub Actions'
  321. SLACK_MESSAGE: |-
  322. ${{ github.repository }}: ${{ matrix.repo_distro }} ${{ matrix.version }} package build for ${{ matrix.arch }} failed.
  323. Checkout: ${{ steps.checkout.outcome }}
  324. Setup QEMU: ${{ steps.qemu.outcome }}
  325. Fetch images: ${{ steps.fetch-images.outcome }}
  326. Build: ${{ steps.build.outcome }}
  327. Test: ${{ steps.test.outcome }}
  328. Import GPG Keys: ${{ steps.import-keys.outcome }}
  329. Sign DEB Packages: ${{ steps.sign-deb.outcome }}
  330. Import SSH Key: ${{ steps.ssh-setup.outcome }}
  331. Publish to packages.netdata.cloud: ${{ steps.package-upload.outcome }}
  332. Publish to packages2.netdata.cloud: ${{ steps.package2-upload.outcome }}
  333. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  334. if: >-
  335. ${{
  336. failure()
  337. && github.event_name != 'pull_request'
  338. && startsWith(github.ref, 'refs/heads/master')
  339. && github.repository == 'netdata/netdata'
  340. && needs.file-check.outputs.run == 'true'
  341. }}