packaging.yml 9.8 KB

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