repoconfig-packages.yml 6.0 KB

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