repoconfig-packages.yml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ---
  2. # Handles building of binary packages for the agent.
  3. name: Repository Packages
  4. on:
  5. workflow_dispatch: null
  6. pull_request:
  7. paths:
  8. - packaging/repoconfig/**
  9. - .github/workflows/repoconfig-packages.yml
  10. - .github/data/distros.yml
  11. push:
  12. branches:
  13. - master
  14. paths:
  15. - packaging/repoconfig/**
  16. - .github/workflows/repoconfig-packages.yml
  17. - .github/data/distros.yml
  18. env:
  19. DISABLE_TELEMETRY: 1
  20. REPO_PREFIX: netdata/netdata
  21. jobs:
  22. matrix:
  23. name: Prepare Build Matrix
  24. runs-on: ubuntu-latest
  25. outputs:
  26. matrix: ${{ steps.set-matrix.outputs.matrix }}
  27. steps:
  28. - name: Checkout
  29. id: checkout
  30. uses: actions/checkout@v3
  31. - name: Prepare tools
  32. id: prepare
  33. run: |
  34. sudo apt-get update && sudo apt-get install -y python3-ruamel.yaml
  35. - name: Read build matrix
  36. id: set-matrix
  37. shell: python3 {0}
  38. run: |
  39. from ruamel.yaml import YAML
  40. import json
  41. yaml = YAML(typ='safe')
  42. entries = list()
  43. with open('.github/data/distros.yml') as f:
  44. data = yaml.load(f)
  45. for i, v in enumerate(data['include']):
  46. if 'packages' in data['include'][i]:
  47. entries.append({
  48. 'distro': data['include'][i]['distro'],
  49. 'version': data['include'][i]['version'],
  50. 'pkgclouddistro': data['include'][i]['packages']['repo_distro'],
  51. 'format': data['include'][i]['packages']['type'],
  52. 'base_image': data['include'][i]['base_image'] if 'base_image' in data['include'][i] else data['include'][i]['distro'],
  53. 'platform': data['platform_map']['amd64']
  54. })
  55. entries.sort(key=lambda k: (k['distro'], k['version']))
  56. matrix = json.dumps({'include': entries}, sort_keys=True)
  57. print('Generated Matrix: ' + matrix)
  58. print('::set-output name=matrix::' + matrix)
  59. - name: Failure Notification
  60. uses: rtCamp/action-slack-notify@v2
  61. env:
  62. SLACK_COLOR: 'danger'
  63. SLACK_ICON_EMOJI: ':github-actions:'
  64. SLACK_TITLE: 'Repository Package Build matrix generation failed:'
  65. SLACK_USERNAME: 'GitHub Actions'
  66. SLACK_MESSAGE: |-
  67. ${{ github.repository }}: Failed to generate build matrix for repository package build.
  68. Checkout: ${{ steps.checkout.outcome }}
  69. Prepare Tools: ${{ steps.prepare.outcome }}
  70. Read Build Matrix: ${{ steps.set-matrix.outcome }}
  71. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  72. if: >-
  73. ${{
  74. failure()
  75. && github.event_name != 'pull_request'
  76. && startsWith(github.ref, 'refs/heads/master')
  77. && github.repository == 'netdata/netdata'
  78. }}
  79. build:
  80. name: Build
  81. runs-on: ubuntu-latest
  82. env:
  83. DISABLE_TELEMETRY: 1
  84. DOCKER_CLI_EXPERIMENTAL: enabled
  85. needs:
  86. - matrix
  87. strategy:
  88. matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
  89. # We intentiaonally disable the fail-fast behavior so that a
  90. # build failure for one version doesn't prevent us from publishing
  91. # successfully built and tested packages for another version.
  92. fail-fast: false
  93. max-parallel: 8
  94. steps:
  95. - name: Checkout
  96. id: checkout
  97. uses: actions/checkout@v3
  98. # Unlike normally, we do not need a deep clone or submodules for this.
  99. - name: Fetch base image
  100. id: fetch-images
  101. uses: nick-invision/retry@v2
  102. with:
  103. max_attempts: 3
  104. retry_wait_seconds: 30
  105. timeout_seconds: 900
  106. command: docker pull --platform ${{ matrix.platform }} ${{ matrix.base_image }}:${{ matrix.version }}
  107. - name: Build Packages
  108. id: build
  109. shell: bash
  110. run: |
  111. docker run --security-opt seccomp=unconfined -e DISABLE_TELEMETRY=1 --platform ${{ matrix.platform }} \
  112. -v "$PWD":/netdata ${{ matrix.base_image }}:${{ matrix.version }} \
  113. /netdata/packaging/repoconfig/build-${{ matrix.format }}.sh
  114. - name: SSH setup
  115. id: ssh-setup
  116. if: github.event_name == 'workflow_dispatch'
  117. continue-on-error: true
  118. uses: shimataro/ssh-key-action@v2
  119. with:
  120. key: ${{ secrets.NETDATABOT_PACKAGES_SSH_KEY }}
  121. name: id_ecdsa
  122. known_hosts: ${{ secrets.PACKAGES_KNOWN_HOSTS }}
  123. - name: Upload to packages.netdata.cloud
  124. id: package-upload
  125. continue-on-error: true
  126. if: github.event_name == 'workflow_dispatch'
  127. run: |
  128. .github/scripts/package-upload.sh \
  129. ${{ matrix.repo_distro }} \
  130. ${{ matrix.arch }} \
  131. ${{ matrix.format }} \
  132. netdata/netdata
  133. .github/scripts/package-upload.sh \
  134. ${{ matrix.repo_distro }} \
  135. ${{ matrix.arch }} \
  136. ${{ matrix.format }} \
  137. netdata/netdata-edge
  138. .github/scripts/package-upload.sh \
  139. ${{ matrix.repo_distro }} \
  140. ${{ matrix.arch }} \
  141. ${{ matrix.format }} \
  142. netdata/netdata-repoconfig
  143. - name: Upload Packages
  144. id: publish
  145. if: github.event_name != 'pull_request' && github.repository == 'netdata/netdata'
  146. shell: bash
  147. env:
  148. PKG_CLOUD_TOKEN: ${{ secrets.PACKAGE_CLOUD_API_KEY }}
  149. run: |
  150. printf "Packages to upload:\n%s" "$(ls artifacts/*.${{ matrix.format }})"
  151. for pkgfile in artifacts/*.${{ matrix.format }} ; do
  152. .github/scripts/package_cloud_wrapper.sh yank "${REPO_PREFIX}/${{ matrix.pkgclouddistro }}" \
  153. "$(basename "${pkgfile}")" || true
  154. .github/scripts/package_cloud_wrapper.sh push "${REPO_PREFIX}/${{ matrix.pkgclouddistro }}" "${pkgfile}"
  155. .github/scripts/package_cloud_wrapper.sh yank "${REPO_PREFIX}-edge/${{ matrix.pkgclouddistro }}" \
  156. "$(basename "${pkgfile}")" || true
  157. .github/scripts/package_cloud_wrapper.sh push "${REPO_PREFIX}-edge/${{ matrix.pkgclouddistro }}" "${pkgfile}"
  158. .github/scripts/package_cloud_wrapper.sh yank "${REPO_PREFIX}-repoconfig/${{ matrix.pkgclouddistro }}" \
  159. "$(basename "${pkgfile}")" || true
  160. .github/scripts/package_cloud_wrapper.sh push "${REPO_PREFIX}-repoconfig/${{ matrix.pkgclouddistro }}" "${pkgfile}"
  161. done
  162. - name: Failure Notification
  163. if: ${{ failure() && github.repository == 'netdata/netdata' }}
  164. uses: rtCamp/action-slack-notify@v2
  165. env:
  166. SLACK_COLOR: 'danger'
  167. SLACK_FOOTER: ''
  168. SLACK_ICON_EMOJI: ':github-actions:'
  169. SLACK_TITLE: 'Repository Package Build failed:'
  170. SLACK_USERNAME: 'GitHub Actions'
  171. SLACK_MESSAGE: |-
  172. ${{ github.repository }}: ${{ matrix.pkgclouddistro }} ${{ matrix.version }} repository package build failed.
  173. Checkout: ${{ steps.checkout.outcome }}
  174. Fetch images: ${{ steps.fetch-images.outcome }}
  175. Build: ${{ steps.build.outcome }}
  176. Import SSH Key: ${{ steps.ssh-setup.outcome }}
  177. Publish to packages.netdata.cloud: ${{ steps.package-upload.outcome }}
  178. Publish to PackageCloud: ${{ steps.publish.outcome }}
  179. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}