packaging.yml 11 KB

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